From 78414cb53ced41fe12497eb8e89f6b22893c8c8b Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Wed, 2 Dec 2020 18:37:31 +0100 Subject: [PATCH 1/3] Allow __dirname and __filename in hoisted mock factory function --- packages/babel-plugin-jest-hoist/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/babel-plugin-jest-hoist/src/index.ts b/packages/babel-plugin-jest-hoist/src/index.ts index f5c59c44de25..e61732c1f851 100644 --- a/packages/babel-plugin-jest-hoist/src/index.ts +++ b/packages/babel-plugin-jest-hoist/src/index.ts @@ -35,6 +35,8 @@ const hoistedVariables = new WeakSet(); // We also allow variables prefixed with `mock` as an escape-hatch. const ALLOWED_IDENTIFIERS = new Set( [ + '__dirname', + '__filename', 'Array', 'ArrayBuffer', 'Boolean', From 16925a5c2bbda19297669e6969ef4860e9b605af Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Wed, 2 Dec 2020 19:07:27 +0100 Subject: [PATCH 2/3] add all module wrapper fields; order --- packages/babel-plugin-jest-hoist/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/babel-plugin-jest-hoist/src/index.ts b/packages/babel-plugin-jest-hoist/src/index.ts index e61732c1f851..d35602e68d5c 100644 --- a/packages/babel-plugin-jest-hoist/src/index.ts +++ b/packages/babel-plugin-jest-hoist/src/index.ts @@ -35,8 +35,6 @@ const hoistedVariables = new WeakSet(); // We also allow variables prefixed with `mock` as an escape-hatch. const ALLOWED_IDENTIFIERS = new Set( [ - '__dirname', - '__filename', 'Array', 'ArrayBuffer', 'Boolean', @@ -87,7 +85,11 @@ const ALLOWED_IDENTIFIERS = new Set( 'jest', 'parseFloat', 'parseInt', + 'exports', 'require', + 'module', + '__filename', + '__dirname', 'undefined', ...Object.getOwnPropertyNames(global), ].sort(), From fb47852a805a3d472c43d919f4ecf97c6a6c7137 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 3 Dec 2020 11:52:23 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfd8a5b022bd..15f9d251e9db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Fixes +- `[babel-plugin-jest-hoist]` Add `__dirname` and `__filename` to whitelisted globals ([#10903](https://github.com/facebook/jest/pull/10903)) - `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708)) - `[jest-circus]` Fixed the issue of beforeAll & afterAll hooks getting executed even if it is inside a skipped `describe` block [#10451](https://github.com/facebook/jest/issues/10451) - `[jest-circus]` Fix `testLocation` on Windows when using `test.each` ([#10871](https://github.com/facebook/jest/pull/10871))