diff --git a/package-lock.json b/package-lock.json index b70024e..2f6c297 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "fast-xml-parser": "^4.3.2", "globrex": "^0.1.2", + "html-escaper": "^3.0.3", "totalist": "^3.0.0" }, "devDependencies": { @@ -561,10 +562,9 @@ } }, "node_modules/html-escaper": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", - "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", - "dev": true + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz", + "integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ==" }, "node_modules/inflight": { "version": "1.0.6", @@ -708,6 +708,12 @@ "node": ">=8" } }, + "node_modules/istanbul-reports/node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true + }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -1671,10 +1677,9 @@ "dev": true }, "html-escaper": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", - "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", - "dev": true + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz", + "integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ==" }, "inflight": { "version": "1.0.6", @@ -1782,6 +1787,14 @@ "requires": { "html-escaper": "^2.0.0", "istanbul-lib-report": "^3.0.0" + }, + "dependencies": { + "html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true + } } }, "js-yaml": { diff --git a/package.json b/package.json index 49d3f1f..6160b3b 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "dependencies": { "fast-xml-parser": "^4.3.2", "globrex": "^0.1.2", + "html-escaper": "^3.0.3", "totalist": "^3.0.0" }, "devDependencies": { diff --git a/src/models/TestCase.d.ts b/src/models/TestCase.d.ts index bfda0b2..0215e34 100644 --- a/src/models/TestCase.d.ts +++ b/src/models/TestCase.d.ts @@ -13,7 +13,10 @@ declare class TestCase { stack_trace: string; steps: TestStep[]; meta_data: Map; + + setFailure: SetFailureFunction } +export type SetFailureFunction = (value: string) => string; declare namespace TestCase { } diff --git a/src/models/TestCase.js b/src/models/TestCase.js index 85ca61c..be6f3db 100644 --- a/src/models/TestCase.js +++ b/src/models/TestCase.js @@ -1,3 +1,5 @@ +const { unescape } = require('html-escaper'); + class TestCase { constructor() { @@ -15,6 +17,10 @@ class TestCase { this.steps = []; this.meta_data = new Map(); } + + setFailure(value) { + this.failure = value ? unescape(value) : value; + } } diff --git a/src/parsers/cucumber.js b/src/parsers/cucumber.js index d20b5d6..cd7cffd 100644 --- a/src/parsers/cucumber.js +++ b/src/parsers/cucumber.js @@ -1,6 +1,3 @@ -/* -* Parser for both Mocha Json report and Mochawesome json -*/ const { resolveFilePath } = require('../helpers/helper'); const TestResult = require('../models/TestResult'); @@ -28,7 +25,7 @@ function getTestCase(rawCase) { } if (rawCase.state && rawCase.state === "failed") { test_case.status = 'FAIL'; - test_case.failure = rawCase.errorStack; + test_case.setFailure(rawCase.errorStack); } else { test_case.status = 'PASS'; diff --git a/src/parsers/junit.js b/src/parsers/junit.js index 094c104..dc5037d 100644 --- a/src/parsers/junit.js +++ b/src/parsers/junit.js @@ -19,7 +19,7 @@ function getTestCase(rawCase, suiteProperties) { } if (rawCase.failure && rawCase.failure.length > 0) { test_case.status = 'FAIL'; - test_case.failure = rawCase.failure[0]["@_message"]; + test_case.setFailure(rawCase.failure[0]["@_message"]); } else { test_case.status = 'PASS'; } diff --git a/src/parsers/mocha.js b/src/parsers/mocha.js index 8754af0..2aedfd0 100644 --- a/src/parsers/mocha.js +++ b/src/parsers/mocha.js @@ -32,7 +32,7 @@ function getTestCase(rawCase) { } else if (rawCase.state && rawCase.state === "failed") { test_case.status = 'FAIL'; - test_case.failure = rawCase.err["message"]; + test_case.setFailure(rawCase.err["message"]); } else { test_case.status = 'PASS'; diff --git a/src/parsers/testng.js b/src/parsers/testng.js index 3eb1738..a9ebaef 100644 --- a/src/parsers/testng.js +++ b/src/parsers/testng.js @@ -45,7 +45,7 @@ function getTestCase(rawCase, testCaseToGroupMap) { }) } if (rawCase.exception) { - test_case.failure = rawCase.exception[0].message; + test_case.setFailure(rawCase.exception[0].message); } if (rawCase['@_retried'] === true) { test_case.status = 'RETRY'; diff --git a/src/parsers/xunit.js b/src/parsers/xunit.js index 790146f..8bad9a7 100644 --- a/src/parsers/xunit.js +++ b/src/parsers/xunit.js @@ -14,7 +14,7 @@ function getTestCase(rawCase) { } else if (rawCase.failure && rawCase.failure.length > 0) { test_case.status = 'FAIL'; - test_case.failure = rawCase.failure[0]["message"]; + test_case.setFailure(rawCase.failure[0]["message"]); } else { test_case.status = 'PASS'; diff --git a/tests/data/testng/single-suite-multiple-tests.xml b/tests/data/testng/single-suite-multiple-tests.xml index 93f048f..800ab7a 100644 --- a/tests/data/testng/single-suite-multiple-tests.xml +++ b/tests/data/testng/single-suite-multiple-tests.xml @@ -131,7 +131,7 @@ - + diff --git a/tests/parser.testng.spec.js b/tests/parser.testng.spec.js index 66b3637..1912971 100644 --- a/tests/parser.testng.spec.js +++ b/tests/parser.testng.spec.js @@ -175,7 +175,7 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 57111, "status": "FAIL", - "failure": "Expected condition failed: : 95ddbda01ea4b3dbcb049e681a6...}", + "failure": "Expected condition failed: : <95ddbda01ea4b3dbcb049e681a6>", "stack_trace": "", "meta_data": new Map(), "steps": [] @@ -788,7 +788,7 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 57111, "status": "FAIL", - "failure": "Expected condition failed: : 95ddbda01ea4b3dbcb049e681a6...}", + "failure": "Expected condition failed: : <95ddbda01ea4b3dbcb049e681a6>", "stack_trace": "", "meta_data": new Map(), "steps": []