Skip to content

Commit 4eb9517

Browse files
committed
move to strip function
1 parent 539cdbc commit 4eb9517

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ const processor = (report, reporterOptions = {}, jestRootDir = null) => {
3434
// Ensure output path exists
3535
mkdirp.sync(path.dirname(outputPath));
3636

37-
// Clean ESC character, which is invalid XML and some libraries include in error messages
38-
const xmlString = xml(jsonResults, { indent: ' ', declaration: true });
39-
const cleanedXmlString = xmlString.replace(/\u001b/g, '');
40-
4137
// Write data to file
42-
fs.writeFileSync(outputPath, cleanedXmlString);
38+
fs.writeFileSync(outputPath, xml(jsonResults, { indent: ' ', declaration: true }));
4339

4440
// Jest 18 compatibility
4541
return report;

utils/buildJsonResults.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file
7474
failureMessages.forEach((failure) => {
7575
const tagName = tc.status === testFailureStatus ? 'failure': testErrorStatus
7676
testCase.testcase.push({
77-
[tagName]: stripAnsi(failure)
77+
[tagName]: strip(failure)
7878
});
7979
})
8080
}
@@ -102,6 +102,11 @@ const addErrorTestResult = function (suite) {
102102
})
103103
}
104104

105+
// Strips escape codes for readability and illegal XML characters to produce valid output.
106+
const strip = function (str) {
107+
return stripAnsi(str).replace(/\u001b/g, '');
108+
}
109+
105110
module.exports = function (report, appDirectory, options, rootDir = null) {
106111
// Check if there is a junitProperties.js (or whatever they called it)
107112
const junitSuitePropertiesFilePath = getTestSuitePropertiesPath(

0 commit comments

Comments
 (0)