mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 17:37:14 +00:00
65f4a030f4
* Rename this.generateRoutes to this.staticRoutes * Refactor generator to separate logic * Move routeCreated hook to generateRoute Add routeFailed hook for unhandled exceptions Keep page errors separately until page hooks have been called * Move debug and report statements to hooks * pageErrors can be a const Push pageErrors to errors * fix done hook, errors are 2nd param * Add generator hooks to nuxt-build for spa mode * Added a cli integration test for bin/nuxt-(build|start|generate) * Removed unnecessary waitFor * Use pify instead util.promisify for v6 compatibility * Fix windows build You cant execute .js files directly on Windows/Appveyor so call node with nuxt-*.js file as argument * Fix windows build (2) Use correct folder separators in text search * Fix possible timing quirck in children.path.test
94 lines
2.4 KiB
JavaScript
94 lines
2.4 KiB
JavaScript
import test from 'ava'
|
|
import { resolve, sep } from 'path'
|
|
import rp from 'request-promise-native'
|
|
import { Utils } from '../index.js'
|
|
import pify from 'pify'
|
|
import { exec, spawn } from 'child_process'
|
|
|
|
const execify = pify(exec, { multiArgs: true })
|
|
const rootDir = resolve(__dirname, 'fixtures/basic')
|
|
|
|
const port = 4011
|
|
const url = (route) => 'http://localhost:' + port + route
|
|
|
|
test('bin/nuxt-build', async t => {
|
|
const binBuild = resolve(__dirname, '..', 'bin', 'nuxt-build')
|
|
|
|
const [ stdout, stderr ] = await execify(`node ${binBuild} ${rootDir}`)
|
|
|
|
t.true(stdout.includes('server-bundle.json'))
|
|
t.true(stderr.includes('Building done'))
|
|
})
|
|
|
|
test('bin/nuxt-start', async t => {
|
|
const binStart = resolve(__dirname, '..', 'bin', 'nuxt-start')
|
|
|
|
let stdout = ''
|
|
let stderr = ''
|
|
let error
|
|
let exitCode
|
|
|
|
const env = process.env
|
|
env.PORT = port
|
|
|
|
const nuxtStart = spawn('node', [binStart, rootDir], { env: env })
|
|
|
|
nuxtStart.stdout.on('data', (data) => {
|
|
stdout += data
|
|
})
|
|
|
|
nuxtStart.stderr.on('data', (data) => {
|
|
stderr += data
|
|
})
|
|
|
|
nuxtStart.on('error', (err) => {
|
|
error = err
|
|
})
|
|
|
|
nuxtStart.on('close', (code) => {
|
|
exitCode = code
|
|
})
|
|
|
|
// Give the process max 10s to start
|
|
let iterator = 0
|
|
while (!stdout.includes('OPEN') && iterator < 40) {
|
|
await Utils.waitFor(250)
|
|
iterator++
|
|
}
|
|
|
|
t.is(error, undefined)
|
|
t.true(stdout.includes('OPEN'))
|
|
|
|
const html = await rp(url('/users/1'))
|
|
t.true(html.includes('<h1>User: 1</h1>'))
|
|
|
|
nuxtStart.kill()
|
|
|
|
// Wait max 10s for the process to be killed
|
|
iterator = 0
|
|
while (exitCode === undefined && iterator < 40) { // eslint-disable-line no-unmodified-loop-condition
|
|
await Utils.waitFor(250)
|
|
iterator++
|
|
}
|
|
|
|
if (iterator >= 40) {
|
|
t.log(`WARN: we were unable to automatically kill the child process with pid: ${nuxtStart.pid}`)
|
|
}
|
|
|
|
t.is(stderr, '')
|
|
t.is(exitCode, null)
|
|
})
|
|
|
|
test('bin/nuxt-generate', async t => {
|
|
const binGenerate = resolve(__dirname, '..', 'bin', 'nuxt-generate')
|
|
|
|
const [ stdout, stderr ] = await execify(`node ${binGenerate} ${rootDir}`)
|
|
|
|
t.true(stdout.includes('server-bundle.json'))
|
|
t.true(stderr.includes('Destination folder cleaned'))
|
|
t.true(stderr.includes('Static & build files copied'))
|
|
t.true(stderr.includes(`Generate file: ${sep}users${sep}1${sep}index.html`))
|
|
t.true(stderr.includes('Error report'))
|
|
t.true(stderr.includes('Generate done'))
|
|
})
|