3 ms·
Kinda niche, I wrote Bazel rules (https://github.com/rivethealth/rules_javascript https://github.com/rivethealth/rules_javascript), and with a build setting `--
by paulddraper 3y ago
Kinda niche, I wrote Bazel rules (https://github.com/rivethealth/rules_javascript https://github.com/rivethealth/rules_javascript), and with a build setting `--//javascript:module`.
Jest tests automatically use the CJS version. Webpack builds use the ESM version. (And all my stuff is in TypeScript, so it needs a build step anyway.)
- spankalee 3y agoJest on jsdom is just terrible though. It's a fake browser environment that acts like no browser that your users use, so the tests are far less meaningful that if you used a real browser.
- paulddraper 3y agoWell, for browser tests I use Selenium. (Tho I still use jest as the test runner.)
- WorldMaker 3y agoIf it matters that much that your tests are in a real browser environment what you are writing are likely integration tests, rather than unit tests. jsdom is great for unit tests that need to test a bare minimum of side effects. I know the distinction between unit tests and integration tests doesn't matter to some, but I still see a huge usefulness in distinguishing because unit tests should run in the "inner loop" every time a developer is touching code (so must be fast to avoid sapping productivity) and integration tests can be delayed until the "outer loop" (CI processes and UAT processes) so are allowed to be slower. Booting up a "real" browser is definitely on my slow things list and not something I think belongs in unit tests.