Skip to content

Commit

Permalink
fix: step names in cucumber (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored Jul 28, 2024
1 parent af9fb39 commit 2726544
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 17 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.1.20",
"version": "0.2.1",
"description": "Parse test results from JUnit, TestNG, xUnit, cucumber and many more",
"main": "src/index.js",
"types": "./src/index.d.ts",
Expand Down
10 changes: 8 additions & 2 deletions src/parsers/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ class CucumberParser extends BaseParser {
const test_case = new TestCase();
test_case.name = scenario.name;
for (const step of scenario.steps) {
test_case.steps.push(this.#getTestStep(step));
const test_step = this.#getTestStep(step);
if (test_step) {
test_case.steps.push(test_step);
}
}
test_case.total = test_case.steps.length;
test_case.passed = test_case.steps.filter(step => step.status === "PASS").length;
Expand All @@ -95,8 +98,11 @@ class CucumberParser extends BaseParser {
* @param {import('./cucumber.result').CucumberStep} step
*/
#getTestStep(step) {
if (!step.keyword) {
return;
}
const test_step = new TestStep();
test_step.name = step.name;
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.duration = step.result.duration ? parseFloat((step.result.duration / 1000000).toFixed(2)) : 0;
if (test_step.status === "FAIL") {
Expand Down
105 changes: 105 additions & 0 deletions tests/data/cucumber/test-with-before-and-after.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
[
{
"description": "Verify calculator functionalities",
"elements": [
{
"description": "",
"id": "addition;addition-of-two-numbers",
"keyword": "Scenario",
"line": 5,
"name": "Addition of two numbers",
"steps": [
{
"keyword": "Before",
"hidden": true,
"result": {
"status": "passed",
"duration": 60072
}
},
{
"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": "passed",
"duration": 244700
}
},
{
"keyword": "After",
"hidden": true,
"result": {
"status": "passed",
"duration": 98253
}
}
],
"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"
}
]
117 changes: 105 additions & 12 deletions tests/parser.cucumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ describe('Parser - Cucumber Json', () => {
steps: [
{
"id": "",
"name": "I have number 6 in calculator",
"name": "Given I have number 6 in calculator",
"duration": 1.21,
"status": "PASS",
"failure": "",
"stack_trace": ""
},
{
"id": "",
"name": "I entered number 7",
"name": "When I entered number 7",
"duration": 0.14,
"status": "PASS",
"failure": "",
"stack_trace": ""
},
{
"id": "",
"name": "I should see result 13",
"name": "Then I should see result 13",
"duration": 0.24,
"status": "PASS",
"failure": "",
Expand Down Expand Up @@ -148,23 +148,23 @@ describe('Parser - Cucumber Json', () => {
steps: [
{
id: "",
name: "I have number 6 in calculator",
name: "Given I have number 6 in calculator",
duration: 1.1,
status: "PASS",
failure: "",
stack_trace: ""
},
{
id: "",
name: "I add number 7",
name: "When I add number 7",
duration: 0.13,
status: "PASS",
failure: "",
stack_trace: ""
},
{
id: "",
name: "I should see result 14",
name: "Then I should see result 14",
duration: 1.33,
status: "FAIL",
failure: "AssertionError [ERR_ASSERTION]: 13 == 14\n + expected - actual\n\n -13\n +14\n\n",
Expand All @@ -190,23 +190,23 @@ describe('Parser - Cucumber Json', () => {
steps: [
{
id: "",
name: "I have number 6 in calculator",
name: "Given I have number 6 in calculator",
duration: 0.11,
status: "PASS",
failure: "",
stack_trace: ""
},
{
id: "",
name: "I add number 7",
name: "When I add number 7",
duration: 0.1,
status: "PASS",
failure: "",
stack_trace: ""
},
{
id: "",
name: "I should see result 13",
name: "Then I should see result 13",
duration: 0.08,
status: "PASS",
failure: "",
Expand Down Expand Up @@ -247,23 +247,23 @@ describe('Parser - Cucumber Json', () => {
steps: [
{
id: "",
name: "I have number 10 in calculator",
name: "Given I have number 10 in calculator",
duration: 0.08,
status: "PASS",
failure: "",
stack_trace: ""
},
{
id: "",
name: "I subtract number 7",
name: "When I subtract number 7",
duration: 0.13,
status: "PASS",
failure: "",
stack_trace: ""
},
{
id: "",
name: "I should see result 3",
name: "Then I should see result 3",
duration: 0.31,
status: "PASS",
failure: "",
Expand All @@ -287,4 +287,97 @@ describe('Parser - Cucumber Json', () => {
assert.notEqual(null, result2);
});

it('test with before and after', () => {
const result = parse({ type: 'cucumber', files: [`${testDataPath}/test-with-before-and-after.json`] });
assert.deepEqual(result, {
id: '',
name: '',
total: 1,
passed: 1,
failed: 0,
errors: 0,
skipped: 0,
retried: 0,
duration: 1.75,
status: 'PASS',
tags: [],
metadata: {},
suites: [
{
id: '',
name: 'Addition',
total: 1,
passed: 1,
failed: 0,
errors: 0,
skipped: 0,
duration: 1.75,
status: 'PASS',
tags: ["@blue", "@slow"],
metadata: { suite: "1234" },
cases: [
{
attachments: [],
duration: 1.75,
errors: 0,
failed: 0,
failure: "",
id: "",
name: "Addition of two numbers",
passed: 5,
skipped: 0,
stack_trace: "",
status: "PASS",
tags: ["@green", "@fast", "@blue", "@slow"],
metadata: { "suite": "1234", testCase: "1234" },
steps: [
{
"id": "",
"name": "Before ",
"duration": 0.06,
"status": "PASS",
"failure": "",
"stack_trace": ""
},
{
"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": 0.24,
"status": "PASS",
"failure": "",
"stack_trace": ""
},
{
"id": "",
"name": "After ",
"duration": 0.1,
"status": "PASS",
"failure": "",
"stack_trace": ""
},
],
total: 5
}
]
}
]
});
});

});

0 comments on commit 2726544

Please sign in to comment.