2018-03-16 16:12:06 +00:00
|
|
|
import { normalize } from 'path'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
2017-05-14 22:33:31 +00:00
|
|
|
import rp from 'request-promise-native'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
2017-12-12 09:42:29 +00:00
|
|
|
import { Nuxt, Builder } from '..'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
2018-03-16 16:12:06 +00:00
|
|
|
import { loadConfig } from './helpers/config'
|
2017-05-14 22:33:31 +00:00
|
|
|
|
2017-05-21 19:00:01 +00:00
|
|
|
const port = 4006
|
2018-01-13 05:22:11 +00:00
|
|
|
const url = route => 'http://localhost:' + port + route
|
2017-05-14 22:33:31 +00:00
|
|
|
|
|
|
|
let nuxt = null
|
2017-11-19 14:35:11 +00:00
|
|
|
let builder = null
|
2017-12-17 19:30:26 +00:00
|
|
|
let buildSpies = null
|
2017-05-14 22:33:31 +00:00
|
|
|
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
2018-03-18 19:31:32 +00:00
|
|
|
beforeAll(async () => {
|
2018-03-16 16:12:06 +00:00
|
|
|
const config = loadConfig('module', { dev: false })
|
|
|
|
|
2017-05-31 14:21:16 +00:00
|
|
|
nuxt = new Nuxt(config)
|
2017-11-19 14:35:11 +00:00
|
|
|
builder = new Builder(nuxt)
|
2017-11-19 15:02:44 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
await builder.build()
|
|
|
|
await nuxt.listen(port, 'localhost')
|
|
|
|
}, 30000)
|
2017-06-20 11:44:47 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Plugin', async () => {
|
|
|
|
expect(normalize(nuxt.options.plugins[0].src).includes(
|
|
|
|
normalize('fixtures/module/.nuxt/basic.reverse.')
|
|
|
|
)).toBe(true)
|
2017-05-14 22:33:31 +00:00
|
|
|
const { html } = await nuxt.renderRoute('/')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>TXUN</h1>')).toBe(true)
|
2017-05-14 22:33:31 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Layout', async () => {
|
|
|
|
expect(nuxt.options.layouts.layout.includes('layout')).toBe(true)
|
2018-02-07 11:58:48 +00:00
|
|
|
|
|
|
|
const { html } = await nuxt.renderRoute('/layout')
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>Module Layouts</h1>')).toBe(true)
|
2018-02-07 11:58:48 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Hooks', async () => {
|
|
|
|
expect(nuxt.__module_hook).toBe(1)
|
|
|
|
expect(nuxt.__renderer_hook).toBe(2)
|
|
|
|
expect(nuxt.__builder_hook).toBe(3)
|
2017-07-17 19:38:02 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Hooks - Functional', async () => {
|
|
|
|
expect(nuxt.__ready_called__).toBe(true)
|
|
|
|
expect(builder.__build_done__).toBe(true)
|
2017-11-19 14:35:11 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Hooks - Error', async () => {
|
|
|
|
expect(buildSpies.error.calledWithMatch(/build:extendRoutes/)).toBe(true)
|
2017-12-17 19:30:26 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Middleware', async () => {
|
2017-12-17 19:30:26 +00:00
|
|
|
let response = await rp(url('/api'))
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(response).toBe('It works!')
|
2017-11-19 15:02:44 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Hooks - Use external middleware before render', async () => {
|
2017-12-07 08:09:49 +00:00
|
|
|
let response = await rp(url('/use-middleware'))
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(response).toBe('Use external middleware')
|
2017-12-07 08:09:49 +00:00
|
|
|
})
|
|
|
|
|
2017-05-14 22:33:31 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
2018-03-18 19:31:32 +00:00
|
|
|
test('Closing server and nuxt.js', async () => {
|
2017-12-17 19:30:26 +00:00
|
|
|
await nuxt.close()
|
2017-05-14 22:33:31 +00:00
|
|
|
})
|