未验证 提交 a750d1cc 编写于 作者: L Luis Fernando Alvarez D 提交者: GitHub

NODE_ENV is set to undefined before running a test command (#6823)

上级 2f325e0f
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册