mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-06 06:03:58 +00:00
fffe741986
Add stdout/stderr to console helpers Remove separate nosubfolders test file in favor of inclusion in basic.generate Add build.stats to silence webpack output Add .always to after hooks: (1) fixes issue with basic.dev test that watch.js is empty when one of the test fails and (2) fixes that sometimes when running multiple tests that failed after eachother the port is still used as the server did not automatically get killed Change all init nuxt before test to serial tests and add tests for DONE and OPEN logs
88 lines
2.4 KiB
JavaScript
88 lines
2.4 KiB
JavaScript
import test from 'ava'
|
|
import { resolve } from 'path'
|
|
import { intercept, release } from './helpers/console'
|
|
import { Nuxt, Builder, Utils } from '..'
|
|
import { truncateSync, readFileSync, writeFileSync } from 'fs'
|
|
|
|
const port = 4001
|
|
const url = (route) => 'http://localhost:' + port + route
|
|
const rootDir = resolve(__dirname, 'fixtures/basic')
|
|
const pluginPath = resolve(rootDir, 'plugins', 'watch.js')
|
|
const pluginContent = readFileSync(pluginPath)
|
|
|
|
let nuxt = null
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
test.serial('Init Nuxt.js', async t => {
|
|
const options = {
|
|
rootDir,
|
|
buildDir: '.nuxt-dev',
|
|
dev: true,
|
|
build: {
|
|
stats: false,
|
|
profile: true
|
|
},
|
|
plugins: [
|
|
'~/plugins/watch.js'
|
|
]
|
|
}
|
|
|
|
const spies = await intercept({ log: true, stderr: true }, async () => {
|
|
nuxt = new Nuxt(options)
|
|
await new Builder(nuxt).build()
|
|
await nuxt.listen(port, 'localhost')
|
|
})
|
|
|
|
t.true(spies.log.calledWithMatch('DONE'))
|
|
t.true(spies.log.calledWithMatch('OPEN'))
|
|
})
|
|
|
|
test.serial('remove mixins in live reloading', async t => {
|
|
const spies = await intercept()
|
|
await nuxt.renderRoute(url('/'))
|
|
t.true(spies.log.calledWith('I am mixin'))
|
|
|
|
truncateSync(pluginPath)
|
|
await new Promise(async (resolve, reject) => {
|
|
let waitTimes = 0
|
|
while (spies.log.neverCalledWithMatch(/Compiled successfully/)) {
|
|
if (waitTimes++ >= 20) {
|
|
t.fail('Dev server doesn\'t reload after 2000ms')
|
|
reject(Error())
|
|
}
|
|
await Utils.waitFor(100)
|
|
}
|
|
resolve()
|
|
})
|
|
spies.log.reset()
|
|
|
|
await nuxt.renderRoute(url('/'))
|
|
t.true(spies.log.neverCalledWith('I am mixin'))
|
|
t.is(spies.error.getCall(0).args[0].statusCode, 404)
|
|
release()
|
|
})
|
|
|
|
test.serial('/stateless', async t => {
|
|
const spies = await intercept()
|
|
const window = await nuxt.renderAndGetWindow(url('/stateless'))
|
|
const html = window.document.body.innerHTML
|
|
t.true(html.includes('<h1>My component!</h1>'))
|
|
t.true(spies.info.calledWithMatch('You are running Vue in development mode.'))
|
|
release()
|
|
})
|
|
|
|
// test('/_nuxt/test.hot-update.json should returns empty html', async t => {
|
|
// try {
|
|
// await rp(url('/_nuxt/test.hot-update.json'))
|
|
// } catch (err) {
|
|
// t.is(err.statusCode, 404)
|
|
// t.is(err.response.body, '')
|
|
// }
|
|
// })
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
test.after.always('Closing server and nuxt.js', async t => {
|
|
writeFileSync(pluginPath, pluginContent)
|
|
await nuxt.close()
|
|
})
|