2018-08-08 18:51:57 +00:00
|
|
|
import { resolve, join } from 'path'
|
2018-09-23 09:49:51 +00:00
|
|
|
import { spawn } from 'cross-spawn'
|
2018-08-08 18:51:57 +00:00
|
|
|
import { writeFileSync } from 'fs-extra'
|
2018-10-24 13:53:34 +00:00
|
|
|
import { getPort, rp, waitUntil, waitFor } 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-10-17 21:28:25 +00:00
|
|
|
|
2018-11-15 20:48:30 +00:00
|
|
|
const nuxtBin = resolve(__dirname, '../../packages/cli/bin/nuxt-cli.js')
|
2018-11-01 04:00:28 +00:00
|
|
|
const spawnNuxt = (command, opts) => spawn(nuxtBin, [command, rootDir], opts)
|
2017-11-23 22:31:54 +00:00
|
|
|
|
2018-08-12 12:40:27 +00:00
|
|
|
const close = async (nuxtInt) => {
|
|
|
|
nuxtInt.kill('SIGKILL')
|
2018-08-08 18:51:57 +00:00
|
|
|
// Wait max 10s for the process to be killed
|
2018-08-12 12:40:27 +00:00
|
|
|
if (await waitUntil(() => nuxtInt.killed, 10)) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.warn(`Unable to close process with pid: ${nuxtInt.pid}`)
|
2018-08-08 18:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-23 08:40:36 +00:00
|
|
|
describe.skip.win('cli', () => {
|
2018-08-08 18:51:57 +00:00
|
|
|
test('nuxt dev', async () => {
|
|
|
|
let stdout = ''
|
|
|
|
const env = process.env
|
|
|
|
env.PORT = port = await getPort()
|
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
const nuxtDev = spawnNuxt('dev', { env })
|
2018-08-08 18:51:57 +00:00
|
|
|
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.')
|
|
|
|
|
2018-08-14 18:35:25 +00:00
|
|
|
// Change file specified in `serverMiddleware` (nuxt.config.js)
|
|
|
|
const serverMiddlewarePath = join(rootDir, 'middleware.js')
|
|
|
|
writeFileSync(serverMiddlewarePath, '// This file is used to test custom chokidar watchers.\n')
|
|
|
|
|
|
|
|
// Wait 2s for picking up changes
|
2018-10-24 13:53:34 +00:00
|
|
|
await waitFor(2000)
|
2018-08-14 18:35:25 +00:00
|
|
|
|
|
|
|
// [Add actual test for changes here]
|
|
|
|
|
2018-08-12 12:40:27 +00:00
|
|
|
await close(nuxtDev)
|
2018-08-08 18:51:57 +00:00
|
|
|
})
|
|
|
|
|
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) => {
|
2018-10-17 21:28:25 +00:00
|
|
|
const nuxtBuild = spawnNuxt('build', { env })
|
2018-08-08 18:51:57 +00:00
|
|
|
nuxtBuild.on('close', () => { resolve() })
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
const nuxtStart = spawnNuxt('start', { 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-08-14 18:35:25 +00:00
|
|
|
// Wait max 40s for the starting
|
|
|
|
if (await waitUntil(() => stdout.includes(`${port}`), 40)) {
|
|
|
|
error = 'server failed to start successfully in 40 seconds'
|
2018-03-18 19:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBe(undefined)
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(stdout).toContain('Listening on')
|
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-12 12:40:27 +00:00
|
|
|
await close(nuxtStart)
|
2017-11-23 22:31:54 +00:00
|
|
|
})
|
|
|
|
})
|