Skip to content

Commit

Permalink
fix: Reset isolateModules after failing (#9541)
Browse files Browse the repository at this point in the history
  • Loading branch information
doniyor2109 committed Feb 9, 2020
1 parent 4f62e93 commit dbeb5da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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

0 comments on commit dbeb5da

Please sign in to comment.