Skip to content

Commit

Permalink
fix: refactor _importCoreModule so required core module is consistent (
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasongg authored Feb 21, 2025
1 parent 5a8103c commit f4246f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
- `[@jest/expect-utils]` Fix not addressing to Sets and Maps as objects without keys ([#14873](https://github.com/jestjs/jest/pull/14873))
- `[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-runtime]` Refactor `_importCoreModel` so required core module is consistent if modified while loading ([#15077](https://github.com/jestjs/jest/issues/15077))
- `[jest-schemas, jest-types]` [**BREAKING**] Fix type of `testFailureExitCode` config option([#15232](https://github.com/jestjs/jest/pull/15232))
- `[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/jestjs/jest/pull/14290))
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1782,13 +1782,15 @@ export default class Runtime {

private _importCoreModule(moduleName: string, context: VMContext) {
const required = this._requireCoreModule(moduleName, true);
const allExports = Object.entries(required);
const exportNames = allExports.map(([key]) => key);

const module = new SyntheticModule(
['default', ...Object.keys(required)],
['default', ...exportNames],
function () {
// @ts-expect-error: TS doesn't know what `this` is
this.setExport('default', required);
for (const [key, value] of Object.entries(required)) {
for (const [key, value] of allExports) {
// @ts-expect-error: TS doesn't know what `this` is
this.setExport(key, value);
}
Expand Down

0 comments on commit f4246f3

Please sign in to comment.