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('