refactor: simplify killNuxt

This commit is contained in:
Clark Du 2018-08-12 13:40:27 +01:00
parent 04e53b0f9f
commit 141a54a1e3
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9

View File

@ -9,17 +9,12 @@ const rootDir = resolve(__dirname, '..', 'fixtures/cli')
const url = route => 'http://localhost:' + port + route const url = route => 'http://localhost:' + port + route
const nuxtBin = resolve(__dirname, '..', '..', 'bin', 'nuxt') const nuxtBin = resolve(__dirname, '..', '..', 'bin', 'nuxt')
const killNuxt = async (nuxtInt) => { const close = async (nuxtInt) => {
let exitCode nuxtInt.kill('SIGKILL')
nuxtInt.on('close', (code) => { exitCode = code })
nuxtInt.kill()
// Wait max 10s for the process to be killed // Wait max 10s for the process to be killed
if (await waitUntil(() => exitCode !== undefined, 10)) { if (await waitUntil(() => nuxtInt.killed, 10)) {
console.warn( // eslint-disable-line no-console // eslint-disable-next-line no-console
`we were unable to automatically kill the child process with pid: ${ console.warn(`Unable to close process with pid: ${nuxtInt.pid}`)
nuxtInt.pid
}`
)
} }
} }
@ -44,7 +39,7 @@ describe.skip.appveyor('cli', () => {
stdout.indexOf('Compiled client') !== stdout.indexOf('Compiled client') !==
stdout.lastIndexOf('Compiled client') stdout.lastIndexOf('Compiled client')
) )
await killNuxt(nuxtDev) await close(nuxtDev)
}) })
test('nuxt start', async () => { test('nuxt start', async () => {
@ -75,6 +70,6 @@ describe.skip.appveyor('cli', () => {
const html = await rp(url('/')) const html = await rp(url('/'))
expect(html).toMatch(('<div>CLI Test</div>')) expect(html).toMatch(('<div>CLI Test</div>'))
await killNuxt(nuxtStart) await close(nuxtStart)
}) })
}) })