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 1 commit
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
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
11 changes: 8 additions & 3 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -539,9 +539,14 @@ class Runtime {
}
this._isolatedModuleRegistry = new Map();
this._isolatedMockRegistry = new Map();
fn();
this._isolatedModuleRegistry = null;
this._isolatedMockRegistry = null;
try {
fn();
} catch (e) {
SimenB marked this conversation as resolved.
Show resolved Hide resolved
throw e;
} finally {
this._isolatedModuleRegistry = null;
this._isolatedMockRegistry = null;
}
}

resetModules() {
Expand Down