Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vitest): update json reporter output #6064

Merged
merged 10 commits into from
Aug 1, 2024
13 changes: 8 additions & 5 deletions docs/guide/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,18 @@ Example of a JSON report:

```json
{
"numTotalTestSuites": 1,
"numPassedTestSuites": 0,
"numTotalTestSuites": 4,
"numTodoTestSuites": 1,
"numFailedTestSuites": 1,
"numPassedTestSuites": 1,
"numSkippedTestSuites": 1,
"numPendingTestSuites": 0,
"numTotalTests": 1,
"numPassedTests": 0,
"numTotalTests": 4,
"numTodoTests": 1,
"numFailedTests": 1,
"numPassedTests": 1,
"numSkippedTests": 1,
"numPendingTests": 0,
"numTodoTests": 0,
"startTime": 1697737019307,
"success": false,
"testResults": [
Expand Down
15 changes: 12 additions & 3 deletions packages/vitest/src/node/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export interface JsonTestResults {
numPendingTests: number
numPendingTestSuites: number
numTodoTests: number
numTodoTestSuites: number
numSkippedTests: number
numSkippedTestSuites: number
numTotalTests: number
numTotalTestSuites: number
startTime: number
Expand Down Expand Up @@ -91,15 +94,18 @@ 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 numPassedTestSuites = suites.filter(s => s.result?.state === 'pass').length
const numSkippedTestSuites = suites.filter(s => s.mode === 'skip' || s.result?.state === 'skip').length
const numTodoTestSuites = suites.filter(s => s.mode === 'todo').length
const numPendingTestSuites = suites.filter(
s => s.result?.state === 'run',
).length
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 numSkippedTests = tests.filter(t => t.mode === 'skip' || t.result?.state === 'skip').length
const numPendingTests = tests.filter(
t => t.result?.state === 'run',
).length
Expand Down Expand Up @@ -175,10 +181,13 @@ export class JsonReporter implements Reporter {
const result: JsonTestResults = {
numTotalTestSuites,
numPassedTestSuites,
numSkippedTestSuites,
numTodoTestSuites,
numFailedTestSuites,
numPendingTestSuites,
numTotalTests,
numPassedTests,
numSkippedTests,
numFailedTests,
numPendingTests,
numTodoTests,
Expand Down
54 changes: 36 additions & 18 deletions test/reporters/tests/__snapshots__/reporters.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ 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,
"numSkippedTestSuites": 0,
Emiyaaaaa marked this conversation as resolved.
Show resolved Hide resolved
"numSkippedTests": 1,
"numTodoTestSuites": 0,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -208,12 +211,15 @@ 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,
"numSkippedTestSuites": 0,
"numSkippedTests": 1,
"numTodoTestSuites": 0,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -357,12 +363,15 @@ 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,
"numSkippedTestSuites": 0,
"numSkippedTests": 1,
"numTodoTestSuites": 0,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -506,12 +515,15 @@ 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,
"numSkippedTestSuites": 0,
"numSkippedTests": 1,
"numTodoTestSuites": 0,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -655,12 +667,15 @@ 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,
"numSkippedTestSuites": 0,
"numSkippedTests": 1,
"numTodoTestSuites": 0,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down Expand Up @@ -804,12 +819,15 @@ 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,
"numSkippedTestSuites": 0,
"numSkippedTests": 1,
"numTodoTestSuites": 0,
"numTodoTests": 1,
"numTotalTestSuites": 2,
"numTotalTests": 9,
Expand Down
7 changes: 5 additions & 2 deletions test/reporters/tests/merge-reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,15 @@ test('merge reports', async () => {

expect(json).toMatchInlineSnapshot(`
{
"numFailedTestSuites": 0,
"numFailedTestSuites": 2,
"numFailedTests": 2,
"numPassedTestSuites": 3,
"numPassedTestSuites": 1,
"numPassedTests": 3,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numSkippedTestSuites": 0,
"numSkippedTests": 0,
"numTodoTestSuites": 0,
"numTodoTests": 0,
"numTotalTestSuites": 3,
"numTotalTests": 5,
Expand Down
Loading