From 86402b1f431f47415d2907a0c240fcdf4507a877 Mon Sep 17 00:00:00 2001 From: lihaozheng001 Date: Tue, 9 Jul 2024 18:17:15 +0800 Subject: [PATCH 1/6] fix(vitest): update json reporter value --- packages/vitest/src/node/reporters/json.ts | 15 ++++-- .../__snapshots__/reporters.spec.ts.snap | 54 ++++++++++++------- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/packages/vitest/src/node/reporters/json.ts b/packages/vitest/src/node/reporters/json.ts index ac1a2c984ba3..1fdc2051f783 100644 --- a/packages/vitest/src/node/reporters/json.ts +++ b/packages/vitest/src/node/reporters/json.ts @@ -62,6 +62,9 @@ export interface JsonTestResults { numPendingTests: number numPendingTestSuites: number numTodoTests: number + numTodoTestSuites: number + numSkippedTests: number + numSkippedTestSuites: number numTotalTests: number numTotalTestSuites: number startTime: number @@ -96,15 +99,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 @@ -180,10 +186,13 @@ export class JsonReporter implements Reporter { const result: JsonTestResults = { numTotalTestSuites, numPassedTestSuites, + numSkippedTestSuites, + numTodoTestSuites, numFailedTestSuites, numPendingTestSuites, numTotalTests, numPassedTests, + numSkippedTests, numFailedTests, numPendingTests, numTodoTests, diff --git a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap index 088b1b17458f..ff32847274b6 100644 --- a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap +++ b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap @@ -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, + "numSkippedTests": 1, + "numTodoTestSuites": 0, "numTodoTests": 1, "numTotalTestSuites": 2, "numTotalTests": 9, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, From 929010550a81af0bed177066dd2e11463a13f96a Mon Sep 17 00:00:00 2001 From: lihaozheng001 Date: Tue, 9 Jul 2024 18:27:56 +0800 Subject: [PATCH 2/6] doc: update json reporter doc --- docs/guide/reporters.md | 13 ++-- test/config/tsconfig.vitest-temp.json | 99 +++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 test/config/tsconfig.vitest-temp.json diff --git a/docs/guide/reporters.md b/docs/guide/reporters.md index 28399a03f532..cf9372561b40 100644 --- a/docs/guide/reporters.md +++ b/docs/guide/reporters.md @@ -282,15 +282,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": [ diff --git a/test/config/tsconfig.vitest-temp.json b/test/config/tsconfig.vitest-temp.json new file mode 100644 index 000000000000..3484213c385a --- /dev/null +++ b/test/config/tsconfig.vitest-temp.json @@ -0,0 +1,99 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": [ + "DOM", + "ESNext" + ], + "module": "ESNext", + "moduleResolution": "Bundler", + "paths": { + "@vitest/ws-client": [ + "./packages/ws-client/src/index.ts" + ], + "@vitest/ui": [ + "./packages/ui/node/index.ts" + ], + "@vitest/utils": [ + "./packages/utils/src/index.ts" + ], + "@vitest/utils/*": [ + "./packages/utils/src/*" + ], + "@vitest/spy": [ + "./packages/spy/src/index.ts" + ], + "@vitest/snapshot": [ + "./packages/snapshot/src/index.ts" + ], + "@vitest/snapshot/*": [ + "./packages/snapshot/src/*" + ], + "@vitest/expect": [ + "./packages/expect/src/index.ts" + ], + "@vitest/runner": [ + "./packages/runner/src/index.ts" + ], + "@vitest/runner/*": [ + "./packages/runner/src/*" + ], + "@vitest/browser": [ + "./packages/browser/src/node/index.ts" + ], + "~/*": [ + "./packages/ui/client/*" + ], + "vitest": [ + "./packages/vitest/src/index.ts" + ], + "vitest/globals": [ + "./packages/vitest/globals.d.ts" + ], + "vitest/node": [ + "./packages/vitest/src/node/index.ts" + ], + "vitest/execute": [ + "./packages/vitest/src/public/execute.ts" + ], + "vitest/config": [ + "./packages/vitest/src/config.ts" + ], + "vitest/coverage": [ + "./packages/vitest/src/coverage.ts" + ], + "vitest/browser": [ + "./packages/vitest/src/browser.ts" + ], + "vitest/runners": [ + "./packages/vitest/src/runners.ts" + ], + "vite-node": [ + "./packages/vite-node/src/index.ts" + ], + "vite-node/client": [ + "./packages/vite-node/src/client.ts" + ], + "vite-node/server": [ + "./packages/vite-node/src/server.ts" + ], + "vite-node/utils": [ + "./packages/vite-node/src/utils.ts" + ] + }, + "strict": true, + "declaration": true, + "noEmit": true, + "esModuleInterop": true, + "skipLibCheck": true, + "types": [ + "vite/client" + ], + "emitDeclarationOnly": false, + "incremental": true, + "tsBuildInfoFile": "/Users/lihaozheng/workProject/github/vitest/packages/vitest/dist/vendor/tsconfig.tmp.tsbuildinfo" + }, + "exclude": [ + "**/dist/**" + ] +} \ No newline at end of file From 0946c67a4d1a51fd83b5decff940d8f5a75cefd3 Mon Sep 17 00:00:00 2001 From: lihaozheng001 Date: Tue, 9 Jul 2024 18:41:34 +0800 Subject: [PATCH 3/6] chore: delete temp file --- test/config/tsconfig.vitest-temp.json | 99 --------------------------- 1 file changed, 99 deletions(-) delete mode 100644 test/config/tsconfig.vitest-temp.json diff --git a/test/config/tsconfig.vitest-temp.json b/test/config/tsconfig.vitest-temp.json deleted file mode 100644 index 3484213c385a..000000000000 --- a/test/config/tsconfig.vitest-temp.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "compilerOptions": { - "target": "ESNext", - "lib": [ - "DOM", - "ESNext" - ], - "module": "ESNext", - "moduleResolution": "Bundler", - "paths": { - "@vitest/ws-client": [ - "./packages/ws-client/src/index.ts" - ], - "@vitest/ui": [ - "./packages/ui/node/index.ts" - ], - "@vitest/utils": [ - "./packages/utils/src/index.ts" - ], - "@vitest/utils/*": [ - "./packages/utils/src/*" - ], - "@vitest/spy": [ - "./packages/spy/src/index.ts" - ], - "@vitest/snapshot": [ - "./packages/snapshot/src/index.ts" - ], - "@vitest/snapshot/*": [ - "./packages/snapshot/src/*" - ], - "@vitest/expect": [ - "./packages/expect/src/index.ts" - ], - "@vitest/runner": [ - "./packages/runner/src/index.ts" - ], - "@vitest/runner/*": [ - "./packages/runner/src/*" - ], - "@vitest/browser": [ - "./packages/browser/src/node/index.ts" - ], - "~/*": [ - "./packages/ui/client/*" - ], - "vitest": [ - "./packages/vitest/src/index.ts" - ], - "vitest/globals": [ - "./packages/vitest/globals.d.ts" - ], - "vitest/node": [ - "./packages/vitest/src/node/index.ts" - ], - "vitest/execute": [ - "./packages/vitest/src/public/execute.ts" - ], - "vitest/config": [ - "./packages/vitest/src/config.ts" - ], - "vitest/coverage": [ - "./packages/vitest/src/coverage.ts" - ], - "vitest/browser": [ - "./packages/vitest/src/browser.ts" - ], - "vitest/runners": [ - "./packages/vitest/src/runners.ts" - ], - "vite-node": [ - "./packages/vite-node/src/index.ts" - ], - "vite-node/client": [ - "./packages/vite-node/src/client.ts" - ], - "vite-node/server": [ - "./packages/vite-node/src/server.ts" - ], - "vite-node/utils": [ - "./packages/vite-node/src/utils.ts" - ] - }, - "strict": true, - "declaration": true, - "noEmit": true, - "esModuleInterop": true, - "skipLibCheck": true, - "types": [ - "vite/client" - ], - "emitDeclarationOnly": false, - "incremental": true, - "tsBuildInfoFile": "/Users/lihaozheng/workProject/github/vitest/packages/vitest/dist/vendor/tsconfig.tmp.tsbuildinfo" - }, - "exclude": [ - "**/dist/**" - ] -} \ No newline at end of file From 9a3f9c86279fbd3f36aa1fc75964c33142456bb6 Mon Sep 17 00:00:00 2001 From: lihaozheng001 Date: Tue, 9 Jul 2024 19:59:12 +0800 Subject: [PATCH 4/6] fix: update test snapshot --- test/reporters/tests/merge-reports.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/reporters/tests/merge-reports.test.ts b/test/reporters/tests/merge-reports.test.ts index 70de1b63fba0..d8d5b9e3e9e4 100644 --- a/test/reporters/tests/merge-reports.test.ts +++ b/test/reporters/tests/merge-reports.test.ts @@ -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, From 29faf083436e42e668fb0e79898d9c98108b0b2a Mon Sep 17 00:00:00 2001 From: lihaozheng001 Date: Thu, 1 Aug 2024 12:14:58 +0800 Subject: [PATCH 5/6] fix: cr --- docs/guide/reporters.md | 13 +++++-------- packages/vitest/src/node/reporters/json.ts | 17 +++++------------ .../tests/__snapshots__/reporters.spec.ts.snap | 5 +---- test/reporters/tests/merge-reports.test.ts | 3 --- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/docs/guide/reporters.md b/docs/guide/reporters.md index a3afb2a53644..e18e974d4116 100644 --- a/docs/guide/reporters.md +++ b/docs/guide/reporters.md @@ -285,17 +285,14 @@ Example of a JSON report: ```json { "numTotalTestSuites": 4, - "numTodoTestSuites": 1, + "numPassedTestSuites": 2, "numFailedTestSuites": 1, - "numPassedTestSuites": 1, - "numSkippedTestSuites": 1, - "numPendingTestSuites": 0, + "numPendingTestSuites": 1, "numTotalTests": 4, - "numTodoTests": 1, - "numFailedTests": 1, "numPassedTests": 1, - "numSkippedTests": 1, - "numPendingTests": 0, + "numFailedTests": 1, + "numPendingTests": 1, + "numTodoTests": 1, "startTime": 1697737019307, "success": false, "testResults": [ diff --git a/packages/vitest/src/node/reporters/json.ts b/packages/vitest/src/node/reporters/json.ts index 2bc41b0b3ffa..b9b335f7ebe5 100644 --- a/packages/vitest/src/node/reporters/json.ts +++ b/packages/vitest/src/node/reporters/json.ts @@ -57,9 +57,6 @@ export interface JsonTestResults { numPendingTests: number numPendingTestSuites: number numTodoTests: number - numTodoTestSuites: number - numSkippedTests: number - numSkippedTestSuites: number numTotalTests: number numTotalTestSuites: number startTime: number @@ -94,20 +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?.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', + 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 = 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', + 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 = [] @@ -181,13 +177,10 @@ export class JsonReporter implements Reporter { const result: JsonTestResults = { numTotalTestSuites, numPassedTestSuites, - numSkippedTestSuites, - numTodoTestSuites, numFailedTestSuites, numPendingTestSuites, numTotalTests, numPassedTests, - numSkippedTests, numFailedTests, numPendingTests, numTodoTests, diff --git a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap index ff32847274b6..f5396ee01ac6 100644 --- a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap +++ b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap @@ -69,10 +69,7 @@ exports[`json reporter (no outputFile entry) 1`] = ` "numPassedTestSuites": 1, "numPassedTests": 6, "numPendingTestSuites": 0, - "numPendingTests": 0, - "numSkippedTestSuites": 0, - "numSkippedTests": 1, - "numTodoTestSuites": 0, + "numPendingTests": 1, "numTodoTests": 1, "numTotalTestSuites": 2, "numTotalTests": 9, diff --git a/test/reporters/tests/merge-reports.test.ts b/test/reporters/tests/merge-reports.test.ts index d8d5b9e3e9e4..b66ccd7c7c9d 100644 --- a/test/reporters/tests/merge-reports.test.ts +++ b/test/reporters/tests/merge-reports.test.ts @@ -135,9 +135,6 @@ test('merge reports', async () => { "numPassedTests": 3, "numPendingTestSuites": 0, "numPendingTests": 0, - "numSkippedTestSuites": 0, - "numSkippedTests": 0, - "numTodoTestSuites": 0, "numTodoTests": 0, "numTotalTestSuites": 3, "numTotalTests": 5, From 66810b88a335a2ec620be4ae92faf3298c64f8c0 Mon Sep 17 00:00:00 2001 From: lihaozheng001 Date: Thu, 1 Aug 2024 14:43:41 +0800 Subject: [PATCH 6/6] fix: test --- .../__snapshots__/reporters.spec.ts.snap | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap index f5396ee01ac6..32d3fc3f7ab1 100644 --- a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap +++ b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap @@ -213,10 +213,7 @@ exports[`json reporter 1`] = ` "numPassedTestSuites": 1, "numPassedTests": 6, "numPendingTestSuites": 0, - "numPendingTests": 0, - "numSkippedTestSuites": 0, - "numSkippedTests": 1, - "numTodoTestSuites": 0, + "numPendingTests": 1, "numTodoTests": 1, "numTotalTestSuites": 2, "numTotalTests": 9, @@ -365,10 +362,7 @@ exports[`json reporter with outputFile 2`] = ` "numPassedTestSuites": 1, "numPassedTests": 6, "numPendingTestSuites": 0, - "numPendingTests": 0, - "numSkippedTestSuites": 0, - "numSkippedTests": 1, - "numTodoTestSuites": 0, + "numPendingTests": 1, "numTodoTests": 1, "numTotalTestSuites": 2, "numTotalTests": 9, @@ -517,10 +511,7 @@ exports[`json reporter with outputFile in non-existing directory 2`] = ` "numPassedTestSuites": 1, "numPassedTests": 6, "numPendingTestSuites": 0, - "numPendingTests": 0, - "numSkippedTestSuites": 0, - "numSkippedTests": 1, - "numTodoTestSuites": 0, + "numPendingTests": 1, "numTodoTests": 1, "numTotalTestSuites": 2, "numTotalTests": 9, @@ -669,10 +660,7 @@ exports[`json reporter with outputFile object 2`] = ` "numPassedTestSuites": 1, "numPassedTests": 6, "numPendingTestSuites": 0, - "numPendingTests": 0, - "numSkippedTestSuites": 0, - "numSkippedTests": 1, - "numTodoTestSuites": 0, + "numPendingTests": 1, "numTodoTests": 1, "numTotalTestSuites": 2, "numTotalTests": 9, @@ -821,10 +809,7 @@ exports[`json reporter with outputFile object in non-existing directory 2`] = ` "numPassedTestSuites": 1, "numPassedTests": 6, "numPendingTestSuites": 0, - "numPendingTests": 0, - "numSkippedTestSuites": 0, - "numSkippedTests": 1, - "numTodoTestSuites": 0, + "numPendingTests": 1, "numTodoTests": 1, "numTotalTestSuites": 2, "numTotalTests": 9,