2018-02-02 16:58:51 +00:00
|
|
|
import test from 'ava'
|
2018-02-03 11:54:16 +00:00
|
|
|
import rp from 'request-promise-native'
|
2018-02-02 16:58:51 +00:00
|
|
|
import { Nuxt, Builder } from '..'
|
|
|
|
import { interceptLog } from './helpers/console'
|
2018-03-16 16:12:06 +00:00
|
|
|
import { loadConfig } from './helpers/config'
|
2018-02-02 16:58:51 +00:00
|
|
|
|
2018-02-03 11:54:16 +00:00
|
|
|
const port = 4007
|
|
|
|
const url = route => 'http://localhost:' + port + route
|
|
|
|
|
2018-02-02 16:58:51 +00:00
|
|
|
let nuxt = null
|
|
|
|
let builder = null
|
|
|
|
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
|
|
test.before('Init Nuxt.js', async t => {
|
2018-03-16 16:12:06 +00:00
|
|
|
const config = loadConfig('/custom-dirs', { dev: false })
|
2018-02-02 16:58:51 +00:00
|
|
|
|
|
|
|
const logSpy = await interceptLog(async () => {
|
|
|
|
nuxt = new Nuxt(config)
|
|
|
|
builder = new Builder(nuxt)
|
|
|
|
await builder.build()
|
|
|
|
await nuxt.listen(4007, 'localhost')
|
|
|
|
})
|
|
|
|
|
|
|
|
t.true(logSpy.calledWithMatch('DONE'))
|
|
|
|
t.true(logSpy.calledWithMatch('OPEN'))
|
|
|
|
})
|
|
|
|
|
2018-02-03 23:24:45 +00:00
|
|
|
test('custom assets directory', async t => {
|
2018-02-03 11:54:16 +00:00
|
|
|
const { html } = await nuxt.renderRoute('/')
|
|
|
|
t.true(html.includes('.global-css-selector'))
|
|
|
|
})
|
|
|
|
|
2018-02-03 23:24:45 +00:00
|
|
|
test('custom layouts directory', async t => {
|
2018-02-03 18:41:43 +00:00
|
|
|
const { html } = await nuxt.renderRoute('/')
|
|
|
|
t.true(html.includes('<p>I have custom layouts directory</p>'))
|
|
|
|
})
|
|
|
|
|
2018-02-03 23:24:45 +00:00
|
|
|
test('custom middleware directory', async t => {
|
|
|
|
const window = await nuxt.renderAndGetWindow(url('/user-agent'))
|
|
|
|
const html = window.document.body.innerHTML
|
|
|
|
t.true(html.includes('<pre>Mozilla'))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('custom pages directory', async t => {
|
2018-02-02 16:58:51 +00:00
|
|
|
const { html } = await nuxt.renderRoute('/')
|
|
|
|
t.true(html.includes('<h1>I have custom pages directory</h1>'))
|
|
|
|
})
|
|
|
|
|
2018-02-03 23:24:45 +00:00
|
|
|
test('custom static directory', async t => {
|
2018-02-03 11:54:16 +00:00
|
|
|
const { headers } = await rp(url('/test.txt'), {
|
|
|
|
resolveWithFullResponse: true
|
|
|
|
})
|
|
|
|
t.is(headers['cache-control'], 'public, max-age=0')
|
2018-02-03 11:10:58 +00:00
|
|
|
})
|
|
|
|
|
2018-02-02 16:58:51 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
test.after.always('Closing server and nuxt.js', async t => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|