Skip to content

Commit 8c9211b

Browse files
authored
chore: capture metadata from cucumber (#86)
1 parent 1d82bd3 commit 8c9211b

File tree

5 files changed

+394
-7
lines changed

5 files changed

+394
-7
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "test-results-parser",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Parse test results from JUnit, TestNG, xUnit, cucumber and many more",
55
"main": "src/index.js",
66
"types": "./src/index.d.ts",

src/parsers/cucumber.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CucumberParser extends BaseParser {
5151
test_suite.duration = test_suite.cases.reduce((total, _) => total + _.duration, 0);
5252
test_suite.duration = parseFloat(test_suite.duration.toFixed(2));
5353
test_suite.status = test_suite.total === test_suite.passed ? 'PASS' : 'FAIL';
54-
const { tags, metadata } = this.#getTagsAndMetadata(feature.tags);
54+
const { tags, metadata } = this.#getTagsAndMetadata(feature);
5555
test_suite.tags = tags;
5656
test_suite.metadata = metadata;
5757
for (const test_case of test_suite.cases) {
@@ -88,7 +88,7 @@ class CucumberParser extends BaseParser {
8888
test_case.failure = failed_step.failure;
8989
test_case.stack_trace = failed_step.stack_trace
9090
}
91-
const { tags, metadata } = this.#getTagsAndMetadata(scenario.tags);
91+
const { tags, metadata } = this.#getTagsAndMetadata(scenario);
9292
test_case.tags = tags;
9393
test_case.metadata = metadata;
9494
return test_case;
@@ -134,9 +134,10 @@ class CucumberParser extends BaseParser {
134134

135135
/**
136136
*
137-
* @param {import('./cucumber.result').CucumberTag[]} cucumber_tags
137+
* @param {import('./cucumber.result').CucumberFeature | import('./cucumber.result').CucumberElement} feature
138138
*/
139-
#getTagsAndMetadata(cucumber_tags) {
139+
#getTagsAndMetadata(feature) {
140+
const cucumber_tags = feature.tags || [];
140141
const metadata = {};
141142
const tags = [];
142143
if (cucumber_tags) {
@@ -149,6 +150,10 @@ class CucumberParser extends BaseParser {
149150
}
150151
}
151152
}
153+
if (feature.metadata) {
154+
Object.assign(metadata, feature.metadata);
155+
}
156+
152157
return { tags, metadata };
153158
}
154159

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
[
2+
{
3+
"description": "Verify calculator functionalities",
4+
"elements": [
5+
{
6+
"description": "",
7+
"id": "addition;addition-of-two-numbers",
8+
"keyword": "Scenario",
9+
"line": 5,
10+
"name": "Addition of two numbers",
11+
"steps": [
12+
{
13+
"arguments": [],
14+
"keyword": "Given ",
15+
"line": 6,
16+
"name": "I have number 6 in calculator",
17+
"match": {
18+
"location": "features\\support\\steps.js:5"
19+
},
20+
"result": {
21+
"status": "passed",
22+
"duration": 1211400
23+
}
24+
},
25+
{
26+
"arguments": [],
27+
"keyword": "When ",
28+
"line": 7,
29+
"name": "I entered number 7",
30+
"match": {
31+
"location": "features\\support\\steps.js:9"
32+
},
33+
"result": {
34+
"status": "passed",
35+
"duration": 136500
36+
}
37+
},
38+
{
39+
"arguments": [],
40+
"keyword": "Then ",
41+
"line": 8,
42+
"name": "I should see result 13",
43+
"match": {
44+
"location": "features\\support\\steps.js:13"
45+
},
46+
"result": {
47+
"status": "passed",
48+
"duration": 244700
49+
}
50+
}
51+
],
52+
"tags": [
53+
{
54+
"name": "@green",
55+
"line": 4
56+
},
57+
{
58+
"name": "@fast",
59+
"line": 4
60+
},
61+
{
62+
"name": "@testCase=1234",
63+
"line": 4
64+
}
65+
],
66+
"type": "scenario"
67+
}
68+
],
69+
"id": "addition",
70+
"line": 1,
71+
"keyword": "Feature",
72+
"name": "Addition",
73+
"tags": [
74+
{
75+
"name": "@blue",
76+
"line": 4
77+
},
78+
{
79+
"name": "@slow",
80+
"line": 4
81+
},
82+
{
83+
"name": "@suite=1234",
84+
"line": 4
85+
}
86+
],
87+
"uri": "features\\sample.feature",
88+
"metadata": {
89+
"browser": { "name": "firefox", "version": "129.0" },
90+
"device": "Desktop",
91+
"platform": { "name": "Windows", "version": "11" }
92+
}
93+
},
94+
{
95+
"description": "Verify calculator functionalities",
96+
"elements": [
97+
{
98+
"description": "",
99+
"id": "addition;addition-of-two-numbers",
100+
"keyword": "Scenario",
101+
"line": 5,
102+
"name": "Addition of two numbers",
103+
"steps": [
104+
{
105+
"arguments": [],
106+
"keyword": "Given ",
107+
"line": 6,
108+
"name": "I have number 6 in calculator",
109+
"match": {
110+
"location": "features\\support\\steps.js:5"
111+
},
112+
"result": {
113+
"status": "passed",
114+
"duration": 1211400
115+
}
116+
},
117+
{
118+
"arguments": [],
119+
"keyword": "When ",
120+
"line": 7,
121+
"name": "I entered number 7",
122+
"match": {
123+
"location": "features\\support\\steps.js:9"
124+
},
125+
"result": {
126+
"status": "passed",
127+
"duration": 136500
128+
}
129+
},
130+
{
131+
"arguments": [],
132+
"keyword": "Then ",
133+
"line": 8,
134+
"name": "I should see result 13",
135+
"match": {
136+
"location": "features\\support\\steps.js:13"
137+
},
138+
"result": {
139+
"status": "passed",
140+
"duration": 244700
141+
}
142+
}
143+
],
144+
"tags": [
145+
{
146+
"name": "@green",
147+
"line": 4
148+
},
149+
{
150+
"name": "@fast",
151+
"line": 4
152+
},
153+
{
154+
"name": "@testCase=1234",
155+
"line": 4
156+
}
157+
],
158+
"type": "scenario"
159+
}
160+
],
161+
"id": "addition",
162+
"line": 1,
163+
"keyword": "Feature",
164+
"name": "Addition",
165+
"tags": [
166+
{
167+
"name": "@blue",
168+
"line": 4
169+
},
170+
{
171+
"name": "@slow",
172+
"line": 4
173+
},
174+
{
175+
"name": "@suite=1234",
176+
"line": 4
177+
}
178+
],
179+
"uri": "features\\sample.feature",
180+
"metadata": {
181+
"browser": { "name": "chrome", "version": "129.0" },
182+
"device": "Desktop",
183+
"platform": { "name": "Windows", "version": "11" }
184+
}
185+
}
186+
]

0 commit comments

Comments
 (0)