Skip to content

Commit ce93195

Browse files
authoredDec 5, 2022
fix: correct test files status in json reporter (fix #2417) (#2419)
* fix: correct test files status in json reporter (fix #2417) * fix: apply a non-breaking fix
1 parent b8ee821 commit ce93195

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed
 

‎packages/vitest/src/node/reporters/json.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,10 @@ export class JsonReporter implements Reporter {
124124
assertionResults,
125125
startTime,
126126
endTime,
127-
status: tests.every(t =>
128-
t.result?.state === 'pass'
129-
|| t.result?.state === 'skip'
130-
|| t.result?.state === 'todo')
131-
? 'passed'
132-
: 'failed',
127+
status: tests.some(t =>
128+
t.result?.state === 'fail')
129+
? 'failed'
130+
: 'passed',
133131
message: file.result?.error?.message ?? '',
134132
name: file.filepath,
135133
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expect, test } from 'vitest'
2+
3+
test('2 + 3 = 5', () => {
4+
expect(2 + 3).toBe(5)
5+
})
6+
7+
test.skip('3 + 3 = 6', () => {
8+
expect(3 + 3).toBe(6)
9+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expect, test } from 'vitest'
2+
3+
test.todo('2 + 3 = 5', () => {
4+
expect(2 + 3).toBe(5)
5+
})
6+
7+
test.skip('3 + 3 = 6', () => {
8+
expect(3 + 3).toBe(6)
9+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expect, test } from 'vitest'
2+
3+
test('2 + 3 = 5', () => {
4+
expect(2 + 3).toBe(5)
5+
})
6+
7+
test('3 + 3 = 7', () => {
8+
expect(3 + 3).toBe(7)
9+
})

‎test/reporters/tests/json.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,25 @@ describe('json reporter', async () => {
2727
delete result.duration
2828
expect(result).toMatchSnapshot()
2929
}, 40000)
30+
31+
it.skipIf(skip).each([
32+
['passed', 'all-passing-or-skipped'],
33+
['passed', 'all-skipped'],
34+
['failed', 'some-failing'],
35+
])('resolves to "%s" status for test file "%s"', async (expected, file) => {
36+
const { stdout } = await execa('npx', ['vitest', 'run', file, '--reporter=json'], {
37+
cwd: root,
38+
env: {
39+
...process.env,
40+
CI: 'true',
41+
NO_COLOR: 'true',
42+
},
43+
stdio: 'pipe',
44+
}).catch(e => e)
45+
46+
const data = JSON.parse(stdout)
47+
48+
expect(data.testResults).toHaveLength(1)
49+
expect(data.testResults[0].status).toBe(expected)
50+
}, 40000)
3051
})

0 commit comments

Comments
 (0)
Please sign in to comment.