Permalink
Browse files

fix(cucumber): Support callback style step definitions (fixes #8)

Match syncronized steps with the contract cucumber expects. es6 generators accepted by cucumber are still not supported (#9)
  • Loading branch information...
Fialkovskyi, Ievgen (ITCDEC) - KLM Fialkovskyi, Ievgen (ITCDEC) - KLM
Fialkovskyi, Ievgen (ITCDEC) - KLM authored and Fialkovskyi, Ievgen (ITCDEC) - KLM committed Dec 2, 2016
1 parent f3d7198 commit 4278968bed1a627ee64f80f3e8142d09bb429d51
Showing with 22 additions and 2 deletions.
  1. +1 −0 package.json
  2. +21 −2 src/serenity-cucumber/webdriver_synchroniser.ts
View
@@ -35,6 +35,7 @@
},
"dependencies": {
"graceful-fs": "4.1.4",
"is-generator": "1.0.3",
"lodash": "4.13.1",
"mkdirp": "0.5.1",
"moment": "2.14.1",
@@ -1,6 +1,7 @@
import { Deferred } from '../serenity/recording/async';
import withArityOf = require('util-arity');
import { StepDefinitions } from 'cucumber';
import {fn as isGeneratorFn} from 'is-generator';
import * as webdriver from 'selenium-webdriver';
@@ -23,7 +24,7 @@ export function synchronise (cucumber: StepDefinitions, controlFlow: webdriver.p
// ---
/**
* Creates a synchronising StepGenerator, which looks like a regular StepGenerator but with this signifficant
* Creates a synchronising StepGenerator, which looks like a regular StepGenerator but with this significant
* difference, that any step function passed to it will be wrapped and executed in the context of WebDriver
* Control Flow
*
@@ -59,15 +60,33 @@ export function synchronise (cucumber: StepDefinitions, controlFlow: webdriver.p
let deferred = new Deferred<void>(),
context = this;
if (isGeneratorFn(originalStep)) {
throw 'Synchronizing e6 generator style steps is not supported by serenity-js yet';
}
controlFlow
.execute(() => originalStep.apply(context, args) )
.then(deferred.resolve, deferred.reject);
return deferred.promise;
if (!hasCallbackInterface(originalStep, args)) {
return deferred.promise;
}
};
}
}
/**
* Assumes that step definition has a callback interface if the number of parameters passed by cucumber
* matches its signature
*
* @return boolean
* @param step
* @param params
*/
function hasCallbackInterface(step: SomeFunction, params: any[]): boolean {
return step.length === params.length;
}
/**
* Makes the pretender function of the same arity as the original one to deceive cucumber.
*

0 comments on commit 4278968

Please sign in to comment.