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: todo assertion status in json output #1223

Merged
merged 2 commits into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/json.ts
Expand Up @@ -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],
Expand Down
11 changes: 11 additions & 0 deletions test/reporters/src/data.ts
Expand Up @@ -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]
Expand Down
126 changes: 100 additions & 26 deletions test/reporters/tests/__snapshots__/reporters.spec.ts.snap
Expand Up @@ -3,7 +3,7 @@
exports[`JUnit reporter (no outputFile entry) 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<testsuites>
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"8\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"1\\" time=\\"0.1459928420\\">
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"9\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"2\\" time=\\"0.1459928420\\">
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; inner suite &gt; Math.sqrt()\\" time=\\"0.0014422860\\">
<failure message=\\"expected 2.23606797749979 to equal 2\\" type=\\"AssertionError\\">
AssertionError: expected 2.23606797749979 to equal 2
Expand All @@ -28,6 +28,9 @@ AssertionError: expected 2.23606797749979 to equal 2
[33merror[39m
</system-err>
</testcase>
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; todo test\\">
<skipped/>
</testcase>
</testsuite>
</testsuites>
"
Expand All @@ -36,7 +39,7 @@ AssertionError: expected 2.23606797749979 to equal 2
exports[`JUnit reporter 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<testsuites>
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"8\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"1\\" time=\\"0.1459928420\\">
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"9\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"2\\" time=\\"0.1459928420\\">
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; inner suite &gt; Math.sqrt()\\" time=\\"0.0014422860\\">
<failure message=\\"expected 2.23606797749979 to equal 2\\" type=\\"AssertionError\\">
AssertionError: expected 2.23606797749979 to equal 2
Expand All @@ -61,6 +64,9 @@ AssertionError: expected 2.23606797749979 to equal 2
[33merror[39m
</system-err>
</testcase>
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; todo test\\">
<skipped/>
</testcase>
</testsuite>
</testsuites>
"
Expand All @@ -74,7 +80,7 @@ exports[`JUnit reporter with outputFile 1`] = `
exports[`JUnit reporter with outputFile 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<testsuites>
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"8\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"1\\" time=\\"0.1459928420\\">
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"9\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"2\\" time=\\"0.1459928420\\">
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; inner suite &gt; Math.sqrt()\\" time=\\"0.0014422860\\">
<failure message=\\"expected 2.23606797749979 to equal 2\\" type=\\"AssertionError\\">
AssertionError: expected 2.23606797749979 to equal 2
Expand All @@ -99,6 +105,9 @@ AssertionError: expected 2.23606797749979 to equal 2
[33merror[39m
</system-err>
</testcase>
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; todo test\\">
<skipped/>
</testcase>
</testsuite>
</testsuites>
"
Expand All @@ -112,7 +121,7 @@ exports[`JUnit reporter with outputFile in non-existing directory 1`] = `
exports[`JUnit reporter with outputFile in non-existing directory 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<testsuites>
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"8\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"1\\" time=\\"0.1459928420\\">
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"9\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"2\\" time=\\"0.1459928420\\">
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; inner suite &gt; Math.sqrt()\\" time=\\"0.0014422860\\">
<failure message=\\"expected 2.23606797749979 to equal 2\\" type=\\"AssertionError\\">
AssertionError: expected 2.23606797749979 to equal 2
Expand All @@ -137,6 +146,9 @@ AssertionError: expected 2.23606797749979 to equal 2
[33merror[39m
</system-err>
</testcase>
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; todo test\\">
<skipped/>
</testcase>
</testsuite>
</testsuites>
"
Expand All @@ -150,7 +162,7 @@ exports[`JUnit reporter with outputFile object 1`] = `
exports[`JUnit reporter with outputFile object 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<testsuites>
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"8\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"1\\" time=\\"0.1459928420\\">
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"9\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"2\\" time=\\"0.1459928420\\">
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; inner suite &gt; Math.sqrt()\\" time=\\"0.0014422860\\">
<failure message=\\"expected 2.23606797749979 to equal 2\\" type=\\"AssertionError\\">
AssertionError: expected 2.23606797749979 to equal 2
Expand All @@ -175,6 +187,9 @@ AssertionError: expected 2.23606797749979 to equal 2
[33merror[39m
</system-err>
</testcase>
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; todo test\\">
<skipped/>
</testcase>
</testsuite>
</testsuites>
"
Expand All @@ -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`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<testsuites>
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"8\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"1\\" time=\\"0.1459928420\\">
<testsuite name=\\"test/core/test/basic.test.ts\\" timestamp=\\"2022-01-19T10:10:01.759Z\\" hostname=\\"hostname\\" tests=\\"9\\" failures=\\"1\\" errors=\\"0\\" skipped=\\"2\\" time=\\"0.1459928420\\">
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; inner suite &gt; Math.sqrt()\\" time=\\"0.0014422860\\">
<failure message=\\"expected 2.23606797749979 to equal 2\\" type=\\"AssertionError\\">
AssertionError: expected 2.23606797749979 to equal 2
Expand All @@ -213,6 +228,9 @@ AssertionError: expected 2.23606797749979 to equal 2
[33merror[39m
</system-err>
</testcase>
<testcase classname=\\"test/core/test/basic.test.ts\\" name=\\"suite &gt; todo test\\">
<skipped/>
</testcase>
</testsuite>
</testsuites>
"
Expand All @@ -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": [
Expand Down Expand Up @@ -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": "",
Expand All @@ -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": [
Expand Down Expand Up @@ -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": "",
Expand All @@ -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\\": [
Expand Down Expand Up @@ -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,
Expand All @@ -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\\": [
Expand Down Expand Up @@ -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,
Expand All @@ -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\\": [
Expand Down Expand Up @@ -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,
Expand All @@ -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\\": [
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -918,14 +990,15 @@ 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
}
}
"
`;

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:
Expand All @@ -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
"
`;