Skip to content

Commit

Permalink
Merge pull request #221 from azzlack/master
Browse files Browse the repository at this point in the history
Don't assume test execution failure if testExecError is null
  • Loading branch information
palmerj3 authored Aug 26, 2022
2 parents a68ff32 + 5bd498f commit d0fb7dc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
65 changes: 65 additions & 0 deletions __mocks__/no-failing-tests-with-testexec-null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"numFailedTestSuites": 0,
"numFailedTests": 0,
"numPassedTestSuites": 1,
"numPassedTests": 1,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numRuntimeErrorTestSuites": 0,
"numTotalTestSuites": 1,
"numTotalTests": 1,
"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,
"testExecError": null,
"numFailingTests": 0,
"numPassingTests": 1,
"numPendingTests": 0,
"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"
}
],
"skipped": false
}
],
"wasInterrupted": false
}
12 changes: 11 additions & 1 deletion __tests__/buildJsonResults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('buildJsonResults', () => {
expect(errorSuite.testcase[1].error).toContain("Cannot find module './mult'");
});

it('should include a failing testcase from a suite with passing testcases but a failure from "testExec" ', () => {
it('should include a failing testcase from a suite with passing testcases but a failure from "testExecError" ', () => {
const failingTestsReport = require('../__mocks__/no-failing-tests-with-testexec-failure.json');

jsonResults = buildJsonResults(failingTestsReport, '/path/to/test',
Expand All @@ -192,6 +192,16 @@ describe('buildJsonResults', () => {
expect(errorSuite.testcase[1].failure).toContain("beforeAll has crashed");
});

it('should not include a failing testcase from a suite with passing testcases but a null value from "testExecError" ', () => {
const notFailingTestsReport = require('../__mocks__/no-failing-tests-with-testexec-null.json');

jsonResults = buildJsonResults(notFailingTestsReport, '/path/to/test',
Object.assign({}, constants.DEFAULT_OPTIONS, {}));

expect(jsonResults.testsuites[1].testsuite[2].testcase.length).toBe(1);
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.name).toEqual('foo baz should bar');
});

it('should report empty suites as error', () => {
const failingTestsReport = require('../__mocks__/empty-suite.json');

Expand Down
2 changes: 1 addition & 1 deletion utils/buildJsonResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module.exports = function (report, appDirectory, options, rootDir = null) {

// We have all tests passed but a failure in a test hook like in the `beforeAll` method
// Make sure we log them since Jest still reports the suite as failed
if (suite.testExecError !== undefined) {
if (suite.testExecError != null) {
const fakeTC = {
status: testFailureStatus,
failureMessages: [JSON.stringify(suite.testExecError)],
Expand Down

0 comments on commit d0fb7dc

Please sign in to comment.