-
Notifications
You must be signed in to change notification settings - Fork 797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Jest ESM support #3256
feat: Jest ESM support #3256
Conversation
This commit does not have test runner support, only works for running `cd test/jest-esm; npm run jest`.
Previous changes introduced a change in command-line arg processing.
The previous bug is that --max-workers should not be set when --runInBand is used.
I added logging to help if
|
@johncrim thanks for raising the PR and supporting Stencil. The team has decided not to move forward with this. We are planning to build a Jest preset for Jest v30 and up that will be published as a standalone module e.g. Again, thanks a lot for everything! |
Thanks for the update @christian-bromann . As long as ESM is handled well, I'm happy. |
Note up front: I don't believe this is quite ready to merge, open issues/questions noted below. I'm posting this PR for initial review/evaluation.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm test
) were run locally and passednpm run test.karma.prod
) were run locally and passednpm run prettier
) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
GitHub Issue Number: #3230
What is the new behavior?
Jest tests are run using ES modules if the following changes are made:
--experimental-vm-modules
, e.g.node --experimental-vm-modules node_modules/jest/bin/jest.js
orNODE_OPTIONS=--experimental-vm-modules npx jest
etc.I also like to include
--no-warnings
to eliminate the experimental feature warning on startup.testing.useESModules: true
Alternatively, if jest is run directly (not through the stencil CLI), the following
jest.config.cjs
can be used to run stencil tests using ES modules:In addition, a bug is fixed: If
--runInBand
is passed in the CLI,--max-workers=${config.maxConcurrentWorkers}
is no longer set. I had to fix this in order to debug my work on this feature. The behavior was incorrect before (one of--runInBand
or--max-workers
wins, b/c--runInBand
means no external worker processes), and I added tests to validate it.I can break that out if you really want me to...
Does this introduce a breaking change?
Changes should not be breaking - the previous code paths are effectively unchanged, so Jest tests using CJS continue to run as before.
Testing
I added some new unit tests, which only validate the config generation. I also added a new test sub-project
test/jest-esm
. To run it:I didn't see a way to loop this project into the CI build; eg the
test/jest-spec-runner
isn't called in the github workflow.Open issues
Documentation. I added js docs to the new config values, but that's probably not sufficient. I didn't see an obvious place to add docs.
More tests would be nice - eg running some jest + jest ESM tests through the whole stack, but I didn't see a pattern to follow.
Jest expect extensions are currently borken when using ESM and
@jest/globals
. That's why there's this ugly expect:TLDR: The return type of
@jest/globals expect()
is not the same asjest.JestMatchers<T>
. So anyone using Jest ESM with expect extensions will have to work around the typing issue until this issue is fixed. Note that this applies to anyone using Jest ESM, it is not stencil specific, but stencil developers likely use expect extensions.I think the last issue is tolerable (and looks like it should be fixed soon) - since this is opt-in, I think it's reasonable to provide this as a preview feature while Jest improves their ESM support.
Other
I validated that these changes provide a fix for #3251, if projects affected by #3251 are willing to switch to using ES modules while testing. Since #3251 only appears due to ESM dependencies, I would think this would be attractive.