NODE_ENV is set to undefined before running a test command (#6823)
This commit is contained in:
parent
2f325e0f69
commit
a750d1cc42
4 changed files with 16 additions and 21 deletions
|
@ -16,7 +16,6 @@ describe('Production Custom Build Directory', () => {
|
|||
it('should render the page', async () => {
|
||||
const result = await runNextCommand(['build', 'build'], {
|
||||
cwd: join(__dirname, '..'),
|
||||
spawnOptions: { env: { ...process.env, NODE_ENV: 'production' } },
|
||||
stdout: true,
|
||||
stderr: true
|
||||
})
|
||||
|
|
|
@ -41,27 +41,21 @@ describe('Production Config Usage', () => {
|
|||
|
||||
describe('env', () => {
|
||||
it('should fail with __ in env key', async () => {
|
||||
const result = await runNextCommand(['build', appDir], { spawnOptions: {
|
||||
env: {
|
||||
...process.env,
|
||||
ENABLE_ENV_FAIL_UNDERSCORE: true
|
||||
}
|
||||
},
|
||||
stdout: true,
|
||||
stderr: true })
|
||||
const result = await runNextCommand(['build', appDir], {
|
||||
env: { ENABLE_ENV_FAIL_UNDERSCORE: true },
|
||||
stdout: true,
|
||||
stderr: true
|
||||
})
|
||||
|
||||
expect(result.stderr).toMatch(/The key "__NEXT_MY_VAR" under/)
|
||||
})
|
||||
|
||||
it('should fail with NODE_ in env key', async () => {
|
||||
const result = await runNextCommand(['build', appDir], { spawnOptions: {
|
||||
env: {
|
||||
...process.env,
|
||||
ENABLE_ENV_FAIL_NODE: true
|
||||
}
|
||||
},
|
||||
stdout: true,
|
||||
stderr: true })
|
||||
const result = await runNextCommand(['build', appDir], {
|
||||
env: { ENABLE_ENV_FAIL_NODE: true },
|
||||
stdout: true,
|
||||
stderr: true
|
||||
})
|
||||
|
||||
expect(result.stderr).toMatch(/The key "NODE_ENV" under/)
|
||||
})
|
||||
|
|
|
@ -27,9 +27,8 @@ const context = {}
|
|||
|
||||
describe('Production Usage', () => {
|
||||
beforeAll(async () => {
|
||||
await runNextCommand(['build', appDir], {
|
||||
spawnOptions: { env: { ...process.env, NODE_ENV: 'production' } }
|
||||
})
|
||||
await runNextCommand(['build', appDir])
|
||||
|
||||
app = nextServer({
|
||||
dir: join(__dirname, '../'),
|
||||
dev: false,
|
||||
|
|
|
@ -74,9 +74,12 @@ export function runNextCommand (argv, options = {}) {
|
|||
const nextDir = path.dirname(require.resolve('next/package'))
|
||||
const nextBin = path.join(nextDir, 'dist/bin/next')
|
||||
const cwd = options.cwd || nextDir
|
||||
// Let Next.js decide the environment
|
||||
const env = { ...process.env, ...options.env, NODE_ENV: undefined }
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(`Running command "next ${argv.join(' ')}"`)
|
||||
const instance = spawn('node', [nextBin, ...argv], { ...options.spawnOptions, cwd, stdio: ['ignore', 'pipe', 'pipe'] })
|
||||
const instance = spawn('node', [nextBin, ...argv], { ...options.spawnOptions, cwd, env, stdio: ['ignore', 'pipe', 'pipe'] })
|
||||
|
||||
if (typeof options.instance === 'function') {
|
||||
options.instance(instance)
|
||||
|
|
Loading…
Reference in a new issue