Skip to content

Commit

Permalink
Merge pull request #21 from palmerj3/failureFixes
Browse files Browse the repository at this point in the history
Nest test failure messages in <failure> tags instead of failure->message property and strip escape codes from output
  • Loading branch information
palmerj3 authored Jul 13, 2017
2 parents f7de5d8 + 3f4780e commit f5620f2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
66 changes: 66 additions & 0 deletions __mocks__/failing-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"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": [],
"failureMessage": "\u001b[1m\u001b[31m \u001b[1m● \u001b[1mSample Failing Test › Should fail\u001b[39m\u001b[22m\n\n foobar\n\u001b[2m \n \u001b[2mat _callee$ (\u001b[2m\u001b[0m\u001b[36mpath/to/failing.test.js\u001b[39m\u001b[0m\u001b[2m:26:15)\u001b[2m\n \u001b[2mat tryCatch (\u001b[2m\u001b[0m\u001b[36mnode_modules/regenerator-runtime/runtime.js\u001b[39m\u001b[0m\u001b[2m:64:40)\u001b[2m\n \u001b[2mat GeneratorFunctionPrototype.invoke [as _invoke] (\u001b[2m\u001b[0m\u001b[36mnode_modules/regenerator-runtime/runtime.js\u001b[39m\u001b[0m\u001b[2m:299:22)\u001b[2m\n \u001b[2mat GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (\u001b[2m\u001b[0m\u001b[36mnode_modules/regenerator-runtime/runtime.js\u001b[39m\u001b[0m\u001b[2m:116:21)\u001b[2m\n \u001b[2mat step (\u001b[2m\u001b[0m\u001b[36mpath/to/failing.test.js\u001b[39m\u001b[0m\u001b[2m:2:394)\u001b[2m\n \u001b[2mat \u001b[2m\u001b[0m\u001b[36mpath/to/failing.test.js\u001b[39m\u001b[0m\u001b[2m:2:554\u001b[2m\u001b[22m\n",
"numFailingTests": 1,
"numPassingTests": 0,
"numPendingTests": 0,
"perfStats": {
"end": 1499904221109,
"start": 1499904215586
},
"snapshot": {
"added": 0,
"fileDeleted": false,
"matched": 0,
"unchecked": 0,
"unmatched": 0,
"updated": 0
},
"testFilePath": "/path/to/failing.test.js",
"testResults": [
{
"ancestorTitles": [
"Sample Failing Test"
],
"duration": 3930,
"failureMessages": [
"\u001b[1m\u001b[31m \u001b[1m● \u001b[1mSample Failing Test › Should fail\u001b[39m\u001b[22m\n\n foobar\n\u001b[2m \n \u001b[2mat _callee$ (\u001b[2m\u001b[0m\u001b[36mpath/to/failing.test.js\u001b[39m\u001b[0m\u001b[2m:26:15)\u001b[2m\n \u001b[2mat tryCatch (\u001b[2m\u001b[0m\u001b[36mnode_modules/regenerator-runtime/runtime.js\u001b[39m\u001b[0m\u001b[2m:64:40)\u001b[2m\n \u001b[2mat GeneratorFunctionPrototype.invoke [as _invoke] (\u001b[2m\u001b[0m\u001b[36mnode_modules/regenerator-runtime/runtime.js\u001b[39m\u001b[0m\u001b[2m:299:22)\u001b[2m\n \u001b[2mat GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (\u001b[2m\u001b[0m\u001b[36mnode_modules/regenerator-runtime/runtime.js\u001b[39m\u001b[0m\u001b[2m:116:21)\u001b[2m\n \u001b[2mat step (\u001b[2m\u001b[0m\u001b[36mpath/to/failing.test.js\u001b[39m\u001b[0m\u001b[2m:2:394)\u001b[2m\n \u001b[2mat \u001b[2m\u001b[0m\u001b[36mpath/to/failing.test.js\u001b[39m\u001b[0m\u001b[2m:2:554\u001b[2m\u001b[22m\n"
],
"fullName": "Sample Failing Test Should fail",
"numPassingAsserts": 0,
"status": "failed",
"title": "Should fail"
}
],
"sourceMaps": {},
"skipped": false
}
],
"wasInterrupted": false
}
11 changes: 11 additions & 0 deletions __tests__/buildJsonResults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ describe('buildJsonResults', () => {
Object.assign({}, constants.DEFAULT_OPTIONS, { usePathForSuiteName: "true" }));
expect(jsonResults.testsuites[1].testsuite[0]._attr.name).toBe('/__tests__/foo.test.js');
});

it('should parse failure messages for failing tests', () => {
const failingTestsReport = require('../__mocks__/failing-tests.json');
const jsonResults = buildJsonResults(failingTestsReport, '/path/to/test', constants.DEFAULT_OPTIONS);

const failureMsg = jsonResults.testsuites[1].testsuite[1].testcase[1].failure;

// Make sure no escape codes are there that exist in the mock
expect(failureMsg.includes('\u001b')).toBe(false);

});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
},
"dependencies": {
"mkdirp": "^0.5.1",
"strip-ansi": "^4.0.0",
"xml": "^1.0.1"
},
"devDependencies": {
"jest": "^19.0.2",
"jest": "20.0.4",
"libxmljs": "^0.18.4"
}
}
7 changes: 2 additions & 5 deletions utils/buildJsonResults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const stripAnsi = require('strip-ansi');
const constants = require('../constants/index');

const replaceVars = function (str, classname, title) {
Expand Down Expand Up @@ -64,11 +65,7 @@ module.exports = function (report, appDirectory, options) {
if (tc.status === 'failed') {
tc.failureMessages.forEach((failure) => {
testCase.testcase.push({
'failure': [{
_attr: {
message: failure || ''
}
}]
'failure': stripAnsi(failure)
});
})
}
Expand Down

0 comments on commit f5620f2

Please sign in to comment.