diff --git a/package-lock.json b/package-lock.json index ed4c701..3d8bf02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "test-results-parser", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "test-results-parser", - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "dependencies": { "fast-xml-parser": "^4.3.2", diff --git a/package.json b/package.json index 7fb6787..aafd795 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "test-results-parser", - "version": "0.2.1", + "version": "0.2.2", "description": "Parse test results from JUnit, TestNG, xUnit, cucumber and many more", "main": "src/index.js", "types": "./src/index.d.ts", diff --git a/src/parsers/base.parser.js b/src/parsers/base.parser.js index 37901e6..ce03e75 100644 --- a/src/parsers/base.parser.js +++ b/src/parsers/base.parser.js @@ -3,6 +3,24 @@ const { unescape } = require('html-escaper'); class BaseParser { + /** + * + * @param {string} value + * @returns + */ + parseStatus(value) { + if (value === 'passed') { + return 'PASS'; + } + if (value === 'failed') { + return 'FAIL'; + } + if (value === 'skipped') { + return 'SKIP'; + } + return 'FAIL'; + } + /** * @param {string} value * @returns diff --git a/src/parsers/cucumber.js b/src/parsers/cucumber.js index c3d5e01..da5ca74 100644 --- a/src/parsers/cucumber.js +++ b/src/parsers/cucumber.js @@ -79,6 +79,7 @@ class CucumberParser extends BaseParser { test_case.total = test_case.steps.length; test_case.passed = test_case.steps.filter(step => step.status === "PASS").length; test_case.failed = test_case.steps.filter(step => step.status === "FAIL").length; + test_case.skipped = test_case.steps.filter(step => step.status === "SKIP").length; test_case.duration = test_case.steps.reduce((total, _) => total + _.duration, 0); test_case.duration = parseFloat((test_case.duration).toFixed(2)); test_case.status = test_case.total === test_case.passed ? 'PASS' : 'FAIL'; @@ -103,7 +104,7 @@ class CucumberParser extends BaseParser { } const test_step = new TestStep(); test_step.name = step.keyword.endsWith(' ') ? step.keyword + (step.name || '') : step.keyword + ' ' + (step.name || ''); - test_step.status = step.result.status === "passed" ? "PASS" : "FAIL"; + test_step.status = this.parseStatus(step.result.status); test_step.duration = step.result.duration ? parseFloat((step.result.duration / 1000000).toFixed(2)) : 0; if (test_step.status === "FAIL") { const { failure, stack_trace } = this.#getFailureAndStackTrace(step.result.error_message); diff --git a/tests/data/cucumber/test-with-skipped-steps.json b/tests/data/cucumber/test-with-skipped-steps.json new file mode 100644 index 0000000..dd55206 --- /dev/null +++ b/tests/data/cucumber/test-with-skipped-steps.json @@ -0,0 +1,103 @@ +[ + { + "description": "Verify calculator functionalities", + "elements": [ + { + "description": "", + "id": "addition;addition-of-two-numbers", + "keyword": "Scenario", + "line": 5, + "name": "Addition of two numbers", + "steps": [ + { + "arguments": [], + "keyword": "Given ", + "line": 6, + "name": "I have number 6 in calculator", + "match": { + "location": "features\\support\\steps.js:5" + }, + "result": { + "status": "passed", + "duration": 1211400 + } + }, + { + "arguments": [], + "keyword": "When ", + "line": 7, + "name": "I entered number 7", + "match": { + "location": "features\\support\\steps.js:9" + }, + "result": { + "status": "passed", + "duration": 136500 + } + }, + { + "arguments": [], + "keyword": "Then ", + "line": 8, + "name": "I should see result 13", + "match": { + "location": "features\\support\\steps.js:13" + }, + "result": { + "status": "failed", + "duration": 1330499, + "error_message": "AssertionError [ERR_ASSERTION]: 13 == 14\n + expected - actual\n\n -13\n +14\n\n at CustomWorld. (D:\\workspace\\nodejs\\cc-tests\\features\\support\\steps.js:18:12)" + } + }, + { + "arguments": [], + "keyword": "And ", + "line": 49, + "name": "I close the test", + "match": { + "location": "features\\support\\steps.js:14" + }, + "result": { + "status": "skipped", + "duration": 0 + } + } + ], + "tags": [ + { + "name": "@green", + "line": 4 + }, + { + "name": "@fast", + "line": 4 + }, + { + "name": "@testCase=1234", + "line": 4 + } + ], + "type": "scenario" + } + ], + "id": "addition", + "line": 1, + "keyword": "Feature", + "name": "Addition", + "tags": [ + { + "name": "@blue", + "line": 4 + }, + { + "name": "@slow", + "line": 4 + }, + { + "name": "@suite=1234", + "line": 4 + } + ], + "uri": "features\\sample.feature" + } +] \ No newline at end of file diff --git a/tests/parser.cucumber.spec.js b/tests/parser.cucumber.spec.js index c4541e0..3ddca81 100644 --- a/tests/parser.cucumber.spec.js +++ b/tests/parser.cucumber.spec.js @@ -380,4 +380,89 @@ describe('Parser - Cucumber Json', () => { }); }); + it('test with skipped steps', () => { + const result = parse({ type: 'cucumber', files: [`${testDataPath}/test-with-skipped-steps.json`] }); + assert.deepEqual(result, { + id: '', + name: '', + total: 1, + passed: 0, + failed: 1, + errors: 0, + skipped: 0, + retried: 0, + duration: 2.68, + status: 'FAIL', + tags: [], + metadata: {}, + suites: [ + { + id: '', + name: 'Addition', + total: 1, + passed: 0, + failed: 1, + errors: 0, + skipped: 0, + duration: 2.68, + status: 'FAIL', + tags: ["@blue", "@slow"], + metadata: { suite: "1234" }, + cases: [ + { + attachments: [], + duration: 2.68, + errors: 0, + failed: 1, + failure: "AssertionError [ERR_ASSERTION]: 13 == 14\n + expected - actual\n\n -13\n +14\n\n", + id: "", + name: "Addition of two numbers", + passed: 2, + skipped: 1, + stack_trace: " at CustomWorld. (D:\\workspace\\nodejs\\cc-tests\\features\\support\\steps.js:18:12)", + status: "FAIL", + tags: ["@green", "@fast", "@blue", "@slow"], + metadata: { "suite": "1234", testCase: "1234" }, + steps: [ + { + "id": "", + "name": "Given I have number 6 in calculator", + "duration": 1.21, + "status": "PASS", + "failure": "", + "stack_trace": "" + }, + { + "id": "", + "name": "When I entered number 7", + "duration": 0.14, + "status": "PASS", + "failure": "", + "stack_trace": "" + }, + { + "id": "", + "name": "Then I should see result 13", + "duration": 1.33, + "status": "FAIL", + "failure": "AssertionError [ERR_ASSERTION]: 13 == 14\n + expected - actual\n\n -13\n +14\n\n", + "stack_trace": " at CustomWorld. (D:\\workspace\\nodejs\\cc-tests\\features\\support\\steps.js:18:12)" + }, + { + "duration": 0, + "failure": "", + "id": "", + "name": "And I close the test", + "stack_trace": "", + "status": "SKIP" + } + ], + total: 4 + } + ] + } + ] + }); + }); + });