feat: check modern build file in modern mode (#4467)

[skip release]
This commit is contained in:
Clark Du 2018-12-04 12:11:18 +00:00 committed by Pooya Parsa
parent e2ab1b4896
commit 14fe6792ae
2 changed files with 28 additions and 4 deletions

View File

@ -103,10 +103,16 @@ export default class VueRenderer {
await this.loadResources(fs) await this.loadResources(fs)
// Verify // Verify
if (!this.isReady && this.context.options._start) { if (this.context.options._start) {
throw new Error( if (!this.isReady) {
'No build files found. Use either `nuxt build` or `builder.build()` or start nuxt in development mode.' throw new Error(
) 'No build files found. Use either `nuxt build` or `builder.build()` or start nuxt in development mode.'
)
} else if (this.context.options.modern && !this.context.resources.modernManifest) {
throw new Error(
'No modern build files found. Use either `nuxt build --modern` or `modern` option to build modern files.'
)
}
} }
} else { } else {
// Development: Listen on build:resources hook // Development: Listen on build:resources hook

View File

@ -1,9 +1,15 @@
import path from 'path'
import consola from 'consola' import consola from 'consola'
import { Nuxt } from '../utils' import { Nuxt } from '../utils'
const NO_BUILD_MSG = 'No build files found. Use either `nuxt build` or `builder.build()` or start nuxt in development mode.' const NO_BUILD_MSG = 'No build files found. Use either `nuxt build` or `builder.build()` or start nuxt in development mode.'
const NO_MODERN_BUILD_MSG = 'No modern build files found. Use either `nuxt build --modern` or `modern` option to build modern files.'
describe('renderer', () => { describe('renderer', () => {
afterEach(() => {
consola.fatal.mockClear()
})
test('detect no-build (Universal)', async () => { test('detect no-build (Universal)', async () => {
const nuxt = new Nuxt({ const nuxt = new Nuxt({
_start: true, _start: true,
@ -27,4 +33,16 @@ describe('renderer', () => {
await expect(nuxt.renderer.renderer.isReady).toBe(false) await expect(nuxt.renderer.renderer.isReady).toBe(false)
expect(consola.fatal).toHaveBeenCalledWith(new Error(NO_BUILD_MSG)) expect(consola.fatal).toHaveBeenCalledWith(new Error(NO_BUILD_MSG))
}) })
test('detect no-modern-build', async () => {
const nuxt = new Nuxt({
_start: true,
mode: 'universal',
modern: 'client',
dev: false,
buildDir: path.resolve(__dirname, '..', 'fixtures', 'empty', '.nuxt')
})
await nuxt.ready()
await expect(nuxt.renderer.renderer.isReady).toBe(true)
expect(consola.fatal).toHaveBeenCalledWith(new Error(NO_MODERN_BUILD_MSG))
})
}) })