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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add info about ES modules to docs #10611
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
id: ecmascript-modules | ||
title: ECMAScript Modules | ||
--- | ||
|
||
Jest ships with _experimental_ support for ECMAScript Modules (ESM). | ||
|
||
> Note that due to its experimental nature there are many bugs and missing features in Jest's implementation, both known and unknown. You should check out the [tracking issue](https://github.com/facebook/jest/issues/9430) and the [label](https://github.com/facebook/jest/labels/ES%20Modules) on the issue tracker for the latest status. | ||
|
||
> Also note that the APIs Jest uses to implement ESM support is still [considered experimental by Node](https://nodejs.org/api/vm.html#vm_class_vm_module) (as of version `14.13.1`). | ||
|
||
With the warnings out of the way, this is how you activate ESM support in your tests. | ||
|
||
1. Ensure you either disable [code transforms](./configuration#transform-objectstring-pathtotransformer--pathtotransformer-object) by passing `transform: {}` or otherwise configure your transformer to emit ESM rather than the default CommonJS (CJS). | ||
1. Execute `node` with `--experimental-vm-modules`, e.g. `node --experimental-vm-modules node_modules/.bin/jest` or `NODE_OPTIONS=--experimental-vm-modules npx jest` etc. | ||
1. Beyond that, we attempt to follow `node`'s logic for activating "ESM mode" (such as looking at `type` in `package.json` or `mjs` files), see [their docs](https://nodejs.org/api/esm.html#esm_enabling) for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
id: version-26.0-ecmascript-modules | ||
title: ECMAScript Modules | ||
original_id: ecmascript-modules | ||
--- | ||
|
||
Jest ships with _experimental_ support for ECMAScript Modules (ESM). | ||
|
||
> Note that due to its experimental nature there are many bugs and missing features in Jest's implementation, both known and unknown. You should check out the [tracking issue](https://github.com/facebook/jest/issues/9430) and the [label](https://github.com/facebook/jest/labels/ES%20Modules) on the issue tracker for the latest status. | ||
|
||
> Also note that the APIs Jest uses to implement ESM support is still [considered experimental by Node](https://nodejs.org/api/vm.html#vm_class_vm_module) (as of version `14.13.1`). | ||
|
||
With the warnings out of the way, this is how you activate ESM support in your tests. | ||
|
||
1. Ensure you either disable [code transforms](./configuration#transform-objectstring-pathtotransformer--pathtotransformer-object) by passing `transform: {}` or otherwise configure your transformer to emit ESM rather than the default CommonJS (CJS). | ||
1. Execute `node` with `--experimental-vm-modules`, e.g. `node --experimental-vm-modules node_modules/.bin/jest` or `NODE_OPTIONS=--experimental-vm-modules npx jest` etc. | ||
1. Beyond that, we attempt to follow `node`'s logic for activating "ESM mode" (such as looking at `type` in `package.json` or `mjs` files), see [their docs](https://nodejs.org/api/esm.html#esm_enabling) for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"version-26.0-docs": { | ||
"Introduction": [ | ||
"version-26.0-getting-started", | ||
"version-26.0-using-matchers", | ||
"version-26.0-asynchronous", | ||
"version-26.0-setup-teardown", | ||
"version-26.0-mock-functions", | ||
"version-26.0-jest-platform", | ||
"version-26.0-jest-community", | ||
"version-26.0-more-resources" | ||
], | ||
"Guides": [ | ||
"version-26.0-snapshot-testing", | ||
"version-26.0-tutorial-async", | ||
"version-26.0-timer-mocks", | ||
"version-26.0-manual-mocks", | ||
"version-26.0-es6-class-mocks", | ||
"version-26.0-bypassing-module-mocks", | ||
"version-26.0-ecmascript-modules", | ||
"version-26.0-webpack", | ||
"version-26.0-puppeteer", | ||
"version-26.0-mongodb", | ||
"version-26.0-dynamodb", | ||
"version-26.0-tutorial-jquery", | ||
"version-26.0-watch-plugins", | ||
"version-26.0-migration-guide", | ||
"version-26.0-troubleshooting", | ||
"version-26.0-architecture" | ||
], | ||
"Framework Guides": [ | ||
"version-26.0-tutorial-react", | ||
"version-26.0-tutorial-react-native", | ||
"version-26.0-testing-frameworks" | ||
], | ||
"API Reference": [ | ||
"version-26.0-api", | ||
"version-26.0-expect", | ||
"version-26.0-mock-function-api", | ||
"version-26.0-jest-object", | ||
"version-26.0-configuration", | ||
"version-26.0-cli" | ||
] | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My tests for tslib didn't need these flags, just making sure that the root package json is a
"type": "module"
- https://github.com/microsoft/tslib/tree/master/test/esm-node-nativeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orta
That鈥檚聽because your聽tests don鈥檛聽use聽Jest, which聽runs聽tests in聽
vm
聽contexts, where聽the聽Module
聽API needs聽that聽flag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, see the https://nodejs.org/api/vm.html#vm_class_vm_module link above.
EDIT: Ergh, same link as @ExE-Boss posted 馃槄