Permalink
Browse files

fix(serenity-cucumber): Cucumber data table and docstring steps are c…

…orrectly reported

Closes #14
  • Loading branch information...
jan-molak committed Jan 22, 2017
1 parent 8f0b4cf commit 053955df5444a422382581660fd73de8b186df14

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,19 @@
Feature: Recognises special step arguments
# https://github.com/cucumber/cucumber-js/blob/b659dc887ee8e94149b2148e83857b6c653aa2fa/features/data_tables.feature
@datatable
Scenario: Reports a data table argument
Given the following accounts:
| name | email | twitter |
| Jan | jan.molak@serenity.io | @JanMolak |
| John | john.smart@serenity.io | @wakaleo |
@docstring
Scenario: Reports a DocString argument
Given an example.ts file with the following content:
"""
export const noop = (_) => _;
export const sum = (a, b) => a + b;
"""
@@ -106,4 +106,8 @@ export = function () {
this.Given(/^a pending step with a generator interface$/,
createStep(StepInterface.GENERATOR, StepResult.PENDING));
this.Given(/^the following.*$/, data => Promise.resolve());
this.Given(/^an example.ts file with the following content:$/, docstring => Promise.resolve());
};
@@ -0,0 +1,65 @@
import expect = require('../../expect');
import { spawner } from '../../support/spawner';
describe('When working with Cucumber', function () {
this.timeout(30 * 1000); // it might take a while to start up the selenium server
const protractorSpawner = spawner(
process.cwd() + '/node_modules/.bin/protractor',
{ cwd: __dirname, silent: true },
);
const protractor = (specs: string, tag: string) => protractorSpawner('protractor.conf.js',
'--specs', specs,
'--cucumberOpts.tags', tag,
'--disableChecks', // needed until https://github.com/angular/protractor/issues/3978 is fixed
);
describe('Serenity/JS', () => {
const messagesPerStep = 4;
it ('reports data table arguments', () => {
let spawned = protractor('**/*special_step_arguments.feature', '@datatable');
return expect(spawned.result).to.be.eventually.fulfilled.then(() => {
expect(spawned.messages).to.have.lengthOf(messagesPerStep);
let cucumberStepDescriptionFromActivityStartedMessage = spawned.messages[1].value.name,
cucumberStepDescriptionFromActivityFinishedMessage = spawned.messages[2].value.subject.name;
expect(cucumberStepDescriptionFromActivityStartedMessage).to.equal([
'Given the following accounts:',
'| name | email | twitter |',
'| Jan | jan.molak@serenity.io | @JanMolak |',
'| John | john.smart@serenity.io | @wakaleo |',
].join('\n'));
expect(cucumberStepDescriptionFromActivityStartedMessage).
to.equal(cucumberStepDescriptionFromActivityFinishedMessage);
});
});
it ('reports DocString arguments', () => {
let spawned = protractor('**/*special_step_arguments.feature', '@docstring');
return expect(spawned.result).to.be.eventually.fulfilled.then(() => {
expect(spawned.messages).to.have.lengthOf(messagesPerStep);
let cucumberStepDescriptionFromActivityStartedMessage = spawned.messages[1].value.name,
cucumberStepDescriptionFromActivityFinishedMessage = spawned.messages[2].value.subject.name;
expect(cucumberStepDescriptionFromActivityStartedMessage).to.equal([
'Given an example.ts file with the following content:',
'export const noop = (_) => _;',
'export const sum = (a, b) => a + b;',
].join('\n'));
expect(cucumberStepDescriptionFromActivityStartedMessage).
to.equal(cucumberStepDescriptionFromActivityFinishedMessage);
});
});
});
});
@@ -60,12 +60,32 @@ function handleScenarioResultEvent (result: cucumber.events.ScenarioResultPayloa
// --
function fullNameOf(step: cucumber.events.StepPayload): string {
const serialise = (argument: any) => {
switch (argument.getType()) {
case 'DataTable':
return '\n' + argument.raw().map(row => `| ${row.join(' | ')} |`).join('\n');
case 'DocString':
return `\n${ argument.getContent() }`;
default:
return '';
}
};
return [
step.getKeyword(),
step.getName(),
(step as any).getArguments().map(serialise).join('\n'), // todo: submit getArguments() to DefinitelyTyped
].join('').trim();
}
function sceneFrom(scenario: cucumber.events.ScenarioPayload): Scene {
return new CucumberScene(scenario);
}
function activityFrom(step: cucumber.events.StepPayload): Activity {
return new Activity(step.getKeyword() + step.getName());
return new Activity(fullNameOf(step));
}
function outcome<T>(subject: T, status: string, error?: Error): Outcome<T> {

0 comments on commit 053955d

Please sign in to comment.