2018-03-16 16:12:06 +00:00
|
|
|
import { normalize } from 'path'
|
2018-08-07 09:24:01 +00:00
|
|
|
import consola from 'consola'
|
2018-03-27 22:28:17 +00:00
|
|
|
import { loadFixture, getPort, Nuxt, rp } from '../utils'
|
2018-03-16 19:52:17 +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
|
2017-05-14 22:33:31 +00:00
|
|
|
|
|
|
|
let nuxt = null
|
2018-03-18 23:41:14 +00:00
|
|
|
// let buildSpies = null
|
2017-05-14 22:33:31 +00:00
|
|
|
|
2018-05-03 19:23:45 +00:00
|
|
|
describe('module', () => {
|
2018-03-30 08:38:22 +00:00
|
|
|
beforeAll(async () => {
|
2018-08-17 20:25:23 +00:00
|
|
|
const config = await loadFixture('module')
|
2018-03-30 08:38:22 +00:00
|
|
|
nuxt = new Nuxt(config)
|
|
|
|
port = await getPort()
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.listen(port, 'localhost')
|
2018-03-30 08:38:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('Plugin', async () => {
|
|
|
|
expect(normalize(nuxt.options.plugins[0].src).includes(
|
|
|
|
normalize('fixtures/module/.nuxt/basic.reverse.')
|
|
|
|
)).toBe(true)
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/')
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>TXUN</h1>')
|
2018-03-30 08:38:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('Layout', async () => {
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(nuxt.options.layouts.layout).toContain('layout')
|
2018-03-30 08:38:22 +00:00
|
|
|
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/layout')
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>Module Layouts</h1>')
|
2018-03-30 08:38:22 +00:00
|
|
|
})
|
|
|
|
|
2018-09-02 09:22:10 +00:00
|
|
|
test('/404 should display the module error layout', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/404')
|
2018-09-02 09:22:10 +00:00
|
|
|
expect(html).toContain('You should see the error in a different Vue!')
|
|
|
|
})
|
|
|
|
|
2018-08-10 07:41:23 +00:00
|
|
|
test('Hooks', () => {
|
2018-03-30 08:38:22 +00:00
|
|
|
expect(nuxt.__module_hook).toBe(1)
|
|
|
|
expect(nuxt.__renderer_hook).toBe(2)
|
|
|
|
})
|
|
|
|
|
2018-08-10 07:41:23 +00:00
|
|
|
test('Hooks - Functional', () => {
|
2018-03-30 08:38:22 +00:00
|
|
|
expect(nuxt.__ready_called__).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
// test('Hooks - Error', async () => {
|
|
|
|
// expect(buildSpies.error.calledWithMatch(/build:extendRoutes/)).toBe(true)
|
|
|
|
// })
|
|
|
|
|
|
|
|
test('Middleware', async () => {
|
2018-08-08 10:54:05 +00:00
|
|
|
const response = await rp(url('/api'))
|
2018-03-30 08:38:22 +00:00
|
|
|
expect(response).toBe('It works!')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Hooks - Use external middleware before render', async () => {
|
2018-08-08 10:54:05 +00:00
|
|
|
const response = await rp(url('/use-middleware'))
|
2018-03-30 08:38:22 +00:00
|
|
|
expect(response).toBe('Use external middleware')
|
|
|
|
})
|
|
|
|
|
2018-05-03 19:49:37 +00:00
|
|
|
test('Hooks - render context', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.renderRoute('/render-context')
|
2018-05-03 19:49:37 +00:00
|
|
|
expect(nuxt.__render_context).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
2018-08-10 07:41:23 +00:00
|
|
|
test('AddVendor - deprecated', () => {
|
2018-08-07 09:24:01 +00:00
|
|
|
nuxt.moduleContainer.addVendor('nuxt-test')
|
|
|
|
expect(consola.warn).toHaveBeenCalledWith('addVendor has been deprecated due to webpack4 optimization')
|
|
|
|
})
|
|
|
|
|
2018-03-30 08:38:22 +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-30 08:38:22 +00:00
|
|
|
await nuxt.close()
|
|
|
|
})
|
2017-05-14 22:33:31 +00:00
|
|
|
})
|