Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

karma-mocha: mocha -r works ,but require in karma-mocha can not work. #147

Open
wangjihong0214 opened this issue Feb 28, 2017 · 4 comments

Comments

@wangjihong0214
Copy link

I want to write ut test for tpyescript . Below command in the shell is ok.
mocha -r /home/wjh/node_modules/ts-node/register /home/wjh/ut/src/*.ts --reporter min

and then i want to use mocha under karma like this in karma.conf.js,but it is not ok. Can anyone help me?
karam.conf.js:
......
client: {
mocha: {
// change Karma's debug.html to the mocha web reporter
reporter: 'min',
// require specific files after Mocha is initialized
require: '/home/wjh/node_modules/ts-node/register',
// custom ui, defined in required file above
ui:'bdd'
}
},

require:[require.resolve( '/home/wjh/node_modules/ts-node/register'), is not work either

@wangjihong0214
Copy link
Author

can anybody help me?:(

@maksimr
Copy link
Contributor

maksimr commented Mar 7, 2017

@wangjihong0214

require:[require.resolve( '/home/wjh/node_modules/ts-node/register'), is not work either

Could you explain how should it work?
Thanks

require simple add array's elements to files map. Something like this:

files: ['/home/wjh/node_modules/ts-node/register', ...]

@soundstep
Copy link

I think I'm having the same issue.
I have a runner.js that requires the javascript spec files like this:

require(arrayOfFiles, function() {
    mocha.run();

Everything is working correctly with mocha v3.5.0, but updating to mocha v4.0.1, the files are not required anymore: it never gets in the require callback. No error in the console, just silent.

Using node 8.3.0
mocha 4.0.1
karma 1.7.0
karma-mocha 1.3.0
requirejs 2.3.4
karma-requirejs 1.1.0

@sayers24
Copy link

@wangjihong0214 did you try just require:[require.resolve('ts-node/register')]?
@maksimr, this should get tests written in typescript to run without compilation. I've gotten this to work with a pure mocha/chai implementation but the register doesn't seem to kick in when karma is involved. Any thoughts on a solution?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants