Skip to content

Commit

Permalink
move to strip function
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenxu-db committed Nov 11, 2022
1 parent 539cdbc commit 4eb9517
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ const processor = (report, reporterOptions = {}, jestRootDir = null) => {
// Ensure output path exists
mkdirp.sync(path.dirname(outputPath));

// Clean ESC character, which is invalid XML and some libraries include in error messages
const xmlString = xml(jsonResults, { indent: ' ', declaration: true });
const cleanedXmlString = xmlString.replace(/\u001b/g, '');

// Write data to file
fs.writeFileSync(outputPath, cleanedXmlString);
fs.writeFileSync(outputPath, xml(jsonResults, { indent: ' ', declaration: true }));

// Jest 18 compatibility
return report;
Expand Down
7 changes: 6 additions & 1 deletion utils/buildJsonResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file
failureMessages.forEach((failure) => {
const tagName = tc.status === testFailureStatus ? 'failure': testErrorStatus
testCase.testcase.push({
[tagName]: stripAnsi(failure)
[tagName]: strip(failure)
});
})
}
Expand Down Expand Up @@ -102,6 +102,11 @@ const addErrorTestResult = function (suite) {
})
}

// Strips escape codes for readability and illegal XML characters to produce valid output.
const strip = function (str) {
return stripAnsi(str).replace(/\u001b/g, '');
}

module.exports = function (report, appDirectory, options, rootDir = null) {
// Check if there is a junitProperties.js (or whatever they called it)
const junitSuitePropertiesFilePath = getTestSuitePropertiesPath(
Expand Down

0 comments on commit 4eb9517

Please sign in to comment.