Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(cucumber): support for Cucumber 5.x
affects: @serenity-js/cucumber, @integration/cucumber-1-runner, @integration/cucumber-2-runner,
@integration/cucumber-3-runner, @integration/cucumber-4-runner, @integration/cucumber-5-runner,
@integration/cucumber, @integration/testing-tools,
@serenity-js-examples/cucumber-domain-level-testing, @serenity-js-examples/cucumber-reporting

ISSUES CLOSED: Closes #28
  • Loading branch information
jan-molak committed Sep 14, 2018
1 parent ac7f446 commit c3bd443
Show file tree
Hide file tree
Showing 36 changed files with 244 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/cucumber-domain-level-testing/package.json
Expand Up @@ -40,7 +40,7 @@
"@serenity-js/cucumber": "*",
"@serenity-js-examples/calculator-app": "*",
"@types/cucumber": "4.0.4",
"cucumber": "4.2.1",
"cucumber": "5.0.0",
"npm-failsafe": "0.4.1",
"serenity-cli": "0.11.0",
"ts-node": "7.0.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/cucumber-reporting/package.json
Expand Up @@ -39,7 +39,7 @@
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*",
"@types/cucumber": "4.0.4",
"cucumber": "4.2.1",
"cucumber": "5.0.0",
"npm-failsafe": "0.4.1",
"serenity-cli": "0.11.0",
"ts-node": "7.0.1"
Expand Down
4 changes: 1 addition & 3 deletions integration/cucumber-1-runner/package.json
Expand Up @@ -36,9 +36,7 @@
"@integration/testing-tools": "*",
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*",
"cucumber": "1.3.3",
"metalsmith-sass": "^1.5.1",
"metalsmith-uglify": "^2.3.0"
"cucumber": "1.3.3"
},
"devDependencies": {
"@types/cucumber": "1.3.3"
Expand Down
4 changes: 1 addition & 3 deletions integration/cucumber-2-runner/package.json
Expand Up @@ -36,9 +36,7 @@
"@integration/testing-tools": "*",
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*",
"cucumber": "2.3.1",
"metalsmith-sass": "^1.5.1",
"metalsmith-uglify": "^2.3.0"
"cucumber": "2.3.1"
},
"devDependencies": {
"@types/cucumber": "2.1.0"
Expand Down
4 changes: 1 addition & 3 deletions integration/cucumber-3-runner/package.json
Expand Up @@ -36,9 +36,7 @@
"@integration/testing-tools": "*",
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*",
"cucumber": "3.2.1",
"metalsmith-sass": "^1.5.1",
"metalsmith-uglify": "^2.3.0"
"cucumber": "3.2.1"
},
"devDependencies": {
"@types/cucumber": "3.2.2"
Expand Down
4 changes: 1 addition & 3 deletions integration/cucumber-4-runner/package.json
Expand Up @@ -36,9 +36,7 @@
"@integration/testing-tools": "*",
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*",
"cucumber": "4.2.1",
"metalsmith-sass": "^1.5.1",
"metalsmith-uglify": "^2.3.0"
"cucumber": "4.2.1"
},
"devDependencies": {
"@types/cucumber": "4.0.4"
Expand Down
7 changes: 7 additions & 0 deletions integration/cucumber-5-runner/.gitignore
@@ -0,0 +1,7 @@
# Node
node_modules
*.log

# Build artifacts
.nyc_output
lib
8 changes: 8 additions & 0 deletions integration/cucumber-5-runner/README.md
@@ -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)
44 changes: 44 additions & 0 deletions integration/cucumber-5-runner/package.json
@@ -0,0 +1,44 @@
{
"name": "@integration/cucumber-5-runner",
"version": "0.0.0",
"description": "Cucumber JS 5.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": ">= 6.9.x",
"npm": ">= 3"
},
"dependencies": {
"@integration/testing-tools": "*",
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*",
"cucumber": "5.0.0"
},
"devDependencies": {
"@types/cucumber": "4.0.4"
}
}
18 changes: 18 additions & 0 deletions integration/cucumber-5-runner/src/index.ts
@@ -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,27 @@
import { Given, TableDefinition } from 'cucumber';

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

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

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

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,27 @@
import { Given, TableDefinition } from 'cucumber';

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

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

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,21 @@
import { Given, TableDefinition } from 'cucumber';

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

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

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;
});
5 changes: 5 additions & 0 deletions integration/cucumber-5-runner/src/support/after_hook.ts
@@ -0,0 +1,5 @@
import { After } from 'cucumber';

After(function() {
// no-op
});
5 changes: 5 additions & 0 deletions integration/cucumber-5-runner/src/support/before_hook.ts
@@ -0,0 +1,5 @@
import { Before } from 'cucumber';

Before(function() {
// no-op
});
11 changes: 11 additions & 0 deletions integration/cucumber-5-runner/src/support/configure_serenity.ts
@@ -0,0 +1,11 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity } from '@serenity-js/core';
import { DebugReporter } from '@serenity-js/core/lib/stage';
import { setDefaultTimeout } from 'cucumber';

setDefaultTimeout(5000);

serenity.stageManager.register(
new ChildProcessReporter(),
new DebugReporter(),
);
5 changes: 5 additions & 0 deletions integration/cucumber-5-runner/src/support/wip_hook.ts
@@ -0,0 +1,5 @@
import { Before } from 'cucumber';

Before({ tags: '@wip' }, function() {
return 'pending';
});
11 changes: 11 additions & 0 deletions integration/cucumber-5-runner/tsconfig-lint.json
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig",
"include": [
"src/**/*.ts",
"spec/**/*.ts",
"features/**/*.ts"
],
"exclude": [
"node_modules"
]
}
20 changes: 20 additions & 0 deletions integration/cucumber-5-runner/tsconfig.json
@@ -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"
]
}
5 changes: 2 additions & 3 deletions integration/cucumber/package.json
Expand Up @@ -35,10 +35,9 @@
"@integration/cucumber-2-runner": "*",
"@integration/cucumber-3-runner": "*",
"@integration/cucumber-4-runner": "*",
"@integration/cucumber-5-runner": "*",
"@integration/testing-tools": "*",
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*",
"metalsmith-sass": "^1.5.1",
"metalsmith-uglify": "^2.3.0"
"@serenity-js/cucumber": "*"
}
}
2 changes: 1 addition & 1 deletion integration/cucumber/spec/ambiguous_steps.spec.ts
Expand Up @@ -26,7 +26,7 @@ describe('@serenity-js/cucumber', function() {
.withStepDefsIn('ambiguous')
.toRun('features/passing_scenario.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('ambiguous')
.withArgs(
Expand Down
2 changes: 1 addition & 1 deletion integration/cucumber/spec/capabilities.spec.ts
Expand Up @@ -19,7 +19,7 @@ describe('@serenity-js/cucumber', function() {
.withStepDefsIn('promise', 'callback', 'synchronous')
.toRun('features/example_capability/example.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down
2 changes: 1 addition & 1 deletion integration/cucumber/spec/data_table.spec.ts
Expand Up @@ -19,7 +19,7 @@ describe('@serenity-js/cucumber', function() {
.withStepDefsIn('promise', 'callback', 'synchronous')
.toRun('features/data_table.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down
2 changes: 1 addition & 1 deletion integration/cucumber/spec/descriptions.spec.ts
Expand Up @@ -19,7 +19,7 @@ describe('@serenity-js/cucumber', function() {
.withStepDefsIn('promise', 'callback', 'synchronous')
.toRun('features/descriptions.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down
2 changes: 1 addition & 1 deletion integration/cucumber/spec/doc_string.spec.ts
Expand Up @@ -19,7 +19,7 @@ describe('@serenity-js/cucumber', function() {
.withStepDefsIn('promise', 'callback', 'synchronous')
.toRun('features/doc_strings.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down
2 changes: 1 addition & 1 deletion integration/cucumber/spec/failing_scenario.spec.ts
Expand Up @@ -26,7 +26,7 @@ describe('@serenity-js/cucumber', function() {
.withStepDefsIn('promise', 'callback', 'synchronous')
.toRun('features/failing_scenario.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down
2 changes: 1 addition & 1 deletion integration/cucumber/spec/passing_scenario.spec.ts
Expand Up @@ -26,7 +26,7 @@ describe('@serenity-js/cucumber', function() {
.withStepDefsIn('synchronous', 'promise', 'callback')
.toRun('features/passing_scenario.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down
6 changes: 3 additions & 3 deletions integration/cucumber/spec/pending_scenarios.spec.ts
Expand Up @@ -37,7 +37,7 @@ describe('@serenity-js/cucumber', function() {
.withArgs('--name', 'A scenario with steps marked as pending', '--no-strict')
.toRun('features/pending_scenarios.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('@serenity-js/cucumber', function() {
.withArgs('--name', 'A scenario with steps that have not been implemented yet', '--no-strict')
.toRun('features/pending_scenarios.feature'),

...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('@serenity-js/cucumber', function() {
}));

given([
...cucumberVersions(3, 4)
...cucumberVersions(3, 4, 5)
.thatRequires(
'lib/support/configure_serenity.js',
'lib/support/wip_hook.js',
Expand Down

0 comments on commit c3bd443

Please sign in to comment.