From 92be51185ad9bbf1da51a99fff51b0c263c6ee5e Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sun, 9 Feb 2020 17:01:58 +0500 Subject: [PATCH 1/4] fix: Reset isolateModules after failing --- .../runtime_require_module_or_mock.test.js | 15 +++++++++++++++ packages/jest-runtime/src/index.ts | 11 ++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js b/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js index a92f4a31769b..5eb2c31e89e0 100644 --- a/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js @@ -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, diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index cb74daf324af..75327b3dcb28 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -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) { + throw e; + } finally { + this._isolatedModuleRegistry = null; + this._isolatedMockRegistry = null; + } } resetModules() { From 4a96e425bf518903a93f8fd1868f0887dd73f487 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sun, 9 Feb 2020 17:24:41 +0500 Subject: [PATCH 2/4] fix: Reset isolateModules after failing --- packages/jest-runtime/src/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 75327b3dcb28..16f5f3774a5e 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -541,8 +541,6 @@ class Runtime { this._isolatedMockRegistry = new Map(); try { fn(); - } catch (e) { - throw e; } finally { this._isolatedModuleRegistry = null; this._isolatedMockRegistry = null; From 178b2dc786c2e074a22febb7769dc5281bf12854 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sun, 9 Feb 2020 17:27:50 +0500 Subject: [PATCH 3/4] fix: Reset isolateModules after failing --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d21a5ffb299..80fd4acc680c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes +- `[jest-runtime]` Reset `isolateModules` after failing ([#9541](https://github.com/facebook/jest/pull/9541)) - `[jest-config]` Treat `setupFilesAfterEnv` like `setupFiles` when normalizing configs against presets ([#9495](https://github.com/facebook/jest/pull/9495)) - `[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)) From 20cf9f0f5c6b44d2714fc1eb02a51ca66ff5d53d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 9 Feb 2020 13:29:41 +0100 Subject: [PATCH 4/4] alphabetical changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80fd4acc680c..e3376f7ee7dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,11 @@ ### Fixes -- `[jest-runtime]` Reset `isolateModules` after failing ([#9541](https://github.com/facebook/jest/pull/9541)) - `[jest-config]` Treat `setupFilesAfterEnv` like `setupFiles` when normalizing configs against presets ([#9495](https://github.com/facebook/jest/pull/9495)) - `[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))