Skip to content

Commit 9bc1608

Browse files
Merge pull request #12 from qavajs/step-gherkin-location
Step gherkin location
2 parents fc68f29 + 4be9010 commit 9bc1608

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed

CHANGELOG.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.0
2+
- added step gherkin location
3+
- fixed issue with identifying hook keyword
4+
15
## 0.4.0
26
- updated logs displaying
37

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/console-formatter",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "console formatter for cucumber framework",
55
"scripts": {
66
"test:e2e": "qavajs run --config test-e2e/config.js"
@@ -29,8 +29,8 @@
2929
"figures": "^3.2.0"
3030
},
3131
"devDependencies": {
32-
"@cucumber/cucumber": "^9.2.0",
33-
"@qavajs/cli": "^0.26.0",
32+
"@cucumber/cucumber": "^9.3.0",
33+
"@qavajs/cli": "^0.27.0",
3434
"@qavajs/memory": "^1.6.0"
3535
}
3636
}

src/formatter.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class PrettyFormatter extends Formatter {
141141
const result = this.eventDataCollector.getTestCaseAttempt(testCase.testCaseStartedId);
142142
const tc = this.testCases[testCase.testCaseStartedId];
143143
tc.testSteps.forEach(step => {
144+
step.gherkinLocation = this.stepGherkinLocation(step, result);
144145
step.logs = result.stepAttachments[step.id]?.filter(attachment => attachment.mediaType === 'text/x.cucumber.log+plain') ?? [];
145146
});
146147
this.updateRunStatus(tc);
@@ -156,7 +157,7 @@ class PrettyFormatter extends Formatter {
156157

157158
drawStep(step) {
158159
let line = this.indent + chalk.bold(this.statusIcons[step.testStepResult.status]) + ' ' + step.stepText;
159-
line += ` ${chalk.gray(step.location)}`;
160+
line += ` ${chalk.gray(step.gherkinLocation)}${chalk.gray(step.location)}`;
160161
if (step.argument && step.argument.dataTable) {
161162
line += `\n${this.drawDataTable(step.argument.dataTable)}`
162163
}
@@ -199,7 +200,23 @@ class PrettyFormatter extends Formatter {
199200
hookKeyword(steps, testStep) {
200201
const hook = this.stepDefinitions[testStep.hookId];
201202
if (hook.name) return hook.name
202-
return steps.every(element => element.stepText === undefined || element.stepText === 'Before') ? 'Before' : 'After'
203+
const hookIndex = steps.findIndex(element => element.hookId === testStep.hookId);
204+
return steps.slice(0, hookIndex).some(element => element.pickleStepId) ? 'After' : 'Before'
205+
}
206+
207+
stepGherkinLocation(step, scenario) {
208+
if (step.pickleStepId) {
209+
const [ scenarioPickleId ] = scenario.pickle.astNodeIds;
210+
const pickle = scenario.pickle.steps.find(e => e.id === step.pickleStepId);
211+
const [ astNodeId] = pickle.astNodeIds;
212+
const children = scenario.gherkinDocument.feature.children;
213+
const scenarioSource = children.find(child => child.scenario?.id === scenarioPickleId);
214+
const backgroundSource = children.find(child => child.background);
215+
const stepsSources = [].concat(scenarioSource?.scenario?.steps).concat(backgroundSource?.background?.steps).filter(x => x);
216+
const stepSource = stepsSources.find(s => s.id === astNodeId);
217+
return stepSource ? `${scenario.gherkinDocument.uri}:${stepSource.location.line} ` : '';
218+
}
219+
return '';
203220
}
204221

205222
}

0 commit comments

Comments
 (0)