Skip to content
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-config): add support for preset written in ESM #11200

Merged
merged 1 commit into from Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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`, `jest-preset.js`, `jest-preset.cjs` or `jest-preset.mjs` file at the root.

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

Expand Down
14 changes: 12 additions & 2 deletions e2e/__tests__/presets.test.ts
Expand Up @@ -5,14 +5,24 @@
* LICENSE file in the root directory of this source tree.
*/

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

test('supports json preset', () => {
const result = runJest('presets/json');
expect(result.exitCode).toBe(0);
});

test('supports js preset', () => {
const result = runJest('presets/js');
test.each(['js', 'cjs'])('supports %s preset', presetDir => {
const result = runJest(`presets/${presetDir}`);

expect(result.exitCode).toBe(0);
});

onNodeVersions('^12.17.0 || >=13.2.0', () => {
test.each(['mjs', 'js-type-module'])('supports %s preset', presetDir => {
const result = runJest(`presets/${presetDir}`);

expect(result.exitCode).toBe(0);
});
});
11 changes: 11 additions & 0 deletions e2e/presets/cjs/__tests__/index.js
@@ -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 cjs preset', () => {
expect(require('./test.foo')).toEqual(42);
});
12 changes: 12 additions & 0 deletions e2e/presets/cjs/node_modules/jest-preset-cjs/jest-preset.cjs

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/cjs/node_modules/jest-preset-cjs/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/cjs/package.json
@@ -0,0 +1,5 @@
{
"jest": {
"preset": "jest-preset-cjs"
}
}
11 changes: 11 additions & 0 deletions e2e/presets/js-type-module/__tests__/index.js
@@ -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);
});

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

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

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/js-type-module/package.json
@@ -0,0 +1,5 @@
{
"jest": {
"preset": "jest-preset-js-type-module"
}
}
11 changes: 11 additions & 0 deletions e2e/presets/mjs/__tests__/index.js
@@ -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 mjs 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
@@ -0,0 +1,5 @@
{
"jest": {
"preset": "jest-preset-mjs"
}
}