Description
For reference, I have a minimal reproducible repo here: https://github.com/mvromer/wtr-watch-error
I am using the latest version of @web/test-server with @web/test-server-playwright on Windows. I'm running this under Node 14.17.6 (latest LTS). When I run web-test-runner from an npm run script with watch mode enabled, when I quit out of the runner by pressing 'Q', the runner exits, but then an error like the following is thrown:
Chromium: |██████████████████████████████| 1/1 test files | 1 passed, 0 failed
Finished running tests, watching for file changes...
Press D to debug in the browser.
Press M to debug manually in a custom browser.
Press Q to quit watch mode.
Press Enter to re-run all tests.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wtr-watch@1.0.0 wtr:watch: `wtr --watch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wtr-watch@1.0.0 wtr:watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\XXXXXXX\AppData\Roaming\npm-cache\_logs\2021-09-22T16_54_05_097Z-debug.log
I've tried running web-test-runner under the JS debugger in VS Code with some breakpoints set, and what I've found is that inside startTestRunner
function, it calls process.exit(passed ? 0 : 1);
, but for whatever reason passed
is false here when watch is enabled (despite the above output showing the tests passed). Here's a snip showing what the value of passed
is when I hit this point of code in the debugger.
The value of passed
looks to come from the value of this.passed
given at the end of the TestRunner.stop
method call, as can be seen here:
As near as I can tell, the only place this.passed
is set inside this class is inside its onSessionFinished
method, but it'll only set it when the runner is not in watch mode. So it looks like web-test-runner will always return non-zero when run in watch mode, which is why npm throws the error above. It would be nice in this case to have the runner somehow return zero when it's in watch mode (or maybe return zero only if the last run of the current test suite is successful under watch mode) so that it doesn't cause tools wrapping it like npm to throw errors because they interpret the runner has having failed.