Skip to content

Commit c80911a

Browse files
authored
chore: add info about ES modules to docs (#10611)
1 parent bb45b8c commit c80911a

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

docs/ECMAScriptModules.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
id: ecmascript-modules
3+
title: ECMAScript Modules
4+
---
5+
6+
Jest ships with _experimental_ support for ECMAScript Modules (ESM).
7+
8+
> 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.
9+
10+
> 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`).
11+
12+
With the warnings out of the way, this is how you activate ESM support in your tests.
13+
14+
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).
15+
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.
16+
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

website/sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"manual-mocks",
1818
"es6-class-mocks",
1919
"bypassing-module-mocks",
20+
"ecmascript-modules",
2021
"webpack",
2122
"puppeteer",
2223
"mongodb",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
id: version-26.0-ecmascript-modules
3+
title: ECMAScript Modules
4+
original_id: ecmascript-modules
5+
---
6+
7+
Jest ships with _experimental_ support for ECMAScript Modules (ESM).
8+
9+
> 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.
10+
11+
> 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`).
12+
13+
With the warnings out of the way, this is how you activate ESM support in your tests.
14+
15+
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).
16+
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.
17+
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
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"version-26.0-docs": {
3+
"Introduction": [
4+
"version-26.0-getting-started",
5+
"version-26.0-using-matchers",
6+
"version-26.0-asynchronous",
7+
"version-26.0-setup-teardown",
8+
"version-26.0-mock-functions",
9+
"version-26.0-jest-platform",
10+
"version-26.0-jest-community",
11+
"version-26.0-more-resources"
12+
],
13+
"Guides": [
14+
"version-26.0-snapshot-testing",
15+
"version-26.0-tutorial-async",
16+
"version-26.0-timer-mocks",
17+
"version-26.0-manual-mocks",
18+
"version-26.0-es6-class-mocks",
19+
"version-26.0-bypassing-module-mocks",
20+
"version-26.0-ecmascript-modules",
21+
"version-26.0-webpack",
22+
"version-26.0-puppeteer",
23+
"version-26.0-mongodb",
24+
"version-26.0-dynamodb",
25+
"version-26.0-tutorial-jquery",
26+
"version-26.0-watch-plugins",
27+
"version-26.0-migration-guide",
28+
"version-26.0-troubleshooting",
29+
"version-26.0-architecture"
30+
],
31+
"Framework Guides": [
32+
"version-26.0-tutorial-react",
33+
"version-26.0-tutorial-react-native",
34+
"version-26.0-testing-frameworks"
35+
],
36+
"API Reference": [
37+
"version-26.0-api",
38+
"version-26.0-expect",
39+
"version-26.0-mock-function-api",
40+
"version-26.0-jest-object",
41+
"version-26.0-configuration",
42+
"version-26.0-cli"
43+
]
44+
}
45+
}

0 commit comments

Comments
 (0)