Skip to content

Commit

Permalink
fix: unhandled error handler (#876)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
sapphi-red and antfu committed Mar 1, 2022
1 parent 9845517 commit 1fcb4ed
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@vitest/test-solid",
"private": true,
"scripts": {
"test": "vitest",
"coverage": "vitest --coverage"
"test": "if-node-version \">14\" vitest",
"coverage": "if-node-version \">14\" vitest --coverage"
},
"dependencies": {
"solid-js": "^1.3.8"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"eslint": "^8.10.0",
"esno": "^0.14.1",
"fast-glob": "^3.2.11",
"if-node-version": "^1.1.1",
"magic-string": "^0.25.7",
"node-fetch": "^3.2.0",
"npm-run-all": "^4.1.5",
Expand Down
14 changes: 12 additions & 2 deletions packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import cac from 'cac'
import c from 'picocolors'
import { version } from '../../package.json'
import type { CliOptions } from './cli-api'
import { startVitest } from './cli-api'
import { divider } from './reporters/renderers/utils'

const cli = cac('vitest')

Expand Down Expand Up @@ -66,6 +68,14 @@ async function run(cliFilters: string[], options: CliOptions) {
}

async function start(cliFilters: string[], options: CliOptions) {
if (await startVitest(cliFilters, options) === false)
process.exit()
try {
if (await startVitest(cliFilters, options) === false)
process.exit()
}
catch (e) {
process.exitCode = 1
console.error(`\n${c.red(divider(c.bold(c.inverse(' Unhandled Error '))))}`)
console.error(e)
console.error('\n\n')
}
}
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/global-setup-fail/test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ it('should fail', async() => {
.find(i => i.includes('Error: '))
?.trim()
expect(msg).toBe('Error: error')
}, 10000)
}, 20000)

0 comments on commit 1fcb4ed

Please sign in to comment.