Skip to content

Commit

Permalink
fix: cucumber skipped tests (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored Aug 2, 2024
1 parent 2726544 commit a7cfa89
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 18 additions & 0 deletions src/parsers/base.parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/parsers/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
103 changes: 103 additions & 0 deletions tests/data/cucumber/test-with-skipped-steps.json
Original file line number Diff line number Diff line change
@@ -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.<anonymous> (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"
}
]
85 changes: 85 additions & 0 deletions tests/parser.cucumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> (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.<anonymous> (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
}
]
}
]
});
});

});

0 comments on commit a7cfa89

Please sign in to comment.