2018-10-16 21:55:56 +00:00
|
|
|
import { resolve } from 'path'
|
|
|
|
import { promisify } from 'util'
|
|
|
|
import fs from 'fs'
|
|
|
|
import { getPort, loadFixture, Nuxt, rp } 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-08-17 20:25:23 +00:00
|
|
|
const config = await 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()
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.listen(port, 'localhost')
|
2018-03-18 23:41:14 +00:00
|
|
|
})
|
2018-02-02 16:58:51 +00:00
|
|
|
|
2018-10-16 21:55:56 +00:00
|
|
|
test('custom assets directory', async () => {
|
|
|
|
const readFile = promisify(fs.readFile)
|
|
|
|
|
|
|
|
const extractedIndexCss = resolve(__dirname, '..', 'fixtures/custom-dirs/.nuxt/dist/client/app.css')
|
|
|
|
const content = await readFile(extractedIndexCss, 'utf-8')
|
|
|
|
|
|
|
|
expect(content).toContain('.global-css-selector{color:red}')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
2018-02-03 11:54:16 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('custom layouts directory', async () => {
|
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('<p>I have custom layouts directory</p>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
2018-02-03 18:41:43 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('custom middleware directory', async () => {
|
2018-10-30 20:42:53 +00:00
|
|
|
const window = await nuxt.server.renderAndGetWindow(url('/user-agent'))
|
2018-03-18 19:31:32 +00:00
|
|
|
const html = window.document.body.innerHTML
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<pre>Mozilla')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
2018-02-03 23:24:45 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('custom pages directory', async () => {
|
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>I have custom pages directory</h1>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
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-02-03 11:10:58 +00:00
|
|
|
|
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()
|
|
|
|
})
|
2018-02-02 16:58:51 +00:00
|
|
|
})
|