fix(generator): throw an error when Builder is missing (#9663)

This commit is contained in:
mrazauskas 2021-08-12 11:49:25 +03:00 committed by GitHub
parent 1b66e9c688
commit b565c38f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -84,6 +84,12 @@ export default class Generator {
await this.nuxt.callHook('export:before', this)
if (build) {
if (!this.builder) {
throw new Error(
`Could not generate. Make sure a Builder instance is passed to the constructor of Generator class or `getGenerator` function \
or disable the build step: \`generate({ build: false })\``)
}
// Add flag to set process.static
this.builder.forGenerate()

View File

@ -98,6 +98,13 @@ describe('generator: initialize', () => {
expect(generator.initDist).not.toBeCalled()
})
test('should throw error when build is not disabled, but Builder instance is omitted', async () => {
const nuxt = createNuxt()
const generator = new Generator(nuxt)
await expect(generator.initiate()).rejects.toThrow('Could not generate')
})
test('should init routes with generate.routes and routes.json', async () => {
const nuxt = createNuxt()
nuxt.options = {