-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: capture
unhandledRejection
even when base reporter is not used (…
- Loading branch information
1 parent
0bf0ab0
commit 8878b04
Showing
5 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/config/fixtures/unhandled-rejections/setup-unhandled-rejections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function setup() { | ||
void new Promise((_, reject) => reject(new Error('intentional unhandled rejection'))) | ||
} |
4 changes: 4 additions & 0 deletions
4
test/config/fixtures/unhandled-rejections/tests/example.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { test } from "vitest" | ||
|
||
test("Some test", () => {}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
import { runVitest } from '../../test-utils' | ||
|
||
test('unhandled rejections of main thread are reported even when no reporter is used', async () => { | ||
const { stderr, exitCode } = await runVitest({ | ||
root: 'fixtures/unhandled-rejections', | ||
globalSetup: ['setup-unhandled-rejections.ts'], | ||
reporters: [{ onInit: () => {} }], | ||
}) | ||
|
||
expect(exitCode).toBe(1) | ||
expect(stderr).toContain('Unhandled Rejection') | ||
expect(stderr).toContain('Error: intentional unhandled rejection') | ||
expect(stderr).toContain('setup-unhandled-rejections.ts:2:42') | ||
}) |