Skip to content

Commit

Permalink
fix: correct test files status in json reporter (fix #2417) (#2419)
Browse files Browse the repository at this point in the history
* fix: correct test files status in json reporter (fix #2417)

* fix: apply a non-breaking fix
  • Loading branch information
brzezinskimarcin committed Dec 5, 2022
1 parent b8ee821 commit ce93195
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/vitest/src/node/reporters/json.ts
Expand Up @@ -124,12 +124,10 @@ export class JsonReporter implements Reporter {
assertionResults,
startTime,
endTime,
status: tests.every(t =>
t.result?.state === 'pass'
|| t.result?.state === 'skip'
|| t.result?.state === 'todo')
? 'passed'
: 'failed',
status: tests.some(t =>
t.result?.state === 'fail')
? 'failed'
: 'passed',
message: file.result?.error?.message ?? '',
name: file.filepath,
})
Expand Down
9 changes: 9 additions & 0 deletions test/reporters/fixtures/all-passing-or-skipped.test.ts
@@ -0,0 +1,9 @@
import { expect, test } from 'vitest'

test('2 + 3 = 5', () => {
expect(2 + 3).toBe(5)
})

test.skip('3 + 3 = 6', () => {
expect(3 + 3).toBe(6)
})
9 changes: 9 additions & 0 deletions test/reporters/fixtures/all-skipped.test.ts
@@ -0,0 +1,9 @@
import { expect, test } from 'vitest'

test.todo('2 + 3 = 5', () => {
expect(2 + 3).toBe(5)
})

test.skip('3 + 3 = 6', () => {
expect(3 + 3).toBe(6)
})
9 changes: 9 additions & 0 deletions test/reporters/fixtures/some-failing.test.ts
@@ -0,0 +1,9 @@
import { expect, test } from 'vitest'

test('2 + 3 = 5', () => {
expect(2 + 3).toBe(5)
})

test('3 + 3 = 7', () => {
expect(3 + 3).toBe(7)
})
21 changes: 21 additions & 0 deletions test/reporters/tests/json.test.ts
Expand Up @@ -27,4 +27,25 @@ describe('json reporter', async () => {
delete result.duration
expect(result).toMatchSnapshot()
}, 40000)

it.skipIf(skip).each([
['passed', 'all-passing-or-skipped'],
['passed', 'all-skipped'],
['failed', 'some-failing'],
])('resolves to "%s" status for test file "%s"', async (expected, file) => {
const { stdout } = await execa('npx', ['vitest', 'run', file, '--reporter=json'], {
cwd: root,
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
stdio: 'pipe',
}).catch(e => e)

const data = JSON.parse(stdout)

expect(data.testResults).toHaveLength(1)
expect(data.testResults[0].status).toBe(expected)
}, 40000)
})

0 comments on commit ce93195

Please sign in to comment.