2018-06-06 12:31:43 +00:00
|
|
|
import { spawn } from 'child_process'
|
2018-08-08 18:51:57 +00:00
|
|
|
import { resolve, join } from 'path'
|
|
|
|
import { writeFileSync } from 'fs-extra'
|
2018-06-06 12:31:43 +00:00
|
|
|
import { getPort, rp, waitUntil } from '../utils'
|
2018-05-15 11:45:09 +00:00
|
|
|
|
2018-05-16 07:10:20 +00:00
|
|
|
let port
|
2018-06-06 12:31:43 +00:00
|
|
|
const rootDir = resolve(__dirname, '..', 'fixtures/cli')
|
|
|
|
|
2018-01-11 16:33:30 +00:00
|
|
|
const url = route => 'http://localhost:' + port + route
|
2018-03-19 10:06:45 +00:00
|
|
|
const nuxtBin = resolve(__dirname, '..', '..', 'bin', 'nuxt')
|
2017-11-23 22:31:54 +00:00
|
|
|
|
2018-08-08 18:51:57 +00:00
|
|
|
const killNuxt = async (nuxtInt) => {
|
|
|
|
let exitCode
|
|
|
|
nuxtInt.on('close', (code) => { exitCode = code })
|
|
|
|
nuxtInt.kill()
|
|
|
|
// Wait max 10s for the process to be killed
|
|
|
|
if (await waitUntil(() => exitCode !== undefined, 10)) {
|
|
|
|
console.warn( // eslint-disable-line no-console
|
|
|
|
`we were unable to automatically kill the child process with pid: ${
|
|
|
|
nuxtInt.pid
|
|
|
|
}`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 16:23:46 +00:00
|
|
|
describe.skip.appveyor('cli', () => {
|
2018-08-08 18:51:57 +00:00
|
|
|
test('nuxt dev', async () => {
|
|
|
|
let stdout = ''
|
|
|
|
const env = process.env
|
|
|
|
env.PORT = port = await getPort()
|
|
|
|
|
|
|
|
const nuxtDev = spawn('node', [nuxtBin, 'dev', rootDir], { env })
|
|
|
|
nuxtDev.stdout.on('data', (data) => { stdout += data })
|
|
|
|
|
|
|
|
// Wait max 20s for the starting
|
|
|
|
await waitUntil(() => stdout.includes(`${port}`))
|
|
|
|
|
|
|
|
// Change file specified in `watchers` (nuxt.config.js)
|
|
|
|
const customFilePath = join(rootDir, 'custom.file')
|
|
|
|
writeFileSync(customFilePath, 'This file is used to test custom chokidar watchers.')
|
|
|
|
|
|
|
|
// Must see two compilations in the log
|
|
|
|
expect(
|
|
|
|
stdout.indexOf('Compiled client') !==
|
|
|
|
stdout.lastIndexOf('Compiled client')
|
|
|
|
)
|
|
|
|
await killNuxt(nuxtDev)
|
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('nuxt start', async () => {
|
|
|
|
let stdout = ''
|
|
|
|
let error
|
|
|
|
|
|
|
|
const env = process.env
|
2018-06-06 12:31:43 +00:00
|
|
|
env.PORT = port = await getPort()
|
2018-03-18 19:31:32 +00:00
|
|
|
|
2018-08-08 18:51:57 +00:00
|
|
|
await new Promise((resolve) => {
|
|
|
|
const nuxtBuild = spawn('node', [nuxtBin, 'build', rootDir], { env })
|
|
|
|
nuxtBuild.on('close', () => { resolve() })
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
|
|
|
|
2018-08-08 18:51:57 +00:00
|
|
|
const nuxtStart = spawn('node', [nuxtBin, 'start', rootDir], { env })
|
2018-03-18 19:31:32 +00:00
|
|
|
|
2018-08-08 18:51:57 +00:00
|
|
|
nuxtStart.stdout.on('data', (data) => { stdout += data })
|
|
|
|
nuxtStart.on('error', (err) => { error = err })
|
2018-03-18 19:31:32 +00:00
|
|
|
|
2018-06-06 12:31:43 +00:00
|
|
|
// Wait max 20s for the starting
|
2018-08-08 18:51:57 +00:00
|
|
|
if (await waitUntil(() => stdout.includes(`${port}`))) {
|
2018-06-06 12:31:43 +00:00
|
|
|
error = 'server failed to start successfully in 20 seconds'
|
2018-03-18 19:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBe(undefined)
|
2018-06-06 12:31:43 +00:00
|
|
|
expect(stdout.includes('Listening on')).toBe(true)
|
2018-03-18 19:31:32 +00:00
|
|
|
|
2018-06-06 12:31:43 +00:00
|
|
|
const html = await rp(url('/'))
|
|
|
|
expect(html).toMatch(('<div>CLI Test</div>'))
|
2018-03-18 19:31:32 +00:00
|
|
|
|
2018-08-08 18:51:57 +00:00
|
|
|
await killNuxt(nuxtStart)
|
2017-11-23 22:31:54 +00:00
|
|
|
})
|
|
|
|
})
|