mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-05 21:53:56 +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
72 lines
2.1 KiB
JavaScript
Executable File
72 lines
2.1 KiB
JavaScript
Executable File
import test from 'ava'
|
|
import { resolve, normalize } from 'path'
|
|
import rp from 'request-promise-native'
|
|
import { Nuxt, Builder } from '..'
|
|
import { intercept } from './helpers/console'
|
|
|
|
const port = 4006
|
|
const url = (route) => 'http://localhost:' + port + route
|
|
|
|
let nuxt = null
|
|
let builder = null
|
|
let buildSpies = null
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
test.serial('Init Nuxt.js', async t => {
|
|
const rootDir = resolve(__dirname, 'fixtures/module')
|
|
const config = require(resolve(rootDir, 'nuxt.config.js'))
|
|
config.rootDir = rootDir
|
|
config.dev = false
|
|
nuxt = new Nuxt(config)
|
|
builder = new Builder(nuxt)
|
|
|
|
buildSpies = await intercept({ log: true, error: true }, async () => {
|
|
await builder.build()
|
|
await nuxt.listen(port, 'localhost')
|
|
})
|
|
|
|
t.true(buildSpies.log.calledWithMatch('DONE'))
|
|
t.true(buildSpies.log.calledWithMatch('OPEN'))
|
|
})
|
|
|
|
test.serial('Vendor', async t => {
|
|
t.true(nuxt.options.build.vendor.indexOf('lodash') !== -1, 'lodash added to config')
|
|
})
|
|
|
|
test.serial('Plugin', async t => {
|
|
t.true(normalize(nuxt.options.plugins[0].src)
|
|
.includes(normalize('fixtures/module/.nuxt/basic.reverse.')), 'plugin added to config')
|
|
const { html } = await nuxt.renderRoute('/')
|
|
t.true(html.includes('<h1>TXUN</h1>'), 'plugin works')
|
|
})
|
|
|
|
test.serial('Hooks', async t => {
|
|
t.is(nuxt.__module_hook, 1)
|
|
t.is(nuxt.__renderer_hook, 2)
|
|
t.is(nuxt.__builder_hook, 3)
|
|
})
|
|
|
|
test.serial('Hooks - Functional', async t => {
|
|
t.true(nuxt.__ready_called__)
|
|
t.true(builder.__build_done__)
|
|
})
|
|
|
|
test.serial('Hooks - Error', async t => {
|
|
t.true(buildSpies.error.calledWithMatch(/build:extendRoutes/))
|
|
})
|
|
|
|
test('Middleware', async t => {
|
|
let response = await rp(url('/api'))
|
|
t.is(response, 'It works!', '/api response is correct')
|
|
})
|
|
|
|
test('Hooks - Use external middleware before render', async t => {
|
|
let response = await rp(url('/use-middleware'))
|
|
t.is(response, 'Use external middleware')
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
test.after.always('Closing server and nuxt.js', async t => {
|
|
await nuxt.close()
|
|
})
|