Skip to content

Commit

Permalink
fix(generator): throw an error when Builder is missing (#9663)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Aug 12, 2021
1 parent 1b66e9c commit b565c38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/generator/src/generator.js
Expand Up @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions packages/generator/test/generator.init.test.js
Expand Up @@ -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 = {
Expand Down

0 comments on commit b565c38

Please sign in to comment.