Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocha --watch #2444

Closed
BrunoQuaresma opened this issue Aug 15, 2016 · 11 comments
Closed

Mocha --watch #2444

BrunoQuaresma opened this issue Aug 15, 2016 · 11 comments

Comments

@BrunoQuaresma
Copy link

When i run the tests with "--watch" flag and change a .jsx file in this path "./src/components/screens/Proposals/New.jsx" the tests aren't reload. But, if i change a test file (tests/unit/components/screens/Proposals/New.js) the tests are reload.

So, i try run pass a regular expression in the flag like "--watch .src/*/.jsx" . The console shows only the jsx files in "components/screens" level. So, i think that Mocha is not load correctly the subdirectories.

It is my test command: NODE_PATH=./src mocha --require test/unit/.setup.js --compilers js:babel-register --recursive test/unit

@govind999
Copy link

are you getting error on $(find api -name '*-test.js')

@BrunoQuaresma
Copy link
Author

@govind999 the console does not show errors.

@ericfong
Copy link

ericfong commented Sep 22, 2016

same here

fixed by change .jsx to .js

@boneskull
Copy link
Member

you'd probably want --compilers jsx:babel-register in addition to --require babel-register (which can replace --compilers js:babel-register), but I can't promise anything.

Mocha's --watch functionality is limited; if you're running into problems, then it's probably being bent in a way which wasn't originally intended. There's no "officially recommended" alternative, but there are a handful of recommendations in the other issues concerning --watch.

@mattiaerre
Copy link

thank you very much for your tip @boneskull
this script works just fine for me.

{
  "test": "mocha --compilers js:babel-core/register --compilers jsx:babel-register"
}

@FullStackForger
Copy link

There's no "officially recommended" alternative, but there are a handful of recommendations in the other issues concerning --watch.

What are those @boneskull? Are you suggesting something like https://www.npmjs.com/package/watch-run

@ScottFreeCode
Copy link
Contributor

Discussion in #1780 seems to have converged on Chokidar; there might be others in the items brought up by searching for GitHub issues, without open/closed restriction, that mention "watch" (or "watch module", "watch package" or "watch plugin"?). (There's also some points made there that we really need to fix the problems with the programmatic API to allow external watcher tools to use Mocha as efficiently as the builtin --watch.)

@FullStackForger
Copy link

FullStackForger commented Oct 25, 2016

Thank you @ScottFreeCode

There's also some points made there that we really need to fix the problems with the programmatic API to allow external watcher tools to use Mocha as efficiently as the builtin --watch.)

Couldn't agree with that more. I was trying to run test with

watch-run -i -p 'src/**/*' npm test:mocha

Which works just fine, however very slow. Reason? Babel!

"test:mocha": "mocha ./internals/test.setup.js ./src/**/*.spec.js* --require babel-core/register",

Every time file changes mocha requires babel-register which takes time to transpile everything, whereas re-running it with --watch take a bit of initial time to kick in but once up and running it is super fast.

@Hettomei
Copy link

Thank you @boneskull

Just a note : if you run mocha through gulp, here is the notation :

  gulp.src(['src/js/test/**/*.spec.js'])
    .pipe(mocha({
      compilers: ['js:babel-register', 'jsx:babel-register'],
      watch: true,
    }))

@mmc41
Copy link

mmc41 commented Jul 23, 2017

Try specifying --watch-extensions to mocha

@demisx
Copy link

demisx commented Sep 15, 2017

Thank you @mmc41. Specifying --watch-extensions made it work:

// in package.json
"scripts": {
  ...
  "watch:test": "mocha -r ts-node/register --watch app/**/*.spec.ts --watch-extensions ts"
}

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

No branches or pull requests

10 participants