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: Reset isolateModules after failing #9541

Merged
merged 4 commits into from Feb 9, 2020
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 @@ -11,6 +11,7 @@
- `[jest-matcher-utils]` Fix diff highlight of symbol-keyed object. ([#9499](https://github.com/facebook/jest/pull/9499))
- `[jest-resolve]` Fix module identity preservation with symlinks and browser field resolution ([#9511](https://github.com/facebook/jest/pull/9511))
- `[jest-resolve]` Do not confuse directories with files ([#8912](https://github.com/facebook/jest/pull/8912))
- `[jest-runtime]` Reset `isolateModules` if it fails ([#9541](https://github.com/facebook/jest/pull/9541))
- `[jest-snapshot]` Downgrade semver to v6 to support node 8 ([#9451](https://github.com/facebook/jest/pull/9451))
- `[jest-snapshot]` Properly indent new snapshots in the presences of existing ones ([#9523](https://github.com/facebook/jest/pull/9523))
- `[jest-transform]` Correct sourcemap behavior for transformed and instrumented code ([#9460](https://github.com/facebook/jest/pull/9460))
Expand Down
Expand Up @@ -240,6 +240,21 @@ describe('isolateModules', () => {
expect(exports.getState()).toBe(1);
}));

it('resets module after failing', () =>
createRuntime(__filename, {
moduleNameMapper,
}).then(runtime => {
expect(() =>
runtime.isolateModules(() => {
throw new Error('Error from isolated module');
}),
).toThrowError('Error from isolated module');

runtime.isolateModules(() => {
expect(true).toBe(true);
});
}));

it('cannot nest isolateModules blocks', () =>
createRuntime(__filename, {
moduleNameMapper,
Expand Down
9 changes: 6 additions & 3 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -539,9 +539,12 @@ class Runtime {
}
this._isolatedModuleRegistry = new Map();
this._isolatedMockRegistry = new Map();
fn();
this._isolatedModuleRegistry = null;
this._isolatedMockRegistry = null;
try {
fn();
} finally {
this._isolatedModuleRegistry = null;
this._isolatedMockRegistry = null;
}
}

resetModules() {
Expand Down