mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
This commit is contained in:
parent
1336ac9c56
commit
c6565c97c6
@ -33,6 +33,11 @@ export default {
|
||||
options.modern = 'client'
|
||||
}
|
||||
}
|
||||
},
|
||||
'fail-on-error': {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Exit with non-zero status code if there are errors when generating pages'
|
||||
}
|
||||
},
|
||||
async run(cmd) {
|
||||
@ -66,9 +71,13 @@ export default {
|
||||
|
||||
const generator = await cmd.getGenerator(nuxt)
|
||||
|
||||
await generator.generate({
|
||||
const { errors } = await generator.generate({
|
||||
init: true,
|
||||
build: cmd.argv.build
|
||||
})
|
||||
|
||||
if (cmd.argv['fail-on-error'] && errors.length > 0) {
|
||||
throw new Error('Error generating pages, exiting with non-zero code')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ describe('generate', () => {
|
||||
|
||||
mockGetGenerator(async () => {
|
||||
await buildDone()
|
||||
return { errors: [] }
|
||||
})
|
||||
|
||||
const cmd = NuxtCommand.from(generate, ['generate', '.'])
|
||||
@ -134,4 +135,28 @@ describe('generate', () => {
|
||||
|
||||
expect(createLock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('throw an error when fail-on-error enabled and page errors', async () => {
|
||||
mockGetNuxt()
|
||||
mockGetGenerator(() => ({ errors: [{ type: 'dummy' }] }))
|
||||
|
||||
const cmd = NuxtCommand.from(generate, ['generate', '.', '--fail-on-error'])
|
||||
await expect(cmd.run()).rejects
|
||||
})
|
||||
|
||||
test('do not throw an error when fail-on-error disabled and page errors', async () => {
|
||||
mockGetNuxt()
|
||||
mockGetGenerator(() => ({ errors: [{ type: 'dummy' }] }))
|
||||
|
||||
const cmd = NuxtCommand.from(generate, ['generate', '.'])
|
||||
await cmd.run()
|
||||
})
|
||||
|
||||
test('do not throw an error when fail-on-error enabled and no page errors', async () => {
|
||||
mockGetNuxt()
|
||||
mockGetGenerator()
|
||||
|
||||
const cmd = NuxtCommand.from(generate, ['generate', '.', '--fail-on-error'])
|
||||
await cmd.run()
|
||||
})
|
||||
})
|
||||
|
@ -39,6 +39,8 @@ export const mockGetGenerator = (ret) => {
|
||||
const generate = jest.fn()
|
||||
if (ret) {
|
||||
generate.mockImplementationOnce(ret)
|
||||
} else {
|
||||
generate.mockImplementationOnce(() => ({ errors: [] }))
|
||||
}
|
||||
|
||||
Command.prototype.getGenerator = jest.fn().mockImplementationOnce(() => ({ generate }))
|
||||
|
Loading…
Reference in New Issue
Block a user