Nuxt/test/unit/module.test.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-03-16 16:12:06 +00:00
import { normalize } from 'path'
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-03-18 19:31:32 +00:00
beforeAll(async () => {
2018-03-18 23:41:14 +00:00
const config = loadFixture('module')
nuxt = new Nuxt(config)
2018-03-18 23:41:14 +00:00
port = await getPort()
2018-03-18 19:31:32 +00:00
await nuxt.listen(port, 'localhost')
2018-03-18 23:41:14 +00:00
})
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)
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)
2017-11-19 14:35:11 +00:00
})
2018-03-18 23:41:14 +00:00
// test('Hooks - Error', async () => {
// expect(buildSpies.error.calledWithMatch(/build:extendRoutes/)).toBe(true)
// })
2018-03-18 19:31:32 +00:00
test('Middleware', async () => {
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 () => {
await nuxt.close()
2017-05-14 22:33:31 +00:00
})