Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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