forked from nuxt/nuxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
40 lines (34 loc) · 1.27 KB
/
build.js
File metadata and controls
40 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { loadFixture, Nuxt, Builder, BundleBuilder, 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, BundleBuilder).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)
})
})
})
}