Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure NODE_ENV is not inlined for next/jest #33032

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/next/build/swc/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const regeneratorRuntimePath = require.resolve(

function getBaseSWCOptions({
filename,
jest,
development,
hasReactRefresh,
globalWindow,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -86,6 +89,7 @@ export function getJestSWCOptions({
}) {
let baseOptions = getBaseSWCOptions({
filename,
jest: true,
development: false,
hasReactRefresh: false,
globalWindow: !isServer,
Expand Down
7 changes: 7 additions & 0 deletions test/unit/jest-next-swc.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})