Nuxt/test/basic.dev.test.js

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-12-21 19:51:43 +00:00
import test from 'ava'
import { resolve } from 'path'
import { intercept, release } from './helpers/console'
2018-01-04 15:53:06 +00:00
import { Nuxt, Builder } from '..'
2017-06-16 12:49:35 +00:00
2017-05-21 19:00:01 +00:00
const port = 4001
2018-01-13 05:22:11 +00:00
const url = route => 'http://localhost:' + port + route
2017-12-05 10:36:54 +00:00
const rootDir = resolve(__dirname, 'fixtures/basic')
2016-12-21 19:51:43 +00:00
let nuxt = null
// Init nuxt.js and create server listening on localhost:4000
test.serial('Init Nuxt.js', async t => {
2016-12-21 19:51:43 +00:00
const options = {
2017-12-05 10:36:54 +00:00
rootDir,
buildDir: '.nuxt-dev',
2017-12-05 10:36:54 +00:00
dev: true,
2017-12-13 08:04:57 +00:00
build: {
stats: false,
2017-12-21 03:35:23 +00:00
profile: true,
extractCSS: {
allChunks: true
}
2018-01-04 15:53:06 +00:00
}
2016-12-21 19:51:43 +00:00
}
2017-06-20 11:44:47 +00:00
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'))
2016-12-21 19:51:43 +00:00
})
// TODO: enable test when style-loader.js:60 was resolved
// test.serial('/extractCSS', async t => {
// const window = await nuxt.renderAndGetWindow(url('/extractCSS'))
// const html = window.document.head.innerHTML
// t.true(html.includes('vendor.css'))
// t.true(!html.includes('30px'))
// t.is(window.getComputedStyle(window.document.body).getPropertyValue('font-size'), '30px')
// })
2017-12-21 03:35:23 +00:00
test.serial('/stateless', async t => {
const spies = await intercept()
2016-12-21 19:51:43 +00:00
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()
2016-12-21 19:51:43 +00:00
})
2017-07-03 11:17:22 +00:00
// 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, '')
// }
// })
2017-05-16 13:12:30 +00:00
2016-12-21 19:51:43 +00:00
// Close server and ask nuxt to stop listening to file changes
test.after.always('Closing server and nuxt.js', async t => {
2017-06-20 12:55:52 +00:00
await nuxt.close()
2016-12-21 19:51:43 +00:00
})