Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.