2018-10-31 15:52:35 +00:00
|
|
|
import { loadFixture, Nuxt, Builder, BundleBuilder, listPaths, equalOrStartsWith } from './index'
|
2018-03-27 22:28:17 +00:00
|
|
|
|
2018-09-08 20:18:14 +00:00
|
|
|
export const buildFixture = function (fixture, callback, hooks = []) {
|
2018-09-18 14:26:41 +00:00
|
|
|
const pathsBefore = {}
|
|
|
|
let nuxt
|
|
|
|
|
2018-03-27 22:28:17 +00:00
|
|
|
test(`Build ${fixture}`, async () => {
|
2018-08-17 20:25:23 +00:00
|
|
|
const config = await loadFixture(fixture)
|
2018-09-18 14:26:41 +00:00
|
|
|
nuxt = new Nuxt(config)
|
|
|
|
|
|
|
|
pathsBefore.root = listPaths(nuxt.options.rootDir)
|
|
|
|
if (nuxt.options.rootDir !== nuxt.options.srcDir) {
|
|
|
|
pathsBefore.src = listPaths(nuxt.options.srcDir)
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:28:17 +00:00
|
|
|
const buildDone = jest.fn()
|
2018-09-08 20:18:14 +00:00
|
|
|
hooks.forEach(([hook, fn]) => nuxt.hook(hook, fn))
|
2018-03-27 22:28:17 +00:00
|
|
|
nuxt.hook('build:done', buildDone)
|
2018-10-31 15:52:35 +00:00
|
|
|
const builder = await new Builder(nuxt, BundleBuilder).build()
|
2018-03-27 22:28:17 +00:00
|
|
|
// 2: BUILD_DONE
|
|
|
|
expect(builder._buildStatus).toBe(2)
|
|
|
|
expect(buildDone).toHaveBeenCalledTimes(1)
|
2018-08-16 15:34:32 +00:00
|
|
|
if (typeof callback === 'function') {
|
|
|
|
callback(builder)
|
|
|
|
}
|
2018-07-24 16:24:10 +00:00
|
|
|
}, 120000)
|
2018-09-18 14:26:41 +00:00
|
|
|
|
|
|
|
test('Check changed files', () => {
|
|
|
|
expect.hasAssertions()
|
|
|
|
|
|
|
|
// When building Nuxt we only expect files to changed
|
|
|
|
// within the nuxt.options.buildDir
|
|
|
|
Object.keys(pathsBefore).forEach((key) => {
|
|
|
|
const paths = listPaths(nuxt.options[`${key}Dir`], pathsBefore[key])
|
|
|
|
paths.forEach((item) => {
|
|
|
|
expect(equalOrStartsWith(nuxt.options.buildDir, item.path)).toBe(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-03-27 22:28:17 +00:00
|
|
|
}
|