From 1ee13baf000ab391e6017c68eb4770768a8e7674 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 5 Jan 2022 09:22:22 -0600 Subject: [PATCH] Ensure NODE_ENV is not inlined for next/jest (#33032) --- packages/next/build/swc/options.js | 22 +++++++++++++--------- test/unit/jest-next-swc.test.ts | 7 +++++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 test/unit/jest-next-swc.test.ts diff --git a/packages/next/build/swc/options.js b/packages/next/build/swc/options.js index 6e2a852bfc0fc..103119885e47b 100644 --- a/packages/next/build/swc/options.js +++ b/packages/next/build/swc/options.js @@ -7,6 +7,7 @@ const regeneratorRuntimePath = require.resolve( function getBaseSWCOptions({ filename, + jest, development, hasReactRefresh, globalWindow, @@ -50,15 +51,17 @@ function getBaseSWCOptions({ }, optimizer: { simplify: false, - globals: { - typeofs: { - window: globalWindow ? 'object' : 'undefined', - }, - envs: { - NODE_ENV: development ? '"development"' : '"production"', - }, - // TODO: handle process.browser to match babel replacing as well - }, + globals: jest + ? null + : { + typeofs: { + window: globalWindow ? 'object' : 'undefined', + }, + envs: { + NODE_ENV: development ? '"development"' : '"production"', + }, + // TODO: handle process.browser to match babel replacing as well + }, }, regenerator: { importPath: regeneratorRuntimePath, @@ -86,6 +89,7 @@ export function getJestSWCOptions({ }) { let baseOptions = getBaseSWCOptions({ filename, + jest: true, development: false, hasReactRefresh: false, globalWindow: !isServer, diff --git a/test/unit/jest-next-swc.test.ts b/test/unit/jest-next-swc.test.ts new file mode 100644 index 0000000000000..55e10a32998cd --- /dev/null +++ b/test/unit/jest-next-swc.test.ts @@ -0,0 +1,7 @@ +/* eslint-env jest */ + +describe('jest next-swc preset', () => { + it('should have correct env', async () => { + expect(process.env.NODE_ENV).toBe('test') + }) +})