Nuxt/test/custom-dirs.test.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-02-02 16:58:51 +00:00
import test from 'ava'
import { resolve } from 'path'
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-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 => {
const rootDir = resolve(__dirname, 'fixtures/custom-dirs')
2018-02-02 16:58:51 +00:00
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
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 11:54:16 +00:00
test('/ (custom assets directory)', async t => {
const { html } = await nuxt.renderRoute('/')
t.true(html.includes('.global-css-selector'))
})
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 11:54:16 +00:00
test('Check /test.txt with custom static directory', async t => {
const { headers } = await rp(url('/test.txt'), {
resolveWithFullResponse: true
})
t.is(headers['cache-control'], 'public, max-age=0')
})
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()
})