提交 51b15417 编写于 作者: L Luis Fernando Alvarez D 提交者: Tim Neutkens

The custom build test now runs in production mode (#6818)

I also removed the copy it had of `runNextCommand`
上级 0f2bd192
/* eslint-env jest */
/* global jasmine */
import { dirname, join } from 'path'
import { join } from 'path'
import {
nextServer,
runNextCommand,
startApp,
stopApp,
renderViaHTTP
} from 'next-test-utils'
import spawn from 'cross-spawn'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
function runNextCommand (argv, options = {}) {
return new Promise((resolve, reject) => {
console.log(`Running command "next ${argv.join(' ')}"`)
const instance = spawn('node', [join(dirname(require.resolve('next/package')), 'dist/bin/next'), ...argv], { ...options.spawnOptions, cwd: join(__dirname, '..'), stdio: ['ignore', 'pipe', 'pipe'] })
let stderrOutput = ''
if (options.stderr) {
instance.stderr.on('data', function (chunk) {
stderrOutput += chunk
})
}
let stdoutOutput = ''
if (options.stdout) {
instance.stdout.on('data', function (chunk) {
stdoutOutput += chunk
})
}
instance.on('close', () => {
resolve({
stdout: stdoutOutput,
stderr: stderrOutput
})
})
instance.on('error', (err) => {
err.stdout = stdoutOutput
err.stderr = stderrOutput
reject(err)
})
})
}
describe('Production Custom Build Directory', () => {
describe('With basic usage', () => {
it('should render the page', async () => {
const result = await runNextCommand(['build', 'build'], { stdout: true, stderr: true })
const result = await runNextCommand(['build', 'build'], {
cwd: join(__dirname, '..'),
spawnOptions: { env: { ...process.env, NODE_ENV: 'production' } },
stdout: true,
stderr: true
})
expect(result.stderr).toBe('')
const app = nextServer({
......
......@@ -71,10 +71,12 @@ export function findPort () {
}
export function runNextCommand (argv, options = {}) {
const cwd = path.dirname(require.resolve('next/package'))
const nextDir = path.dirname(require.resolve('next/package'))
const nextBin = path.join(nextDir, 'dist/bin/next')
const cwd = options.cwd || nextDir
return new Promise((resolve, reject) => {
console.log(`Running command "next ${argv.join(' ')}"`)
const instance = spawn('node', ['dist/bin/next', ...argv], { ...options.spawnOptions, cwd, stdio: ['ignore', 'pipe', 'pipe'] })
const instance = spawn('node', [nextBin, ...argv], { ...options.spawnOptions, cwd, 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.
先完成此消息的编辑!
想要评论请 注册