Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Fixing issue #138 #139

Merged
merged 3 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions lib/cucumberEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class CucumberEventListener extends EventEmitter {
const doc = this.gherkinDocEvents.find(gde => gde.uri === uri).document
const feature = doc.feature
const scenario = feature.children.find((child) => compareScenenarioLineWithSourceLine(child, sourceLocation))
const step = getStepFromFeature(feature, testStepStartedEvent.index)
const step = getStepFromFeature(feature, testStepStartedEvent.index, sourceLocation)

this.emit('before-step', uri, feature, scenario, step, sourceLocation)
}
Expand All @@ -114,13 +114,18 @@ export class CucumberEventListener extends EventEmitter {
// }
onTestCasePrepared (testCasePreparedEvent) {
this.testCasePreparedEvents.push(testCasePreparedEvent)
const steps = testCasePreparedEvent.steps
const sourceLocation = testCasePreparedEvent.sourceLocation
const uri = sourceLocation.uri

const doc = this.gherkinDocEvents.find(gde => gde.uri === uri).document
const scenario = doc.feature.children.find((child) => compareScenenarioLineWithSourceLine(child, sourceLocation))

const scenarioHasHooks = steps.filter((step) => step.type === 'Hook').length > 0
const scenarioHasHooks = scenario.steps.filter((step) => step.type === 'Hook').length > 0
if (scenarioHasHooks) {
return
}
steps.forEach((step, idx) => {
const allSteps = testCasePreparedEvent.steps
allSteps.forEach((step, idx) => {
if (!step.sourceLocation) {
step.sourceLocation = { line: step.actionLocation.line, column: 0, uri: step.actionLocation.uri }
const hook = {
Expand All @@ -129,7 +134,7 @@ export class CucumberEventListener extends EventEmitter {
keyword: 'Hook',
text: ''
}
steps.splice(idx, 0, hook)
scenario.steps.splice(idx, 0, hook)
}
})
}
Expand All @@ -148,7 +153,7 @@ export class CucumberEventListener extends EventEmitter {
const doc = this.gherkinDocEvents.find(gde => gde.uri === uri).document
const feature = doc.feature
const scenario = feature.children.find((child) => compareScenenarioLineWithSourceLine(child, sourceLocation))
const step = getStepFromFeature(feature, testStepFinishedEvent.index)
const step = getStepFromFeature(feature, testStepFinishedEvent.index, sourceLocation)
const result = testStepFinishedEvent.result

this.emit('after-step', uri, feature, scenario, step, result, sourceLocation)
Expand Down Expand Up @@ -217,8 +222,13 @@ function compareScenenarioLineWithSourceLine (scenario, sourceLocation) {
}
}

function getStepFromFeature (feature, stepIndex) {
function getStepFromFeature (feature, stepIndex, sourceLocation) {
let combinedSteps = []
feature.children.forEach((child) => { combinedSteps = combinedSteps.concat(child.steps) })
feature.children.forEach((child) => {
if (child.type.indexOf('Scenario') > -1 && !compareScenenarioLineWithSourceLine(child, sourceLocation)) {
return
}
combinedSteps = combinedSteps.concat(child.steps)
})
return combinedSteps[stepIndex]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"release:major": "np major",
"test": "run-s eslint test:unit build test:postadapter",
"test:ci": "run-s clean eslint build test:cover test:postadapter",
"test:unit": "mocha --compilers js:babel-core/register \"./test/!(adapter.spec).js\"",
"test:unit": "mocha --bail --compilers js:babel-core/register \"./test/!(adapter.spec).js\"",
"test:postadapter": "mocha test/adapter.spec.js",
"test:cover": "babel-node ./node_modules/.bin/isparta cover --include 'lib/*.js' _mocha -- \"test/!(adapter.spec).js\"",
"prepare": "npm prune",
Expand Down
2 changes: 1 addition & 1 deletion test/hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('CucumberAdapter executes hooks using native Promises', () => {

it('should contain right step data', () => {
let step = afterStepHook.args[0]
step.text.should.be.equal(`should the title of the page be "Google"`)
step.text.should.startWith(`should the title of the page be`)
})
})

Expand Down