-
-
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(vitest): fix tap reporter to handle custom error (#4897)
- Loading branch information
Showing
4 changed files
with
62 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { test } from 'vitest'; | ||
|
||
test('no name object', () => { | ||
throw { noName: 'hi' }; | ||
}); | ||
|
||
test('string', () => { | ||
throw "hi"; | ||
}); | ||
|
||
test('number', () => { | ||
throw 1234; | ||
}); | ||
|
||
test('number name object', () => { | ||
throw { name: 1234 }; | ||
}); |
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 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({}) |
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,37 @@ | ||
import { expect, test } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
test('handle custom error without name', async () => { | ||
let { stdout, stderr } = await runVitest({ reporters: 'tap-flat', root: './fixtures/custom-error' }) | ||
stdout = stdout.replaceAll(/time=(\S*)/g, 'time=[...]') // strip non-deterministic output | ||
expect(stdout).toMatchInlineSnapshot(` | ||
"TAP version 13 | ||
1..4 | ||
not ok 1 - basic.test.ts > no name object # time=[...] | ||
--- | ||
error: | ||
name: "Unknown Error" | ||
message: "undefined" | ||
... | ||
not ok 2 - basic.test.ts > string # time=[...] | ||
--- | ||
error: | ||
name: "Unknown Error" | ||
message: "hi" | ||
... | ||
not ok 3 - basic.test.ts > number # time=[...] | ||
--- | ||
error: | ||
name: "Unknown Error" | ||
message: "1234" | ||
... | ||
not ok 4 - basic.test.ts > number name object # time=[...] | ||
--- | ||
error: | ||
name: "1234" | ||
message: "undefined" | ||
... | ||
" | ||
`) | ||
expect(stderr).toBe('') | ||
}) |