I want to run the tests on my CI, so I need to start the webpack-dev-server before to run the tests.
So jest-dev-server would be very good to me, but I noticed that it isn't waiting my bundler finish before to run the tests.
My bundle process is long: it takes ~16 seconds to be able to see the index.
But since jest-dev-server just wait the port be available, it will fail on tests, because the port is open much before to server be ready.
Just have a very complex build process to see this bug.
Also, if start manually the server before to run the tests, it'll work. But is bad to write a code like that to run automatically on CI.
jest-dev-server should wait the build finish before to start (maybe afterCompile could help).
I really don't know if it's the best solution, but I solved this bug setting to wait-on wait to /webpack-dev-server be available instead of the port:
server: {
command: 'webpack-dev-server --mode development --env=local --config webpack.config.js',
port: 8080,
debug: true,
launchTimeout: 30000,
waitOnScheme: {
verbose: true,
resources: ['http://localhost:8080/webpack-dev-server'],
},
},
I think that it could be the default behaviour. Wait for http://localhost:8080/webpack-dev-server instead of just the tcp:localhost:8080
@macabeus I also experienced this problem, but solved it differently. I noticed that by default, jest-dev-server calls wait-on with an URL that starts with http:// or https://, see here https://github.com/smooth-code/jest-puppeteer/blob/0d72f09fa95173bf63999e05368bd4f312cde851/packages/jest-dev-server/src/global.js#L195
This in turn means it uses HTTP HEAD to call the resources
http: - HTTP HEAD returns 2XX response. ex: http://m.com:90/foo
https: - HTTPS HEAD returns 2XX response. ex: https://my/bar
Using HEAD, in an older version of webpack-dev-server that I had, it replied before the bundle finished. Trying a GET request it properly replied after the bundle had finished. I found out that this was due to that webpack-dev-server had no proper HEAD support until verison 3.4.0, see https://github.com/webpack/webpack-dev-server/releases/tag/v3.4.0
Summary: Upgrade webpack-dev-server to the latest version and it will work.
@macabeus solution worked for me 馃憤
You should do the bundle before you start the tests.
// in package.json
"scripts": {
"pretest": "webpack-dev-server --mode development --env=local --config webpack.config.js"
}
Most helpful comment
I really don't know if it's the best solution, but I solved this bug setting to
wait-onwait to/webpack-dev-serverbe available instead of the port:I think that it could be the default behaviour. Wait for
http://localhost:8080/webpack-dev-serverinstead of just thetcp:localhost:8080