60frames / jestpack

Jest Webpack Integration
MIT License
66 stars 3 forks source link

Is there a --watch option? #10

Closed amannn closed 8 years ago

amannn commented 8 years ago

Or something similar so there is live reload while writing tests and/or the app itself?

richardscarrott commented 8 years ago

Currently my workflow with Jestpack involves running the Webpack build in watch mode (webpack --watch) in one terminal window then manually running the tests with Jest in another (using jest --testPathPattern=foo to only run the tests I'm interested in during development) however I'm sure this could be improved...

It would be relatively trivial to run Jest whenever Webpack re-compiles, something like this:

compiler.plugin('done', () => {
    jest.runCLI({ ... });
});

The reason I've not implemented it this way is because the project I'm currently working on has 1000s of tests so it's not practical to run them all on change.

I think the optimum solution would be to run any tests which have been affected by a change (i.e. when the test file itself has changed or a dependency of the test file has changed). This would be a little more difficult to implement but I'm hoping something comes out of this https://github.com/webpack/webpack/issues/1608 which may make it easy enough.

amannn commented 8 years ago

Wow, thanks for the quick reply!

Ok, I see – makes sense.

I went for reloading all the time, since the project I'm working on currently only has around 40 tests.

Setup was pretty easy with this in package.json

{
  "scripts": {
    "test": "rimraf __bundled_tests__ && npm run test:jest",
    "test:watch": "nodemon -w ./src -e js -x npm run test",
    "test:jest": "NODE_ENV=testing webpack --config webpack.config.js --bail && jest",
  }
}

But it takes around 6 seconds on my MacBook Pro. I hope that webpack feature you referenced will make it.