mantoni / mochify.js

☕️ TDD with Browserify, Mocha, Headless Chrome and WebDriver
MIT License
346 stars 57 forks source link

Ensure bundling ran successfully before instantiating driver #259

Closed m90 closed 2 years ago

m90 commented 2 years ago

As described in #258 a failed bundling would currently cause Mochify to never exit (when using driver-puppeteer at least).

This seems to happen because in that case noone ever calls end on the driver, leaving puppeteer idling. To work around this, we can make sure bundling worked properly before instantiating the driver so we can make sure it can always be closed.

N.B.: In case you are wondering how it would look like if bundling and driver instantiation would still happen in "parallel": https://github.com/mantoni/mochify.js/commit/279086018643a9f98b54f975607ba3aeb4514217 - I found it nicer doing it serially as it requires a lot less control flow logic.

m90 commented 2 years ago

On a meta level I was surprised to find that @mochify/mochify sets process.exitCode on test failures which I wouldn't expect from an API module. Should it maybe rather throw in such cases, leaving it up to the consumer to define how this should affect the program?

mantoni commented 2 years ago

On a meta level I was surprised to find that @mochify/mochify sets process.exitCode on test failures which I wouldn't expect from an API module.

Indeed, I agree.

Should it maybe rather throw in such cases, leaving it up to the consumer to define how this should affect the program?

It could also return { exit_code }, which could be assigned to process.exitCode in @mochify/cli.

m90 commented 2 years ago

Closing this in favor of #260

m90 commented 2 years ago

It could also return { exit_code }, which could be assigned to process.exitCode in @mochify/cli.

I like this because a failed test run is not really a runtime exception so it's still possible to distinguish the two.