Skip to content

Commit 6fd96be

Browse files
committed
Ensure NODE_ENV is not inlined for next/jest
1 parent ce3a3d8 commit 6fd96be

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

packages/next/build/swc/options.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const regeneratorRuntimePath = require.resolve(
77

88
function getBaseSWCOptions({
99
filename,
10+
jest,
1011
development,
1112
hasReactRefresh,
1213
globalWindow,
@@ -50,15 +51,17 @@ function getBaseSWCOptions({
5051
},
5152
optimizer: {
5253
simplify: false,
53-
globals: {
54-
typeofs: {
55-
window: globalWindow ? 'object' : 'undefined',
56-
},
57-
envs: {
58-
NODE_ENV: development ? '"development"' : '"production"',
59-
},
60-
// TODO: handle process.browser to match babel replacing as well
61-
},
54+
globals: jest
55+
? null
56+
: {
57+
typeofs: {
58+
window: globalWindow ? 'object' : 'undefined',
59+
},
60+
envs: {
61+
NODE_ENV: development ? '"development"' : '"production"',
62+
},
63+
// TODO: handle process.browser to match babel replacing as well
64+
},
6265
},
6366
regenerator: {
6467
importPath: regeneratorRuntimePath,
@@ -86,6 +89,7 @@ export function getJestSWCOptions({
8689
}) {
8790
let baseOptions = getBaseSWCOptions({
8891
filename,
92+
jest: true,
8993
development: false,
9094
hasReactRefresh: false,
9195
globalWindow: !isServer,

test/unit/jest-next-swc.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-env jest */
2+
3+
describe('jest next-swc preset', () => {
4+
it('should have correct env', async () => {
5+
expect(process.env.NODE_ENV).toBe('test')
6+
})
7+
})

0 commit comments

Comments
 (0)