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

fix: properly handle re-exported native modules in ESM via CJS #14589

Merged
merged 3 commits into from
Oct 2, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- `[jest-config]` Make sure to respect `runInBand` option ([#14578](https://github.com/facebook/jest/pull/14578))
- `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408))
- `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526))
- `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589))
- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552))
- `[pretty-format]` [**BREAKING**] Print `ArrayBuffer` and `DataView` correctly ([#14290](https://github.com/facebook/jest/pull/14290))

Expand Down
12 changes: 10 additions & 2 deletions e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`does not enforce import assertions 1`] = `
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-missing-import-assertions.test/i."
Ran all test suites matching /native-esm-missing-import-assertions.test.js/i."
`;

exports[`on node >=16.9.0 support re-exports from CJS of dual packages 1`] = `
Expand All @@ -21,7 +21,15 @@ exports[`on node >=16.12.0 supports import assertions 1`] = `
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-import-assertions.test/i."
Ran all test suites matching /native-esm-import-assertions.test.js/i."
`;

exports[`properly handle re-exported native modules in ESM via CJS 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-native-module.test.js/i."
`;

exports[`runs WebAssembly (Wasm) test with native ESM 1`] = `
Expand Down
20 changes: 17 additions & 3 deletions e2e/__tests__/nativeEsm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,21 @@ test('runs WebAssembly (Wasm) test with native ESM', () => {
test('does not enforce import assertions', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-missing-import-assertions.test'],
['native-esm-missing-import-assertions.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

const {summary} = extractSummary(stderr);

expect(summary).toMatchSnapshot();
expect(stdout).toBe('');
expect(exitCode).toBe(0);
});

test('properly handle re-exported native modules in ESM via CJS', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-native-module.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

Expand All @@ -113,7 +127,7 @@ onNodeVersions('>=16.12.0', () => {
test('supports import assertions', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-import-assertions.test'],
['native-esm-import-assertions.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

Expand All @@ -129,7 +143,7 @@ onNodeVersions('<16.12.0', () => {
test('syntax error for import assertions', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-import-assertions.test'],
['native-esm-import-assertions.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

Expand Down
12 changes: 12 additions & 0 deletions e2e/native-esm/__tests__/native-esm-native-module.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import ivm from 'isolated-vm';

test('supports native modules exported via CJS', () => {
expect(ivm).toBeDefined();
});
1 change: 1 addition & 0 deletions e2e/native-esm/__tests__/native-esm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test('should support importing node core modules', () => {
devDependencies: {
'discord.js': '14.3.0',
'iso-constants': '^0.1.2',
'isolated-vm': '^4.6.0',
yargs: '^17.5.1',
},
jest: {
Expand Down
1 change: 1 addition & 0 deletions e2e/native-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"discord.js": "14.3.0",
"iso-constants": "^0.1.2",
"isolated-vm": "^4.6.0",
"yargs": "^17.5.1"
},
"jest": {
Expand Down
Loading