2018-08-22 21:54:08 +00:00
|
|
|
import consola from 'consola'
|
2018-08-10 07:41:23 +00:00
|
|
|
import { Builder, getPort, loadFixture, Nuxt, rp } from '../utils'
|
2017-06-16 12:49:35 +00:00
|
|
|
|
2018-03-18 23:41:14 +00:00
|
|
|
let port
|
2018-01-13 05:22:11 +00:00
|
|
|
const url = route => 'http://localhost:' + port + route
|
2016-12-21 19:51:43 +00:00
|
|
|
|
|
|
|
let nuxt = null
|
2018-08-20 12:19:09 +00:00
|
|
|
let builder = null
|
2018-05-06 19:29:59 +00:00
|
|
|
let transpile = null
|
2018-08-22 15:47:52 +00:00
|
|
|
let output = null
|
2016-12-21 19:51:43 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
describe('basic dev', () => {
|
|
|
|
beforeAll(async () => {
|
2018-08-17 20:25:23 +00:00
|
|
|
const config = await loadFixture('basic', {
|
2018-03-29 07:11:34 +00:00
|
|
|
dev: true,
|
2018-04-15 16:26:45 +00:00
|
|
|
debug: true,
|
2018-03-29 07:11:34 +00:00
|
|
|
buildDir: '.nuxt-dev',
|
|
|
|
build: {
|
2018-08-22 15:08:51 +00:00
|
|
|
filenames: {
|
2018-08-22 21:54:08 +00:00
|
|
|
app: ({ isDev }) => {
|
|
|
|
return isDev ? 'test-app.js' : 'test-app.[contenthash].js'
|
2018-08-22 15:47:52 +00:00
|
|
|
},
|
|
|
|
chunk: 'test-[name].[contenthash].js'
|
2018-08-22 15:08:51 +00:00
|
|
|
},
|
2018-05-06 19:29:59 +00:00
|
|
|
transpile: [
|
2018-05-06 19:35:32 +00:00
|
|
|
'vue\\.test\\.js',
|
2018-05-06 19:29:59 +00:00
|
|
|
/vue-test/
|
|
|
|
],
|
2018-08-22 15:47:52 +00:00
|
|
|
extend({ module: { rules }, output: wpOutput }, { isClient }) {
|
2018-05-06 19:29:59 +00:00
|
|
|
if (isClient) {
|
|
|
|
const babelLoader = rules.find(loader => loader.test.test('.jsx'))
|
2018-08-06 00:12:44 +00:00
|
|
|
transpile = file => !babelLoader.exclude(file)
|
2018-08-22 15:47:52 +00:00
|
|
|
output = wpOutput
|
2018-05-06 19:29:59 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-29 07:11:34 +00:00
|
|
|
}
|
|
|
|
})
|
2018-03-18 23:41:14 +00:00
|
|
|
nuxt = new Nuxt(config)
|
2018-08-20 12:19:09 +00:00
|
|
|
builder = new Builder(nuxt)
|
|
|
|
await builder.build()
|
2018-03-18 23:41:14 +00:00
|
|
|
port = await getPort()
|
2017-12-17 19:30:26 +00:00
|
|
|
await nuxt.listen(port, 'localhost')
|
2018-03-18 23:41:14 +00:00
|
|
|
})
|
2018-03-18 19:31:32 +00:00
|
|
|
|
2018-08-20 12:19:09 +00:00
|
|
|
test('Check build:done hook called', () => {
|
2018-08-20 14:20:45 +00:00
|
|
|
expect(builder.__hook_built_called__).toBe(true)
|
2018-08-20 12:19:09 +00:00
|
|
|
})
|
|
|
|
|
2018-08-10 07:41:23 +00:00
|
|
|
test('Config: build.transpile', () => {
|
2018-05-14 07:22:44 +00:00
|
|
|
expect(transpile('vue-test')).toBe(true)
|
2018-05-14 07:21:40 +00:00
|
|
|
expect(transpile('node_modules/test.js')).toBe(false)
|
|
|
|
expect(transpile('node_modules/vue-test')).toBe(true)
|
|
|
|
expect(transpile('node_modules/vue.test.js')).toBe(true)
|
|
|
|
expect(transpile('node_modules/test.vue.js')).toBe(true)
|
2018-05-06 19:29:59 +00:00
|
|
|
})
|
2018-03-18 19:31:32 +00:00
|
|
|
|
2018-08-22 15:47:52 +00:00
|
|
|
test('Config: build.filenames', () => {
|
2018-08-22 21:54:08 +00:00
|
|
|
expect(output.filename).toBe('test-app.js')
|
|
|
|
expect(output.chunkFilename).toBe('test-[name].[contenthash].js')
|
|
|
|
expect(consola.warn).toBeCalledWith(
|
|
|
|
'Notice: Please do not use contenthash in dev mode to prevent memory leak'
|
|
|
|
)
|
2018-08-22 15:08:51 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/stateless', async () => {
|
|
|
|
const window = await nuxt.renderAndGetWindow(url('/stateless'))
|
|
|
|
const html = window.document.body.innerHTML
|
|
|
|
expect(html.includes('<h1>My component!</h1>')).toBe(true)
|
2017-12-17 19:30:26 +00:00
|
|
|
})
|
|
|
|
|
2018-08-21 16:35:46 +00:00
|
|
|
test('Check render:routeDone hook called', () => {
|
|
|
|
expect(nuxt.__hook_render_routeDone__).toBe('/stateless')
|
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +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, '')
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
2018-04-15 16:26:45 +00:00
|
|
|
test('/__open-in-editor (open-in-editor)', async () => {
|
|
|
|
const { body } = await rp(
|
|
|
|
url('/__open-in-editor?file=pages/index.vue'),
|
|
|
|
{ resolveWithFullResponse: true }
|
|
|
|
)
|
|
|
|
expect(body).toBe('')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/__open-in-editor should return error (open-in-editor)', async () => {
|
|
|
|
await expect(rp(url('/__open-in-editor?file='))).rejects.toMatchObject({
|
|
|
|
statusCode: 500,
|
|
|
|
error: 'launch-editor-middleware: required query param "file" is missing.'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/error should return error stack trace (Youch)', async () => {
|
|
|
|
await expect(nuxt.renderAndGetWindow(url('/error'))).rejects.toMatchObject({
|
|
|
|
statusCode: 500
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/error no source-map (Youch)', async () => {
|
|
|
|
const sourceMaps = nuxt.renderer.resources.serverBundle.maps
|
|
|
|
nuxt.renderer.resources.serverBundle.maps = {}
|
|
|
|
|
|
|
|
await expect(nuxt.renderAndGetWindow(url('/error'))).rejects.toMatchObject({
|
|
|
|
statusCode: 500
|
|
|
|
})
|
|
|
|
|
|
|
|
nuxt.renderer.resources.serverBundle.maps = sourceMaps
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/error should return json format error (Youch)', async () => {
|
|
|
|
const opts = {
|
|
|
|
headers: {
|
|
|
|
accept: 'application/json'
|
|
|
|
},
|
|
|
|
resolveWithFullResponse: true
|
|
|
|
}
|
|
|
|
await expect(rp(url('/error'), opts)).rejects.toMatchObject({
|
|
|
|
statusCode: 500,
|
|
|
|
response: {
|
|
|
|
headers: {
|
|
|
|
'content-type': 'text/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
2018-03-30 09:20:16 +00:00
|
|
|
afterAll(async () => {
|
2018-03-18 19:31:32 +00:00
|
|
|
await nuxt.close()
|
|
|
|
})
|
2016-12-21 19:51:43 +00:00
|
|
|
})
|