Skip to content
Permalink
Browse files
feat(cucumber): Support for Cucumber 6
  • Loading branch information
jan-molak committed Oct 13, 2019
1 parent 2ce1b69 commit b437edd8b060194fd405b62ced916de76f7c17dc
Showing with 314 additions and 33 deletions.
  1. +2 −2 examples/cucumber-domain-level-testing/package.json
  2. +2 −2 examples/cucumber-reporting/package.json
  3. +2 −2 examples/cucumber-rest-api-level-testing/package.json
  4. +2 −2 examples/protractor-cucumber/package.json
  5. +1 −1 integration/cucumber-3-runner/package.json
  6. +1 −1 integration/cucumber-4-runner/package.json
  7. +1 −1 integration/cucumber-5-runner/package.json
  8. +7 −0 integration/cucumber-6-runner/.gitignore
  9. +8 −0 integration/cucumber-6-runner/README.md
  10. +44 −0 integration/cucumber-6-runner/package.json
  11. +18 −0 integration/cucumber-6-runner/src/index.ts
  12. +9 −0 integration/cucumber-6-runner/src/step_definitions/ambiguous.steps.ts
  13. +32 −0 integration/cucumber-6-runner/src/step_definitions/callback.steps.ts
  14. +32 −0 integration/cucumber-6-runner/src/step_definitions/promise.steps.ts
  15. +35 −0 integration/cucumber-6-runner/src/step_definitions/screenplay.steps.ts
  16. +26 −0 integration/cucumber-6-runner/src/step_definitions/synchronous.steps.ts
  17. +7 −0 integration/cucumber-6-runner/src/support/Actors.ts
  18. +5 −0 integration/cucumber-6-runner/src/support/after_hook.ts
  19. +5 −0 integration/cucumber-6-runner/src/support/before_hook.ts
  20. +15 −0 integration/cucumber-6-runner/src/support/configure_serenity.ts
  21. +5 −0 integration/cucumber-6-runner/src/support/wip_hook.ts
  22. +11 −0 integration/cucumber-6-runner/tsconfig-lint.json
  23. +20 −0 integration/cucumber-6-runner/tsconfig.json
  24. +1 −0 integration/cucumber/package.json
  25. +1 −1 integration/cucumber/spec/ambiguous_steps.spec.ts
  26. +1 −1 integration/cucumber/spec/assertion_failure_scenario.spec.ts
  27. +1 −1 integration/cucumber/spec/capabilities.spec.ts
  28. +1 −1 integration/cucumber/spec/data_table.spec.ts
  29. +1 −1 integration/cucumber/spec/descriptions.spec.ts
  30. +1 −1 integration/cucumber/spec/doc_string.spec.ts
  31. +1 −1 integration/cucumber/spec/failing_scenario.spec.ts
  32. +1 −1 integration/cucumber/spec/passing_scenario.spec.ts
  33. +6 −6 integration/cucumber/spec/pending_scenarios.spec.ts
  34. +1 −1 integration/cucumber/spec/scenario_outlines.spec.ts
  35. +1 −1 integration/cucumber/spec/screenplay_scenario.spec.ts
  36. +2 −2 integration/cucumber/spec/tags.spec.ts
  37. +1 −1 integration/cucumber/spec/themes.spec.ts
  38. +1 −1 integration/cucumber/spec/timed_out_scenario.spec.ts
  39. +2 −2 packages/cucumber/package.json
  40. +1 −0 packages/cucumber/src/listeners/cucumber-6.ts
@@ -42,8 +42,8 @@
"@serenity-js/cucumber": "2.0.1-alpha.84",
"@serenity-js/rest": "2.0.1-alpha.84",
"@serenity-js/serenity-bdd": "2.0.1-alpha.84",
"@types/cucumber": "4.0.4",
"cucumber": "5.0.1",
"@types/cucumber": "^4.0.7",
"cucumber": "6.0.2",
"npm-failsafe": "0.4.1",
"ts-node": "^8.4.1",
"typescript": "^3.6.3"
@@ -40,8 +40,8 @@
"@serenity-js/cucumber": "2.0.1-alpha.84",
"@serenity-js/rest": "2.0.1-alpha.84",
"@serenity-js/serenity-bdd": "2.0.1-alpha.84",
"@types/cucumber": "4.0.4",
"cucumber": "5.0.1",
"@types/cucumber": "^4.0.7",
"cucumber": "6.0.2",
"npm-failsafe": "0.4.1",
"ts-node": "^8.4.1",
"typescript": "^3.6.3"
@@ -43,10 +43,10 @@
"@serenity-js/local-server": "2.0.1-alpha.84",
"@serenity-js/rest": "2.0.1-alpha.84",
"@serenity-js/serenity-bdd": "2.0.1-alpha.84",
"@types/cucumber": "^4.0.5",
"@types/cucumber": "^4.0.7",
"@types/express": "^4.16.1",
"@types/mocha": "^5.2.6",
"cucumber": "^5.1.0",
"cucumber": "6.0.2",
"express": "^4.16.4",
"npm-failsafe": "^0.4.1",
"ts-node": "^8.4.1",
@@ -43,10 +43,10 @@
"@serenity-js/protractor": "2.0.1-alpha.84",
"@serenity-js/rest": "2.0.1-alpha.84",
"@serenity-js/serenity-bdd": "2.0.1-alpha.84",
"@types/cucumber": "^4.0.5",
"@types/cucumber": "^4.0.7",
"@types/express": "^4.16.1",
"chromedriver": "^77.0.0",
"cucumber": "^5.1.0",
"cucumber": "6.0.2",
"express": "^4.16.4",
"npm-failsafe": "0.4.1",
"protractor": "^5.4.2",
@@ -39,6 +39,6 @@
"cucumber": "3.2.1"
},
"devDependencies": {
"@types/cucumber": "3.2.2"
"@types/cucumber": "3.2.3"
}
}
@@ -39,6 +39,6 @@
"cucumber": "4.2.1"
},
"devDependencies": {
"@types/cucumber": "4.0.4"
"@types/cucumber": "4.0.7"
}
}
@@ -39,6 +39,6 @@
"cucumber": "5.1.0"
},
"devDependencies": {
"@types/cucumber": "4.0.4"
"@types/cucumber": "4.0.7"
}
}
@@ -0,0 +1,7 @@
# Node
node_modules
*.log

# Build artifacts
.nyc_output
lib
@@ -0,0 +1,8 @@
# Cucumber 4.x runner

This is an internal test module that embeds Cucumber 4.2.1
so that it can be executed against the integration tests in [`integration/cucumber`](../cucumber)

## Notes
- [Cucumber.js step definitions](https://github.com/cucumber/cucumber-js/blob/v4.2.1/docs/support_files/step_definitions.md)
- [Sample event protocol events](https://github.com/cucumber/cucumber-js/blob/v4.2.1/src/formatter/event_protocol_formatter.js)
@@ -0,0 +1,44 @@
{
"name": "@integration/cucumber-6-runner",
"version": "2.0.1-alpha.84",
"description": "Cucumber JS 6.x test runner",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"author": {
"name": "Jan Molak",
"email": "jan.molak@smartcodeltd.co.uk",
"url": "https://janmolak.com"
},
"homepage": "http://serenity-js.org",
"license": "Apache-2.0",
"private": true,
"config": {
"access": "private"
},
"scripts": {
"clean": "rimraf lib",
"lint": "tslint --project tsconfig-lint.json --config ../../tslint.json --format stylish",
"test": "exit 0",
"compile": "tsc --project tsconfig.json"
},
"repository": {
"type": "git",
"url": "https://github.com/jan-molak/serenity-js.git"
},
"bugs": {
"url": "https://github.com/jan-molak/serenity-js/issues"
},
"engines": {
"node": ">= 8",
"npm": ">= 5"
},
"dependencies": {
"@integration/testing-tools": "2.0.1-alpha.84",
"@serenity-js/core": "2.0.1-alpha.84",
"@serenity-js/cucumber": "2.0.1-alpha.84",
"cucumber": "6.0.2"
},
"devDependencies": {
"@types/cucumber": "4.0.7"
}
}
@@ -0,0 +1,18 @@
import { spawner, SpawnResult } from '@integration/testing-tools';
import * as path from 'path';

const cucumberExecutable = path.resolve(
require.resolve('cucumber/package.json'),
'..',
'bin',
'cucumber-js',
);

const cucumberSpawner = spawner(
cucumberExecutable,
{ cwd: path.resolve(__dirname, '..') },
);

export = (...params: string[]): Promise<SpawnResult> => cucumberSpawner(
...params,
);
@@ -0,0 +1,9 @@
import { Given } from 'cucumber';

Given(/^.*step (?:.*) passes$/, function () {
return void 0;
});

Given(/^.*step (?:.*) passes$/, function () {
return void 0;
});
@@ -0,0 +1,32 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

type Callback = (error?: Error, pending?: string) => void;

Given(/^.*step (?:.*) passes$/, function (done: Callback) {
done();
});

Given(/^.*step (?:.*) fails with generic error$/, function (done: Callback) {
done(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function (done: Callback) {
done(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function (done: Callback) {
done(void 0, 'pending');
});

Given(/^.*step (?:.*) receives a table:$/, function (data: TableDefinition, done) {
done();
});

Given(/^.*step (?:.*) receives a doc string:$/, function (docstring: string, done) {
done();
});

Given(/^.*step that times out$/, { timeout: 100 }, function (done: Callback) {
setTimeout(done, 1000);
});
@@ -0,0 +1,32 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

Given(/^.*step (?:.*) passes$/, function () {
return Promise.resolve();
});

Given(/^.*step (?:.*) fails with generic error$/, function () {
return Promise.reject(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function () {
return Promise.reject(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function () {
return Promise.resolve('pending');
});

Given(/^.*step (?:.*) receives a table:$/, function (data: TableDefinition) {
return Promise.resolve();
});

Given(/^.*step (?:.*) receives a doc string:$/, function (docstring: string) {
return Promise.resolve();
});

Given(/^.*step that times out$/, { timeout: 100 }, function () {
return new Promise((resolve, reject) => {
setTimeout(resolve, 1000);
});
});
@@ -0,0 +1,35 @@
import { Interaction, WithStage } from '@serenity-js/core';
import { After, Before, Then, When } from 'cucumber';

const
MakeAnArrow = () => Interaction.where(`#actor makes an arrow`, actor => void 0),
Nock = () => Interaction.where(`#actor fits an arrow to the bowstring`, actor => void 0),
Draw = () => Interaction.where(`#actor draws the bow`, actor => void 0),
Loose = () => Interaction.where(`#actor releases the bowstring`, actor => void 0),
RetrieveArrow = () => Interaction.where(`#actor retrieves the arrow from the target`, actor => void 0);

Before(function (this: WithStage) {
return this.stage.theActorCalled('Lara').attemptsTo(
MakeAnArrow(),
);
});

When(/^(.*) shoots an arrow$/, function (this: WithStage, actorName: string) {
return this.stage.theActorCalled(actorName).attemptsTo(
Nock(),
Draw(),
Loose(),
);
});

Then(/^she should hit a target$/, function (this: WithStage) {
return this.stage.theActorInTheSpotlight().attemptsTo(
// some assertion
);
});

After(function () {
return this.stage.theActorCalled('Lara').attemptsTo(
RetrieveArrow(),
);
});
@@ -0,0 +1,26 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

Given(/^.*step (?:.*) passes$/, function () {
return void 0;
});

Given(/^.*step (?:.*) fails with generic error$/, function () {
throw new Error(`Something's wrong`);
});

Given(/^.*step (?:.*) fails with assertion error$/, function () {
throw new AssertionError(`Expected false to equal true`, false, true);
});

Given(/^.*step (?:.*) marked as pending/, function () {
return 'pending';
});

Given(/^.*step (?:.*) receives a table:$/, function (data: TableDefinition) {
return void 0;
});

Given(/^.*step (?:.*) receives a doc string:$/, function (docstring: string) {
return void 0;
});
@@ -0,0 +1,7 @@
import { Actor, DressingRoom } from '@serenity-js/core';

export class Actors implements DressingRoom {
prepare(actor: Actor): Actor {
return actor; // no-op actors with no special abilities
}
}
@@ -0,0 +1,5 @@
import { After } from 'cucumber';

After(function () {
// no-op
});
@@ -0,0 +1,5 @@
import { Before } from 'cucumber';

Before(function () {
// no-op
});
@@ -0,0 +1,15 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity, StreamReporter, WithStage } from '@serenity-js/core';
import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './Actors';

setDefaultTimeout(5000);

serenity.setTheStage(
new ChildProcessReporter(),
new StreamReporter(),
);

setWorldConstructor(function (this: WithStage) {
this.stage = serenity.callToStageFor(new Actors());
});
@@ -0,0 +1,5 @@
import { Before } from 'cucumber';

Before({ tags: '@wip' }, function () {
return 'pending';
});
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig",
"include": [
"src/**/*.ts",
"spec/**/*.ts",
"features/**/*.ts"
],
"exclude": [
"node_modules"
]
}
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": [ "es5", "es6" ],
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true,
"outDir": "./lib"
},

"include": [
"src"
],

"exclude": [
"node_modules"
]
}
@@ -35,6 +35,7 @@
"@integration/cucumber-3-runner": "2.0.1-alpha.84",
"@integration/cucumber-4-runner": "2.0.1-alpha.84",
"@integration/cucumber-5-runner": "2.0.1-alpha.84",
"@integration/cucumber-6-runner": "2.0.1-alpha.84",
"@integration/testing-tools": "2.0.1-alpha.84",
"@serenity-js/core": "2.0.1-alpha.84",
"@serenity-js/cucumber": "2.0.1-alpha.84"
@@ -26,7 +26,7 @@ describe('@serenity-js/cucumber', function () {
.withStepDefsIn('ambiguous')
.toRun('features/passing_scenario.feature'),

...cucumberVersions(3, 4, 5)
...cucumberVersions(3, 4, 5, 6)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('ambiguous')
.withArgs(
@@ -27,7 +27,7 @@ describe('@serenity-js/cucumber', function () {
.withStepDefsIn('promise', 'callback', 'synchronous')
.toRun('features/assertion_failure_scenario.feature'),

...cucumberVersions(3, 4, 5)
...cucumberVersions(3, 4, 5, 6)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(

0 comments on commit b437edd

Please sign in to comment.