Nuxt/test/utils/build.js
Pim 88c9bae57b feat: add tests to check for changed files (#3893)
* feat: add tests to check for changed files

Make sure that if we are building or generating only files in buildDir and generate.dir are changed. If files in another location would also be changed due to a new config option, those locations should be guarded in lib/common/options so you cant set them lower then rootDir or srcDir.

* fix running tests inBand

use simpler path comparisons

* add debug logs for ci

use process.hrtime for waitFor test

* add debug logs for ci

use process.hrtime for waitFor test

* use writeFileSync should probably help

* use forEach instead of map when not returning a value

update waitFor test to compare values with jest

* fix appeveyor

* use lower limit than delay in waitFor test

revert isAppveyor export
2018-09-18 16:26:41 +02:00

41 lines
1.2 KiB
JavaScript

import { loadFixture, Nuxt, Builder, listPaths, equalOrStartsWith } from './index'
export const buildFixture = function (fixture, callback, hooks = []) {
const pathsBefore = {}
let nuxt
test(`Build ${fixture}`, async () => {
const config = await loadFixture(fixture)
nuxt = new Nuxt(config)
pathsBefore.root = listPaths(nuxt.options.rootDir)
if (nuxt.options.rootDir !== nuxt.options.srcDir) {
pathsBefore.src = listPaths(nuxt.options.srcDir)
}
const buildDone = jest.fn()
hooks.forEach(([hook, fn]) => nuxt.hook(hook, fn))
nuxt.hook('build:done', buildDone)
const builder = await new Builder(nuxt).build()
// 2: BUILD_DONE
expect(builder._buildStatus).toBe(2)
expect(buildDone).toHaveBeenCalledTimes(1)
if (typeof callback === 'function') {
callback(builder)
}
}, 120000)
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)
})
})
})
}