mantoni / mochify.js

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

Do not assume availability of default driver, prevent accidental fall back to wrong modules #262

Closed m90 closed 2 years ago

m90 commented 2 years ago

This PR addresses two issues:

I noticed I could run tests when not specifying any driver. I'm not sure if we want this as installing @mochify/cli or @mochfiy/mochify does not provide any driver implementation themselves and consumers would see a message about how a module could not be found when trying to run it, probably thinking this is a bug. Instead we can provide a clear error message about it.

The logic I implemented in #253 has one really awful flaw: Assuming you try passing jsdom as the driver without having installed it (whre it = @mochify/driver-jsdom), the logic would fall back to requiring jsdom which might be installed or resolvable because it's used by something else and then Mochify would try to use the main export of the jsdom module as a driver. I don't even want to imagine the confusion caused by the error messages happening here :sweat_smile: . To work around this, a check if the export matches the expected interface is added.