Ensure NODE_ENV is not inlined for next/jest (#33032)

This commit is contained in:
JJ Kasper 2022-01-05 09:22:22 -06:00 committed by GitHub
parent ce3a3d8eea
commit 1ee13baf00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

View file

@ -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,

View file

@ -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')
})
})