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

mark "todo" tests as skipped #261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
82 changes: 82 additions & 0 deletions __mocks__/no-failing-tests-with-todo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"numFailedTestSuites": 0,
"numFailedTests": 0,
"numPassedTestSuites": 1,
"numPassedTests": 1,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numRuntimeErrorTestSuites": 0,
"numTodoTests": 1,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this always comes out set to 0 - if so I think the rest of the .json files should be updated to reflect this ...

"numTotalTestSuites": 1,
"numTotalTests": 2,
"snapshot": {
"added": 0,
"failure": false,
"filesAdded": 0,
"filesRemoved": 0,
"filesUnmatched": 0,
"filesUpdated": 0,
"matched": 0,
"total": 0,
"unchecked": 0,
"unmatched": 0,
"updated": 0
},
"startTime": 1489712747092,
"success": true,
"testResults": [
{
"console": null,
"failureMessage": null,
"numFailingTests": 0,
"numPassingTests": 1,
"numPendingTests": 0,
"numTodoTests": 1,
"perfStats": {
"end": 1489712747644,
"start": 1489712747524
},
"snapshot": {
"added": 0,
"fileDeleted": false,
"matched": 0,
"unchecked": 0,
"unmatched": 0,
"updated": 0
},
"testFilePath": "/path/to/test/__tests__/foo.test.js",
"testResults": [
{
"ancestorTitles": [
"foo",
"baz"
],
"duration": 1,
"failureMessages": [],
"fullName": "foo baz should bar",
"numPassingAsserts": 0,
"status": "passed",
"title": "should bar"
},
{
"ancestorTitles": [
"foo",
"bar"
],
"duration": 0,
"failureDetails": [],
"failureMessages": [],
"fullName": "foo bar should baz",
"invocations": 1,
"location": null,
"numPassingAsserts": 0,
"retryReasons": [],
"status": "todo",
"title": "should baz"
}
],
"skipped": false
}
],
"wasInterrupted": false
}
28 changes: 27 additions & 1 deletion __tests__/buildJsonResults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,32 @@ describe('buildJsonResults', () => {
expect(jsonResults.testsuites[1].testsuite[2]['system-out']).not.toBeDefined();
});

it('should include number of todo tests in testSuite skipped count', () => {
const noFailingTestsWithTodoReport = require('../__mocks__/no-failing-tests-with-todo.json');
jsonResults = buildJsonResults(noFailingTestsWithTodoReport, '/', constants.DEFAULT_OPTIONS);

expect(jsonResults.testsuites[1].testsuite[0]._attr.skipped).toBe(1);
});

it('should include number of todo tests in testSuite total count', () => {
const noFailingTestsWithTodoReport = require('../__mocks__/no-failing-tests-with-todo.json');
jsonResults = buildJsonResults(noFailingTestsWithTodoReport, '/', constants.DEFAULT_OPTIONS);

expect(jsonResults.testsuites[1].testsuite[0]._attr.tests).toBe(2);
});

it('should include a skipped tag when outputting todo tests', () => {
const noFailingTestsWithTodoReport = require('../__mocks__/no-failing-tests-with-todo.json');
jsonResults = buildJsonResults(noFailingTestsWithTodoReport, '/', constants.DEFAULT_OPTIONS);
expect(jsonResults.testsuites[1].testsuite[3].testcase[1]).toEqual({
"skipped": {
"_attr": {
"message": "todo"
}
}
});
});

it("should add properties to testcase (non standard)", () => {
const retriedTestsReport = require("../__mocks__/retried-tests.json");
// <properties> in <testcase> is not compatible JUnit but can be consumed by some e.g. DataDog
Expand All @@ -452,7 +478,7 @@ describe('buildJsonResults', () => {
...constants.DEFAULT_OPTIONS,
testCasePropertiesFile: "junitDataDogInvocationsProperties.js",
});

expect(jsonResults).toMatchInlineSnapshot(`
Object {
"testsuites": Array [
Expand Down
14 changes: 12 additions & 2 deletions utils/buildJsonResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file
});
}

if (tc.status === 'todo') {
testCase.testcase.push({
skipped: {
_attr: {
message: "todo"
}
}
});
}

if (getGetCaseProperties !== null) {
let junitCaseProperties = getGetCaseProperties(tc);

Expand Down Expand Up @@ -216,7 +226,7 @@ module.exports = function (report, appDirectory, options, rootDir = null) {
suiteNameVariables[constants.DISPLAY_NAME_VAR] = displayName;

// Add <testsuite /> properties
const suiteNumTests = suite.numFailingTests + suite.numPassingTests + suite.numPendingTests;
const suiteNumTests = suite.numFailingTests + suite.numPassingTests + suite.numPendingTests + (suite.numTodoTests ? suite.numTodoTests : 0);
const suiteExecutionTime = executionTime(suite.perfStats.start, suite.perfStats.end);

const suiteErrors = noResults ? 1 : 0;
Expand All @@ -226,7 +236,7 @@ module.exports = function (report, appDirectory, options, rootDir = null) {
name: replaceVars(suiteOptions.suiteNameTemplate, suiteNameVariables),
errors: suiteErrors,
failures: suite.numFailingTests,
skipped: suite.numPendingTests,
skipped: suite.numPendingTests + (suite.numTodoTests ? suite.numTodoTests : 0),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and the numTodoTests ? numTodoTests : 0 in this file updated to just numTodoTests.

But, if numTodoTests only comes out after a certain Jest version, and it would entail bumping them minimum compatible version of jest in this library's package.json, then I suppose it's fine to leave the test harness and this line as-is.

Anyone know?

timestamp: (new Date(suite.perfStats.start)).toISOString().slice(0, -5),
time: suiteExecutionTime,
tests: suiteNumTests
Expand Down