Skip to content

Commit bb28ab4

Browse files
committed
Properly isolate setting env vars
1 parent 2356190 commit bb28ab4

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
lines changed

test/integration/config-output-export/test/index.test.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getRedboxHeader,
99
killApp,
1010
launchApp,
11+
type NextDevOptions,
1112
} from 'next-test-utils'
1213
import webdriver from 'next-webdriver'
1314
import { join } from 'path'
@@ -17,7 +18,7 @@ import type { Response } from 'node-fetch'
1718
const appDir = join(__dirname, '../')
1819
const nextConfig = new File(join(appDir, 'next.config.js'))
1920
let app
20-
const runDev = async (config: any) => {
21+
const runDev = async (config: any, opts?: NextDevOptions) => {
2122
await nextConfig.write(`module.exports = ${JSON.stringify(config)}`)
2223
const port = await findPort()
2324
const obj = { port, stdout: '', stderr: '' }
@@ -30,6 +31,7 @@ const runDev = async (config: any) => {
3031
onStderr(msg: string) {
3132
obj.stderr += msg || ''
3233
},
34+
...opts,
3335
})
3436
return obj
3537
}
@@ -103,44 +105,45 @@ describe('config-output-export', () => {
103105
})
104106

105107
describe('when hasNextSupport = true', () => {
106-
beforeAll(() => {
107-
process.env.NOW_BUILDER = '1'
108-
})
109-
110-
afterAll(() => {
111-
delete process.env.NOW_BUILDER
112-
})
113-
114108
it('should error with "rewrites" config', async () => {
115-
const { stderr } = await runDev({
116-
output: 'export',
117-
rewrites: [{ source: '/from', destination: '/to' }],
118-
})
109+
const { stderr } = await runDev(
110+
{
111+
output: 'export',
112+
rewrites: [{ source: '/from', destination: '/to' }],
113+
},
114+
{ env: { NOW_BUILDER: '1' } }
115+
)
119116
expect(stderr).not.toContain(
120117
'Specified "rewrites" will not automatically work with "output: export".'
121118
)
122119
})
123120

124121
it('should error with "redirects" config', async () => {
125-
const { stderr } = await runDev({
126-
output: 'export',
127-
redirects: [{ source: '/from', destination: '/to', permanent: true }],
128-
})
122+
const { stderr } = await runDev(
123+
{
124+
output: 'export',
125+
redirects: [{ source: '/from', destination: '/to', permanent: true }],
126+
},
127+
{ env: { NOW_BUILDER: '1' } }
128+
)
129129
expect(stderr).not.toContain(
130130
'Specified "redirects" will not automatically work with "output: export".'
131131
)
132132
})
133133

134134
it('should error with "headers" config', async () => {
135-
const { stderr } = await runDev({
136-
output: 'export',
137-
headers: [
138-
{
139-
source: '/foo',
140-
headers: [{ key: 'x-foo', value: 'val' }],
141-
},
142-
],
143-
})
135+
const { stderr } = await runDev(
136+
{
137+
output: 'export',
138+
headers: [
139+
{
140+
source: '/foo',
141+
headers: [{ key: 'x-foo', value: 'val' }],
142+
},
143+
],
144+
},
145+
{ env: { NOW_BUILDER: '1' } }
146+
)
144147
expect(stderr).not.toContain(
145148
'Specified "headers" will not automatically work with "output: export".'
146149
)

test/production/standalone-mode/required-server-files/required-server-files-app.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ describe('required server files app router', () => {
2525
nextEnv?: boolean
2626
minimalMode?: boolean
2727
}) => {
28-
// test build against environment with next support
29-
process.env.NOW_BUILDER = nextEnv ? '1' : ''
30-
process.env.NEXT_PRIVATE_TEST_HEADERS = '1'
31-
3228
next = await createNext({
3329
files: {
3430
app: new FileRef(join(__dirname, 'app')),
@@ -48,6 +44,11 @@ describe('required server files app router', () => {
4844
},
4945
output: 'standalone',
5046
},
47+
env: {
48+
// test build against environment with next support
49+
NOW_BUILDER: nextEnv ? '1' : '',
50+
NEXT_PRIVATE_TEST_HEADERS: '1',
51+
},
5152
})
5253
await next.stop()
5354

test/production/standalone-mode/required-server-files/required-server-files-ppr.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ describe('required server files app router', () => {
2424
let cliOutput = ''
2525

2626
beforeAll(async () => {
27-
process.env.NOW_BUILDER = '1'
28-
process.env.NEXT_PRIVATE_TEST_HEADERS = '1'
29-
3027
// Setup the Next.js app and build it.
3128
next = await createNext({
3229
files: {
@@ -50,6 +47,11 @@ describe('required server files app router', () => {
5047
},
5148
output: 'standalone',
5249
},
50+
env: {
51+
// test build against environment with next support
52+
NOW_BUILDER: '1',
53+
NEXT_PRIVATE_TEST_HEADERS: '1',
54+
},
5355
})
5456

5557
// Stop the server, we're going to restart it using the standalone server

test/production/standalone-mode/required-server-files/required-server-files.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ describe('required server files', () => {
2828
let minimalMode = true
2929

3030
const setupNext = async ({ nextEnv }: { nextEnv?: boolean }) => {
31-
// test build against environment with next support
32-
process.env.NOW_BUILDER = nextEnv ? '1' : ''
33-
process.env.NEXT_PRIVATE_TEST_HEADERS = '1'
34-
3531
next = await createNext({
3632
files: {
3733
pages: new FileRef(join(__dirname, 'pages')),
@@ -87,6 +83,11 @@ describe('required server files', () => {
8783
}
8884
},
8985
},
86+
env: {
87+
// test build against environment with next support
88+
NOW_BUILDER: nextEnv ? '1' : '',
89+
NEXT_PRIVATE_TEST_HEADERS: '1',
90+
},
9091
})
9192
await next.stop()
9293

test/production/standalone-mode/response-cache/index.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ describe('minimal-mode-response-cache', () => {
2020
let output = ''
2121

2222
beforeAll(async () => {
23-
// test build against environment with next support
24-
process.env.NOW_BUILDER = '1'
25-
process.env.NEXT_PRIVATE_TEST_HEADERS = '1'
26-
2723
next = await createNext({
2824
files: new FileRef(join(__dirname, 'app')),
25+
env: {
26+
// test build against environment with next support
27+
NOW_BUILDER: '1',
28+
NEXT_PRIVATE_TEST_HEADERS: '1',
29+
},
2930
})
3031
await next.stop()
3132

0 commit comments

Comments
 (0)