Skip to content

Commit

Permalink
feat: add option for ignoring unhandled errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DerYeger committed Jul 19, 2022
1 parent d553031 commit 40cc27b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,13 @@ export default defineConfig({

Allow tests and suites that are marked as only.

### dangerouslyIgnoreUnhandledErrors

- **Type**: `boolean`
- **Default**: `false`

Ignore any unhandled errors that occur.

### passWithNoTests

- **Type**: `boolean`
Expand Down
1 change: 1 addition & 0 deletions docs/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ vitest related /src/index.ts /src/hello-world.js
| `--environment <env>` | Runner environment (default: `node`) |
| `--passWithNoTests` | Pass when no tests found |
| `--allowOnly` | Allow tests and suites that are marked as `only` (default: false in CI, true otherwise) |
| `--dangerouslyIgnoreUnhandledErrors` | Ignore any unhandled errors that occur |
| `--changed [since]` | Run tests that are affected by the changed files (default: false). See [docs](#changed) |
| `--shard <shard>` | Execute tests in a specified shard |
| `--sequence` | Define in what order to run tests. Use [cac's dot notation] to specify options (for example, use `--sequence.suffle` to run tests in random order) |
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const config = {
coverage: coverageConfigDefaults,
fakeTimers: fakeTimersDefaults,
maxConcurrency: 5,
dangerouslyIgnoreUnhandledErrors: false,
}

export const configDefaults: Required<Pick<UserConfig, keyof typeof config>> = Object.freeze(config)
1 change: 1 addition & 0 deletions packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cli
.option('--environment <env>', 'runner environment (default: node)')
.option('--passWithNoTests', 'pass when no tests found')
.option('--allowOnly', 'Allow tests and suites that are marked as only (default: !process.env.CI)')
.option('--dangerouslyIgnoreUnhandledErrors', 'Ignore any unhandled errors that occur')
.option('--shard <shard>', 'Test suite shard to execute in a format of <index>/<count>')
.option('--changed [since]', 'Run tests that are affected by the changed files (default: false)')
.option('--sequence <options>', 'Define in what order to run tests (use --sequence.shuffle to run tests in random order)')
Expand Down
3 changes: 2 additions & 1 deletion packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export abstract class BaseReporter implements Reporter {
this.end = performance.now()
await this.reportSummary(files)
if (errors.length) {
process.exitCode = 1
if (!this.ctx.config.dangerouslyIgnoreUnhandledErrors)
process.exitCode = 1
this.ctx.logger.printUnhandledErrors(errors)
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ export interface InlineConfig {
*/
seed?: number
}

/**
* Ignore any unhandled errors that occur
*/
dangerouslyIgnoreUnhandledErrors?: boolean
}

export interface UserConfig extends InlineConfig {
Expand Down

0 comments on commit 40cc27b

Please sign in to comment.