mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
bed0714fad
* feat: modern build * refactor: use single module import for lodash * refactor: add credit comment for modern plugin * feat: ssr modern build * fix: not null check for request * fix: not null check for request.headers * feat: add modern argument on build command * refactor: simpilfy filenames for modern * refactor: use packages/webpack src instead of dist in test * test: add feature test for modern build
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
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)
|
|
})
|
|
})
|
|
})
|
|
}
|