Skip to content

Commit

Permalink
test: fix breaking assertions after using kernel.errorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 5, 2024
1 parent 4c61de9 commit fd8944c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion commands/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { stubsRoot } from '../stubs/main.js'
import type { CommandOptions } from '../types/ace.js'
import { args, BaseCommand, flags } from '../modules/ace/main.js'
import { RuntimeException } from '@poppinss/utils'

/**
* The configure command is used to configure packages after installation
Expand Down Expand Up @@ -165,6 +166,12 @@ export default class Configure extends BaseCommand {
/**
* Run instructions
*/
await packageExports.configure(this)
try {
await packageExports.configure(this)
} catch (error) {
throw new RuntimeException(`Unable to configure package "${this.name}"`, {
cause: error,
})
}
}
}
12 changes: 12 additions & 0 deletions tests/ace/base_command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ test.group('Base command', () => {

const kernel = createAceKernel(app)
kernel.ui.switchMode('raw')
kernel.errorHandler.render = async function (error: Error) {
command.logger.fatal(error)
}

const command = await kernel.create(MakeController, [])
await command.exec()
Expand All @@ -137,6 +140,9 @@ test.group('Base command', () => {

const kernel = createAceKernel(app)
kernel.ui.switchMode('raw')
kernel.errorHandler.render = async function (error: Error) {
command.logger.fatal(error)
}

const command = await kernel.create(MakeController, [])
await command.exec()
Expand All @@ -162,6 +168,9 @@ test.group('Base command', () => {

const kernel = createAceKernel(app)
kernel.ui.switchMode('raw')
kernel.errorHandler.render = async function (error: Error) {
command.logger.fatal(error)
}

const command = await kernel.create(MakeController, [])
await command.exec()
Expand Down Expand Up @@ -219,6 +228,9 @@ test.group('Base command', () => {

const kernel = createAceKernel(app)
kernel.ui.switchMode('raw')
kernel.errorHandler.render = async function (error: Error) {
command.logger.fatal(error)
}

const command = await kernel.create(MakeController, [])
await command.exec()
Expand Down
5 changes: 4 additions & 1 deletion tests/commands/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,14 @@ test.group('Install', (group) => {

const command = await ace.create(Add, [new URL('node_modules/foo', fs.baseUrl).href])
command.verbose = VERBOSE
ace.errorHandler.render = async function (error: Error) {
command.logger.fatal(error)
}

await command.exec()

command.assertExitCode(1)
command.assertLogMatches(/Invalid configure/)
command.assertLogMatches(/Unable to configure/)
})

test('configure edge', async ({ assert, fs }) => {
Expand Down

0 comments on commit fd8944c

Please sign in to comment.