Skip to content
Permalink
Browse files
fix(cucumber-2): the cucumber-2 module is compatible with the updated…
… serenity configuration format

affects: @serenity-js/cucumber-2
  • Loading branch information
jan-molak committed Apr 1, 2017
1 parent 256d29b commit 108d3763ab27b53b2004a9eca418e3d4a3ac77be
@@ -0,0 +1 @@
require('./lib/register');
@@ -4,11 +4,13 @@ import { ChildProcessReporter } from '../spawner/child_process_reporter';
import path = require('path');
import _ = require('lodash');

serenity.assignCrewMembers(new ChildProcessReporter());
serenity.configure({
crew: [new ChildProcessReporter()]
});

export = parsed => require(__dirname + '/../../src/index.ts')({ // tslint:disable-line:no-var-requires
cwd: path.resolve(__dirname, '..', '..'),
options: _(parsed.options).omitBy(_.isUndefined).omit('version').value(),
parameters: _(parsed.options).omitBy(_.isUndefined).omit('version').value(),
}).
run(_(parsed.args).without('').value()).
then(() => {
@@ -1,4 +1,5 @@
import { Config, TestFrameworkAdapter } from 'serenity-js/lib/serenity-protractor/framework';
import { TestFrameworkAdapter } from 'serenity-js/lib/serenity-protractor/framework';
import { SerenityConfig } from 'serenity-js/lib/serenity/serenity';
import { CucumberOptions } from './cucumber_options';

import _ = require('lodash');
@@ -11,7 +12,7 @@ export class CucumberAdapter implements TestFrameworkAdapter {

private argv: string[] = [];

constructor(private config: Config<CucumberOptions>) {
constructor(private config: SerenityConfig<CucumberOptions>) {
this.argv = [ 'node', 'cucumberjs' ]
.concat([ '--require', this.notifier() ])
.concat([ '--require', this.stageCue() ])
@@ -24,13 +25,13 @@ export class CucumberAdapter implements TestFrameworkAdapter {
stdout: process.stdout,
}).run().then(this.booleanToPromise)

private notifier = () => glob.sync(path.resolve(__dirname) + '/notifier.?s').pop();
private notifier = () => glob.sync(path.resolve(__dirname) + '/register.?s').pop();
private stageCue = () => glob.sync(path.resolve(__dirname) + '/stage_cue.?s').pop();

private booleanToPromise = (result: boolean) => result ? Promise.resolve(result) : Promise.reject(result);

private argumentsFrom(config: Config<CucumberOptions>): string[] {
const resolvedConfig = Object.assign({}, config.options, { require: this.resolved(config.options.require || []) });
private argumentsFrom(config: SerenityConfig<CucumberOptions>): string[] {
const resolvedConfig = Object.assign({}, config.parameters, { require: this.resolved(config.parameters.require || []) });

const toCLIArgument = option => (value: string) => !! value
? [ `--${ option }`, value ]
@@ -1,5 +1,5 @@
import { Config } from 'serenity-js/lib/serenity-protractor/framework/config';
import { SerenityConfig } from 'serenity-js/lib/serenity/serenity';
import { CucumberAdapter } from './cucumber_adapter';
import { CucumberOptions } from './cucumber_options';

export = (config: Config<CucumberOptions>) => new CucumberAdapter(config);
export = (config: SerenityConfig<CucumberOptions>) => new CucumberAdapter(config);
@@ -1,29 +1,30 @@
import { defineSupportCode } from 'cucumber';
import { serenity } from 'serenity-js';
import { ActivityFinished, ActivityStarts, Outcome, RecordedScene, RecordedTask, Result, SceneFinished, SceneStarts, Tag } from 'serenity-js/lib/serenity/domain';
import { DataTable, DocString, FailureException, Scenario, ScenarioResult, Step, StepArgument, StepResult } from './model';

const CucumberStep = require('cucumber/lib/models/step').default; // tslint:disable-line:no-var-requires

defineSupportCode(({ registerHandler }) => {
export class Notifier {
handleBeforeScenario = (scenario: Scenario) =>
serenity.notify(new SceneStarts(CucumberScene.from(scenario)));

function isOfInterest(step: any) {
// "Before hooks" will also trigger the listeners, but we don't want to report on them
// https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/event_handlers.md
return step instanceof CucumberStep && ! step.isHidden;
}
handleBeforeStep = (step: Step) =>
this.isOfInterest(step) && serenity.notify(new ActivityStarts(CucumberTask.from(step)));

registerHandler('BeforeScenario', (scenario: Scenario) => serenity.notify(new SceneStarts(CucumberScene.from(scenario))));
handleStepResult = (result: StepResult) =>
this.isOfInterest(result.step) && serenity.notify(new ActivityFinished(CucumberOutcome.fromStep(result)));

registerHandler('BeforeStep', (step: Step) =>
isOfInterest(step) && serenity.notify(new ActivityStarts(CucumberTask.from(step))));
handleScenarioResult = (result: ScenarioResult) =>
serenity.notify(new SceneFinished(CucumberOutcome.fromScenario(result)));

registerHandler('StepResult', (result: StepResult) =>
isOfInterest(result.step) && serenity.notify(new ActivityFinished(CucumberOutcome.fromStep(result))));
/**
* "Before hooks" will also trigger the listeners, but we don't want to report on them
* https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/event_handlers.md
* @param step
*/
private isOfInterest = (step: any) => step instanceof CucumberStep && ! step.isHidden;

registerHandler('ScenarioResult', (result: ScenarioResult) =>
serenity.notify(new SceneFinished(CucumberOutcome.fromScenario(result))));
});
}

class CucumberOutcome<T> extends Outcome<T> {

@@ -0,0 +1,7 @@
import { defineSupportCode } from 'cucumber';
import { Notifier } from './notifier';

defineSupportCode(({ registerListener }) => {

registerListener(new Notifier() as any);
});

0 comments on commit 108d376

Please sign in to comment.