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

feat: add option for ignoring unhandled errors #1678

Merged
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
7 changes: 7 additions & 0 deletions docs/config/index.md
Expand Up @@ -538,6 +538,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
Expand Up @@ -71,6 +71,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.shuffle` to run tests in random order) |
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/defaults.ts
Expand Up @@ -83,6 +83,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
Expand Up @@ -34,6 +34,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
Expand Up @@ -48,7 +48,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
Expand Up @@ -413,6 +413,11 @@ export interface InlineConfig {
* Will be merged with the default aliases inside `resolve.alias`.
*/
alias?: AliasOptions

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

export interface UserConfig extends InlineConfig {
Expand Down