Nuxt/test/unit/custom-dirs.test.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-02-03 11:54:16 +00:00
import rp from 'request-promise-native'
2018-03-19 10:06:45 +00:00
import { Nuxt } from '../../'
import { loadFixture, getPort } from '../utils'
2018-02-02 16:58:51 +00:00
2018-03-18 23:41:14 +00:00
let port
2018-02-03 11:54:16 +00:00
const url = route => 'http://localhost:' + port + route
2018-02-02 16:58:51 +00:00
let nuxt = null
2018-03-18 19:31:32 +00:00
describe('custom-dirs', () => {
beforeAll(async () => {
2018-03-18 23:41:14 +00:00
const config = loadFixture('custom-dirs')
2018-02-02 16:58:51 +00:00
nuxt = new Nuxt(config)
2018-03-18 23:41:14 +00:00
port = await getPort()
await nuxt.listen(port, 'localhost')
})
2018-02-02 16:58:51 +00:00
2018-03-18 19:31:32 +00:00
test('custom assets directory', async () => {
const { html } = await nuxt.renderRoute('/')
expect(html.includes('.global-css-selector')).toBe(true)
})
2018-02-03 11:54:16 +00:00
2018-03-18 19:31:32 +00:00
test('custom layouts directory', async () => {
const { html } = await nuxt.renderRoute('/')
expect(html.includes('<p>I have custom layouts directory</p>')).toBe(true)
})
2018-02-03 18:41:43 +00:00
2018-03-18 19:31:32 +00:00
test('custom middleware directory', async () => {
const window = await nuxt.renderAndGetWindow(url('/user-agent'))
const html = window.document.body.innerHTML
expect(html.includes('<pre>Mozilla')).toBe(true)
})
2018-02-03 23:24:45 +00:00
2018-03-18 19:31:32 +00:00
test('custom pages directory', async () => {
const { html } = await nuxt.renderRoute('/')
expect(html.includes('<h1>I have custom pages directory</h1>')).toBe(true)
})
2018-02-02 16:58:51 +00:00
2018-03-18 19:31:32 +00:00
test('custom static directory', async () => {
const { headers } = await rp(url('/test.txt'), {
resolveWithFullResponse: true
})
expect(headers['cache-control']).toBe('public, max-age=0')
2018-02-03 11:54:16 +00:00
})
2018-03-18 19:31:32 +00:00
// Close server and ask nuxt to stop listening to file changes
test('Closing server and nuxt.js', async () => {
await nuxt.close()
})
2018-02-02 16:58:51 +00:00
})