Skip to content

Commit

Permalink
fix(vitest): update json reporter output (#6064)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiyaaaaa authored Aug 1, 2024
1 parent af2b813 commit c997937
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
14 changes: 7 additions & 7 deletions docs/guide/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ Example of a JSON report:

```json
{
"numTotalTestSuites": 1,
"numPassedTestSuites": 0,
"numTotalTestSuites": 4,
"numPassedTestSuites": 2,
"numFailedTestSuites": 1,
"numPendingTestSuites": 0,
"numTotalTests": 1,
"numPassedTests": 0,
"numPendingTestSuites": 1,
"numTotalTests": 4,
"numPassedTests": 1,
"numFailedTests": 1,
"numPendingTests": 0,
"numTodoTests": 0,
"numPendingTests": 1,
"numTodoTests": 1,
"startTime": 1697737019307,
"success": false,
"testResults": [
Expand Down
12 changes: 7 additions & 5 deletions packages/vitest/src/node/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,19 @@ export class JsonReporter implements Reporter {
const numTotalTestSuites = suites.length
const tests = getTests(files)
const numTotalTests = tests.length
const numFailedTestSuites = suites.filter(s => s.result?.errors).length
const numPassedTestSuites = numTotalTestSuites - numFailedTestSuites

const numFailedTestSuites = suites.filter(s => s.result?.state === 'fail').length
const numPendingTestSuites = suites.filter(
s => s.result?.state === 'run',
s => s.result?.state === 'run' || s.mode === 'todo',
).length
const numPassedTestSuites = numTotalTestSuites - numFailedTestSuites - numPendingTestSuites

const numFailedTests = tests.filter(
t => t.result?.state === 'fail',
).length
const numPassedTests = numTotalTests - numFailedTests
const numPassedTests = tests.filter(t => t.result?.state === 'pass').length
const numPendingTests = tests.filter(
t => t.result?.state === 'run',
t => t.result?.state === 'run' || t.mode === 'skip' || t.result?.state === 'skip',
).length
const numTodoTests = tests.filter(t => t.mode === 'todo').length
const testResults: Array<JsonTestResult> = []
Expand Down
48 changes: 24 additions & 24 deletions test/reporters/tests/__snapshots__/reporters.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ exports[`JUnit reporter with outputFile object in non-existing directory 2`] = `
exports[`json reporter (no outputFile entry) 1`] = `
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 1,
"numFailedTests": 1,
"numPassedTestSuites": 2,
"numPassedTests": 8,
"numPassedTestSuites": 1,
"numPassedTests": 6,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numPendingTests": 1,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -208,12 +208,12 @@ exports[`json reporter (no outputFile entry) 1`] = `
exports[`json reporter 1`] = `
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 1,
"numFailedTests": 1,
"numPassedTestSuites": 2,
"numPassedTests": 8,
"numPassedTestSuites": 1,
"numPassedTests": 6,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numPendingTests": 1,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -357,12 +357,12 @@ exports[`json reporter with outputFile 1`] = `
exports[`json reporter with outputFile 2`] = `
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 1,
"numFailedTests": 1,
"numPassedTestSuites": 2,
"numPassedTests": 8,
"numPassedTestSuites": 1,
"numPassedTests": 6,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numPendingTests": 1,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -506,12 +506,12 @@ exports[`json reporter with outputFile in non-existing directory 1`] = `
exports[`json reporter with outputFile in non-existing directory 2`] = `
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 1,
"numFailedTests": 1,
"numPassedTestSuites": 2,
"numPassedTests": 8,
"numPassedTestSuites": 1,
"numPassedTests": 6,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numPendingTests": 1,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -655,12 +655,12 @@ exports[`json reporter with outputFile object 1`] = `
exports[`json reporter with outputFile object 2`] = `
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 1,
"numFailedTests": 1,
"numPassedTestSuites": 2,
"numPassedTests": 8,
"numPassedTestSuites": 1,
"numPassedTests": 6,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numPendingTests": 1,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -804,12 +804,12 @@ exports[`json reporter with outputFile object in non-existing directory 1`] = `
exports[`json reporter with outputFile object in non-existing directory 2`] = `
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 1,
"numFailedTests": 1,
"numPassedTestSuites": 2,
"numPassedTests": 8,
"numPassedTestSuites": 1,
"numPassedTests": 6,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numPendingTests": 1,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down
4 changes: 2 additions & 2 deletions test/reporters/tests/merge-reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ test('merge reports', async () => {

expect(json).toMatchInlineSnapshot(`
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 2,
"numFailedTests": 2,
"numPassedTestSuites": 3,
"numPassedTestSuites": 1,
"numPassedTests": 3,
"numPendingTestSuites": 0,
"numPendingTests": 0,
Expand Down

0 comments on commit c997937

Please sign in to comment.