From 756107beaecb8fa097376fa1c650a254fe955166 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Sun, 1 May 2022 17:29:31 +0300 Subject: [PATCH 1/2] fix: todo assertion status in json output --- packages/vitest/src/node/reporters/json.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/reporters/json.ts b/packages/vitest/src/node/reporters/json.ts index 30fda9ff38b1..0dacc37f63c5 100644 --- a/packages/vitest/src/node/reporters/json.ts +++ b/packages/vitest/src/node/reporters/json.ts @@ -104,7 +104,7 @@ export class JsonReporter implements Reporter { return { ancestorTitles, fullName: ancestorTitles.length > 0 ? `${ancestorTitles.join(' ')} ${t.name}` : t.name, - status: t.result != null ? StatusMap[t.result.state] : 'skipped', + status: StatusMap[t.result?.state || t.mode] || 'skipped', title: t.name, duration: t.result?.duration, failureMessages: t.result?.error?.message == null ? [] : [t.result.error.message], From 247e657ef1743d9722e914f14d4fe4abf3ea1916 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Sun, 1 May 2022 17:29:50 +0300 Subject: [PATCH 2/2] test: fix tests for reporters --- test/reporters/src/data.ts | 11 ++ .../__snapshots__/reporters.spec.ts.snap | 126 ++++++++++++++---- 2 files changed, 111 insertions(+), 26 deletions(-) diff --git a/test/reporters/src/data.ts b/test/reporters/src/data.ts index 27b7f893027c..83676111e84e 100644 --- a/test/reporters/src/data.ts +++ b/test/reporters/src/data.ts @@ -159,6 +159,17 @@ const tasks: Task[] = [ }, ], }, + { + id: '1223128da3_9', + type: 'test', + name: 'todo test', + mode: 'todo', + suite, + fails: undefined, + file, + result: undefined, + context: null as any, + }, ] file.tasks = [suite] diff --git a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap index 6083083da594..13a7d361e974 100644 --- a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap +++ b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap @@ -3,7 +3,7 @@ exports[`JUnit reporter (no outputFile entry) 1`] = ` " - + AssertionError: expected 2.23606797749979 to equal 2 @@ -28,6 +28,9 @@ AssertionError: expected 2.23606797749979 to equal 2 [33merror[39m + + + " @@ -36,7 +39,7 @@ AssertionError: expected 2.23606797749979 to equal 2 exports[`JUnit reporter 1`] = ` " - + AssertionError: expected 2.23606797749979 to equal 2 @@ -61,6 +64,9 @@ AssertionError: expected 2.23606797749979 to equal 2 [33merror[39m + + + " @@ -74,7 +80,7 @@ exports[`JUnit reporter with outputFile 1`] = ` exports[`JUnit reporter with outputFile 2`] = ` " - + AssertionError: expected 2.23606797749979 to equal 2 @@ -99,6 +105,9 @@ AssertionError: expected 2.23606797749979 to equal 2 [33merror[39m + + + " @@ -112,7 +121,7 @@ exports[`JUnit reporter with outputFile in non-existing directory 1`] = ` exports[`JUnit reporter with outputFile in non-existing directory 2`] = ` " - + AssertionError: expected 2.23606797749979 to equal 2 @@ -137,6 +146,9 @@ AssertionError: expected 2.23606797749979 to equal 2 [33merror[39m + + + " @@ -150,7 +162,7 @@ exports[`JUnit reporter with outputFile object 1`] = ` exports[`JUnit reporter with outputFile object 2`] = ` " - + AssertionError: expected 2.23606797749979 to equal 2 @@ -175,6 +187,9 @@ AssertionError: expected 2.23606797749979 to equal 2 [33merror[39m + + + " @@ -188,7 +203,7 @@ exports[`JUnit reporter with outputFile object in non-existing directory 1`] = ` exports[`JUnit reporter with outputFile object in non-existing directory 2`] = ` " - + AssertionError: expected 2.23606797749979 to equal 2 @@ -213,6 +228,9 @@ AssertionError: expected 2.23606797749979 to equal 2 [33merror[39m + + + " @@ -223,12 +241,12 @@ exports[`json reporter (no outputFile entry) 1`] = ` "numFailedTestSuites": 0, "numFailedTests": 1, "numPassedTestSuites": 3, - "numPassedTests": 7, + "numPassedTests": 8, "numPendingTestSuites": 0, "numPendingTests": 0, - "numTodoTests": 0, + "numTodoTests": 1, "numTotalTestSuites": 3, - "numTotalTests": 8, + "numTotalTests": 9, "startTime": 1642587001759, "success": false, "testResults": [ @@ -316,6 +334,15 @@ exports[`json reporter (no outputFile entry) 1`] = ` "status": "passed", "title": "callback test success done(false)", }, + { + "ancestorTitles": [ + "suite", + ], + "failureMessages": [], + "fullName": "suite todo test", + "status": "todo", + "title": "todo test", + }, ], "endTime": 1642587001759, "message": "", @@ -332,12 +359,12 @@ exports[`json reporter 1`] = ` "numFailedTestSuites": 0, "numFailedTests": 1, "numPassedTestSuites": 3, - "numPassedTests": 7, + "numPassedTests": 8, "numPendingTestSuites": 0, "numPendingTests": 0, - "numTodoTests": 0, + "numTodoTests": 1, "numTotalTestSuites": 3, - "numTotalTests": 8, + "numTotalTests": 9, "startTime": 1642587001759, "success": false, "testResults": [ @@ -425,6 +452,15 @@ exports[`json reporter 1`] = ` "status": "passed", "title": "callback test success done(false)", }, + { + "ancestorTitles": [ + "suite", + ], + "failureMessages": [], + "fullName": "suite todo test", + "status": "todo", + "title": "todo test", + }, ], "endTime": 1642587001759, "message": "", @@ -447,11 +483,11 @@ exports[`json reporter with outputFile 2`] = ` \\"numPassedTestSuites\\": 3, \\"numFailedTestSuites\\": 0, \\"numPendingTestSuites\\": 0, - \\"numTotalTests\\": 8, - \\"numPassedTests\\": 7, + \\"numTotalTests\\": 9, + \\"numPassedTests\\": 8, \\"numFailedTests\\": 1, \\"numPendingTests\\": 0, - \\"numTodoTests\\": 0, + \\"numTodoTests\\": 1, \\"startTime\\": 1642587001759, \\"success\\": false, \\"testResults\\": [ @@ -538,6 +574,15 @@ exports[`json reporter with outputFile 2`] = ` \\"title\\": \\"callback test success done(false)\\", \\"duration\\": 0.1923508644104004, \\"failureMessages\\": [] + }, + { + \\"ancestorTitles\\": [ + \\"suite\\" + ], + \\"fullName\\": \\"suite todo test\\", + \\"status\\": \\"todo\\", + \\"title\\": \\"todo test\\", + \\"failureMessages\\": [] } ], \\"startTime\\": 1642587001759, @@ -561,11 +606,11 @@ exports[`json reporter with outputFile in non-existing directory 2`] = ` \\"numPassedTestSuites\\": 3, \\"numFailedTestSuites\\": 0, \\"numPendingTestSuites\\": 0, - \\"numTotalTests\\": 8, - \\"numPassedTests\\": 7, + \\"numTotalTests\\": 9, + \\"numPassedTests\\": 8, \\"numFailedTests\\": 1, \\"numPendingTests\\": 0, - \\"numTodoTests\\": 0, + \\"numTodoTests\\": 1, \\"startTime\\": 1642587001759, \\"success\\": false, \\"testResults\\": [ @@ -652,6 +697,15 @@ exports[`json reporter with outputFile in non-existing directory 2`] = ` \\"title\\": \\"callback test success done(false)\\", \\"duration\\": 0.1923508644104004, \\"failureMessages\\": [] + }, + { + \\"ancestorTitles\\": [ + \\"suite\\" + ], + \\"fullName\\": \\"suite todo test\\", + \\"status\\": \\"todo\\", + \\"title\\": \\"todo test\\", + \\"failureMessages\\": [] } ], \\"startTime\\": 1642587001759, @@ -675,11 +729,11 @@ exports[`json reporter with outputFile object 2`] = ` \\"numPassedTestSuites\\": 3, \\"numFailedTestSuites\\": 0, \\"numPendingTestSuites\\": 0, - \\"numTotalTests\\": 8, - \\"numPassedTests\\": 7, + \\"numTotalTests\\": 9, + \\"numPassedTests\\": 8, \\"numFailedTests\\": 1, \\"numPendingTests\\": 0, - \\"numTodoTests\\": 0, + \\"numTodoTests\\": 1, \\"startTime\\": 1642587001759, \\"success\\": false, \\"testResults\\": [ @@ -766,6 +820,15 @@ exports[`json reporter with outputFile object 2`] = ` \\"title\\": \\"callback test success done(false)\\", \\"duration\\": 0.1923508644104004, \\"failureMessages\\": [] + }, + { + \\"ancestorTitles\\": [ + \\"suite\\" + ], + \\"fullName\\": \\"suite todo test\\", + \\"status\\": \\"todo\\", + \\"title\\": \\"todo test\\", + \\"failureMessages\\": [] } ], \\"startTime\\": 1642587001759, @@ -789,11 +852,11 @@ exports[`json reporter with outputFile object in non-existing directory 2`] = ` \\"numPassedTestSuites\\": 3, \\"numFailedTestSuites\\": 0, \\"numPendingTestSuites\\": 0, - \\"numTotalTests\\": 8, - \\"numPassedTests\\": 7, + \\"numTotalTests\\": 9, + \\"numPassedTests\\": 8, \\"numFailedTests\\": 1, \\"numPendingTests\\": 0, - \\"numTodoTests\\": 0, + \\"numTodoTests\\": 1, \\"startTime\\": 1642587001759, \\"success\\": false, \\"testResults\\": [ @@ -880,6 +943,15 @@ exports[`json reporter with outputFile object in non-existing directory 2`] = ` \\"title\\": \\"callback test success done(false)\\", \\"duration\\": 0.1923508644104004, \\"failureMessages\\": [] + }, + { + \\"ancestorTitles\\": [ + \\"suite\\" + ], + \\"fullName\\": \\"suite todo test\\", + \\"status\\": \\"todo\\", + \\"title\\": \\"todo test\\", + \\"failureMessages\\": [] } ], \\"startTime\\": 1642587001759, @@ -898,7 +970,7 @@ exports[`tap reporter 1`] = ` not ok 1 - test/core/test/basic.test.ts # time=145.99ms { 1..1 ok 1 - suite # time=1.90ms { - 1..8 + 1..9 ok 1 - inner suite # time=1.90ms { 1..1 not ok 1 - Math.sqrt() # time=1.44ms @@ -918,6 +990,7 @@ not ok 1 - test/core/test/basic.test.ts # time=145.99ms { ok 6 - callback test success # time=0.33ms ok 7 - callback setup success done(false) # time=19.74ms ok 8 - callback test success done(false) # time=0.19ms + ok 9 - todo test # TODO } } " @@ -925,7 +998,7 @@ not ok 1 - test/core/test/basic.test.ts # time=145.99ms { exports[`tap-flat reporter 1`] = ` "TAP version 13 -1..8 +1..9 not ok 1 - test/core/test/basic.test.ts > suite > inner suite > Math.sqrt() # time=1.44ms --- error: @@ -942,5 +1015,6 @@ ok 5 - test/core/test/basic.test.ts > suite > callback setup success # time=20. ok 6 - test/core/test/basic.test.ts > suite > callback test success # time=0.33ms ok 7 - test/core/test/basic.test.ts > suite > callback setup success done(false) # time=19.74ms ok 8 - test/core/test/basic.test.ts > suite > callback test success done(false) # time=0.19ms +ok 9 - test/core/test/basic.test.ts > suite > todo test # TODO " `;