Nuxt/test/dll.test.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

import { promisify } from 'util'
2017-10-29 10:24:58 +00:00
import test from 'ava'
import { resolve } from 'path'
import fs from 'fs'
import { Nuxt, Builder } from '..'
2017-12-13 05:38:46 +00:00
import { interceptLog, release } from './helpers/console'
2017-10-29 10:24:58 +00:00
const readFile = promisify(fs.readFile)
const rootDir = resolve(__dirname, 'fixtures/dll')
2017-10-29 10:24:58 +00:00
const dllDir = resolve(rootDir, '.cache/client-dll')
const checkCache = (lib) => {
return async (t) => {
const manifest = await readFile(resolve(dllDir, `./${lib}-manifest.json`), 'utf-8')
t.truthy(JSON.parse(manifest).name)
t.true(fs.existsSync(resolve(dllDir, `./${JSON.parse(manifest).name}.js`)))
}
}
2017-11-20 02:54:37 +00:00
let nuxt
test.serial('Init Nuxt.js', async t => {
2017-10-29 10:24:58 +00:00
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = true
const logSpy = await interceptLog(async () => {
nuxt = new Nuxt(config)
await new Builder(nuxt).build()
})
t.true(logSpy.calledWithMatch('DONE'))
2017-10-29 10:24:58 +00:00
})
test('Check vue cache', checkCache('vue'))
test('Check vue-meta cache', checkCache('vue-meta'))
test('Check vue-router cache', checkCache('vue-router'))
2017-11-20 02:54:37 +00:00
test('Build with DllReferencePlugin', async t => {
2017-12-13 05:38:46 +00:00
const logSpy = await interceptLog()
2017-11-20 02:54:37 +00:00
await new Builder(nuxt).build()
2017-12-13 05:38:46 +00:00
release()
t.true(logSpy.withArgs('Using dll for 3 libs').calledOnce)
2017-11-20 02:54:37 +00:00
})
// Close server and ask nuxt to stop listening to file changes
test.after.always('Closing nuxt.js', t => {
2017-11-20 02:54:37 +00:00
nuxt.close()
})