Skip to content

Commit

Permalink
feat(jest-config): add support for preset written in ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Mar 14, 2021
1 parent 33c3b07 commit 00ffa95
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `[jest-circus, jest-jasmine2]` [**BREAKING**] Fail the test instead of just warning when describe returns a value ([#10947](https://github.com/facebook/jest/pull/10947))
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
- `[jest-config]` [**BREAKING**] Use `jest-circus` as default test runner ([#10686](https://github.com/facebook/jest/pull/10686))
- `[jest-config]` Add support for `preset` written in ESM ([#11200](https://github.com/facebook/jest/pull/11200))
- `[jest-config, jest-runtime]` Support ESM for files other than `.js` and `.mjs` ([#10823](https://github.com/facebook/jest/pull/10823))
- `[jest-config, jest-runtime]` [**BREAKING**] Use "modern" implementation as default for fake timers ([#10874](https://github.com/facebook/jest/pull/10874) & [#11197](https://github.com/facebook/jest/pull/11197))
- `[jest-core]` make `TestWatcher` extend `emittery` ([#10324](https://github.com/facebook/jest/pull/10324))
Expand Down
2 changes: 1 addition & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ Specifies notification mode. Requires `notify: true`.

Default: `undefined`

A preset that is used as a base for Jest's configuration. A preset should point to an npm module that has a `jest-preset.json` or `jest-preset.js` file at the root.
A preset that is used as a base for Jest's configuration. A preset should point to an npm module that has a `jest-preset.json` or `jest-preset.js` or `jest-preset.mjs` file at the root.

For example, this preset `foo-bar/jest-preset.js` will be configured as follows:

Expand Down
9 changes: 9 additions & 0 deletions e2e/__tests__/presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {onNodeVersions} from '@jest/test-utils';
import runJest from '../runJest';

test('supports json preset', () => {
Expand All @@ -16,3 +17,11 @@ test('supports js preset', () => {
const result = runJest('presets/js');
expect(result.exitCode).toBe(0);
});

onNodeVersions('^12.17.0 || >=13.2.0', () => {
test('supports mjs preset', () => {
const result = runJest('presets/mjs');

expect(result.exitCode).toBe(0);
});
});
11 changes: 11 additions & 0 deletions e2e/presets/mjs/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

test('load file mapped by js preset', () => {
expect(require('./test.foo')).toEqual(42);
});
12 changes: 12 additions & 0 deletions e2e/presets/mjs/node_modules/jest-preset-mjs/jest-preset.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions e2e/presets/mjs/node_modules/jest-preset-mjs/mapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions e2e/presets/mjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"preset": "jest-preset-mjs"
}
}
Loading

0 comments on commit 00ffa95

Please sign in to comment.