Skip to content

Commit 3435179

Browse files
committed
mark "todo" tests as skipped
1 parent a7f59c1 commit 3435179

File tree

3 files changed

+113
-2
lines changed

3 files changed

+113
-2
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"numFailedTestSuites": 0,
3+
"numFailedTests": 0,
4+
"numPassedTestSuites": 1,
5+
"numPassedTests": 1,
6+
"numPendingTestSuites": 0,
7+
"numPendingTests": 0,
8+
"numRuntimeErrorTestSuites": 0,
9+
"numTodoTests": 1,
10+
"numTotalTestSuites": 1,
11+
"numTotalTests": 2,
12+
"snapshot": {
13+
"added": 0,
14+
"failure": false,
15+
"filesAdded": 0,
16+
"filesRemoved": 0,
17+
"filesUnmatched": 0,
18+
"filesUpdated": 0,
19+
"matched": 0,
20+
"total": 0,
21+
"unchecked": 0,
22+
"unmatched": 0,
23+
"updated": 0
24+
},
25+
"startTime": 1489712747092,
26+
"success": true,
27+
"testResults": [
28+
{
29+
"console": null,
30+
"failureMessage": null,
31+
"numFailingTests": 0,
32+
"numPassingTests": 1,
33+
"numPendingTests": 0,
34+
"numTodoTests": 1,
35+
"perfStats": {
36+
"end": 1489712747644,
37+
"start": 1489712747524
38+
},
39+
"snapshot": {
40+
"added": 0,
41+
"fileDeleted": false,
42+
"matched": 0,
43+
"unchecked": 0,
44+
"unmatched": 0,
45+
"updated": 0
46+
},
47+
"testFilePath": "/path/to/test/__tests__/foo.test.js",
48+
"testResults": [
49+
{
50+
"ancestorTitles": [
51+
"foo",
52+
"baz"
53+
],
54+
"duration": 1,
55+
"failureMessages": [],
56+
"fullName": "foo baz should bar",
57+
"numPassingAsserts": 0,
58+
"status": "passed",
59+
"title": "should bar"
60+
},
61+
{
62+
"ancestorTitles": [
63+
"foo",
64+
"bar"
65+
],
66+
"duration": 0,
67+
"failureDetails": [],
68+
"failureMessages": [],
69+
"fullName": "foo bar should baz",
70+
"invocations": 1,
71+
"location": null,
72+
"numPassingAsserts": 0,
73+
"retryReasons": [],
74+
"status": "todo",
75+
"title": "should baz"
76+
}
77+
],
78+
"skipped": false
79+
}
80+
],
81+
"wasInterrupted": false
82+
}

__tests__/buildJsonResults.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,25 @@ describe('buildJsonResults', () => {
440440
expect(jsonResults.testsuites[1].testsuite[2]['system-out']).not.toBeDefined();
441441
});
442442

443+
it('should include number of todo tests in testSuite skipped count', () => {
444+
const noFailingTestsWithTodoReport = require('../__mocks__/no-failing-tests-with-todo.json');
445+
jsonResults = buildJsonResults(noFailingTestsWithTodoReport, '/', constants.DEFAULT_OPTIONS);
446+
447+
expect(jsonResults.testsuites[1].testsuite[0]._attr.skipped).toBe(1);
448+
});
449+
450+
it('should include a skipped tag when outputting todo tests', () => {
451+
const noFailingTestsWithTodoReport = require('../__mocks__/no-failing-tests-with-todo.json');
452+
jsonResults = buildJsonResults(noFailingTestsWithTodoReport, '/', constants.DEFAULT_OPTIONS);
453+
expect(jsonResults.testsuites[1].testsuite[3].testcase[1]).toEqual({
454+
"skipped": {
455+
"_attr": {
456+
"message": "todo"
457+
}
458+
}
459+
});
460+
});
461+
443462
it("should add properties to testcase (non standard)", () => {
444463
const retriedTestsReport = require("../__mocks__/retried-tests.json");
445464
// <properties> in <testcase> is not compatible JUnit but can be consumed by some e.g. DataDog
@@ -452,7 +471,7 @@ describe('buildJsonResults', () => {
452471
...constants.DEFAULT_OPTIONS,
453472
testCasePropertiesFile: "junitDataDogInvocationsProperties.js",
454473
});
455-
474+
456475
expect(jsonResults).toMatchInlineSnapshot(`
457476
Object {
458477
"testsuites": Array [

utils/buildJsonResults.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file
102102
});
103103
}
104104

105+
if (tc.status === 'todo') {
106+
testCase.testcase.push({
107+
skipped: {
108+
_attr: {
109+
message: "todo"
110+
}
111+
}
112+
});
113+
}
114+
105115
if (getGetCaseProperties !== null) {
106116
let junitCaseProperties = getGetCaseProperties(tc);
107117

@@ -226,7 +236,7 @@ module.exports = function (report, appDirectory, options, rootDir = null) {
226236
name: replaceVars(suiteOptions.suiteNameTemplate, suiteNameVariables),
227237
errors: suiteErrors,
228238
failures: suite.numFailingTests,
229-
skipped: suite.numPendingTests,
239+
skipped: suite.numPendingTests + (suite.numTodoTests ? suite.numTodoTests : 0),
230240
timestamp: (new Date(suite.perfStats.start)).toISOString().slice(0, -5),
231241
time: suiteExecutionTime,
232242
tests: suiteNumTests

0 commit comments

Comments
 (0)