Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Add docString argument to steps #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ declare module 'cucumber' {
export type StepFunction = (
testController: typeof t,
parameters: any[],
dataTable: TableDefinition | null
dataTable: TableDefinition | null,
docString: string | null
) => Promise<void>;

export function Given(pattern: RegExp | string, code: StepFunction): void;
Expand Down
21 changes: 14 additions & 7 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,21 @@ module.exports = class GherkinTestcafeCompiler {

_resolveAndRunStepDefinition(testController, step) {
for (const stepDefinition of this.stepDefinitions) {
const [isMatched, parameters, table] = this._shouldRunStep(stepDefinition, step);
const [isMatched, parameters, table, docString] = this._shouldRunStep(stepDefinition, step);
if (isMatched) {
return this._runStep(stepDefinition.code, testController, parameters, table);
return this._runStep(stepDefinition.code, testController, parameters, table, docString);
}
}

throw new Error(`Step implementation missing for: ${step.text}`);
}

_runStep(step, testController, parameters, table) {
_runStep(step, testController, parameters, table, docString) {
const markedFn = testRunTracker.addTrackingMarkerToFunction(testController.testRun.id, step);

testRunTracker.ensureEnabled();

return markedFn(testController, parameters, table);
return markedFn(testController, parameters, table, docString);
}

_findHook(scenario, hooks) {
Expand All @@ -224,6 +224,12 @@ module.exports = class GherkinTestcafeCompiler {
);
}

_getCucumberDocString(step) {
if (step.argument && step.argument.docString) return step.argument.docString.content;
else if (step.docString) return step.docString.content;
else return null;
}

_getCucumberDataTable(step) {
if (step.argument && step.argument.dataTable) return new DataTable(step.argument.dataTable);
else if (step.dataTable) return new DataTable(step.dataTable);
Expand All @@ -239,11 +245,12 @@ module.exports = class GherkinTestcafeCompiler {

const matchResult = cucumberExpression.match(step.text);
return matchResult
? [true, matchResult.map(r => r.getValue()), this._getCucumberDataTable(step)]
: [false, [], this._getCucumberDataTable(step)];
? [true, matchResult.map(r => r.getValue()), this._getCucumberDataTable(step), this._getCucumberDocString(step)]
: [false, [], this._getCucumberDataTable(step), this._getCucumberDocString(step)];
} else if (stepDefinition.pattern instanceof RegExp) {
const match = stepDefinition.pattern.exec(step.text);
return [Boolean(match), match ? match.slice(1) : [], this._getCucumberDataTable(step)];
return [Boolean(match), match ? match.slice(1) : [], this._getCucumberDataTable(step),
this._getCucumberDocString(step)];
}

const stepType = step.text instanceof Object ? step.text.constructor.name : typeof step.text;
Expand Down