Skip to content

Commit

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

ISSUES CLOSED: #28
  • Loading branch information
jan-molak committed Aug 29, 2018
1 parent b4932b9 commit 330d731
Show file tree
Hide file tree
Showing 33 changed files with 395 additions and 147 deletions.
@@ -1,6 +1,6 @@
import { TableDefinition } from 'cucumber';

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

export = function() {
this.Given(/^.*step (?:.*) passes$/, function(done: Callback) {
Expand Down
@@ -1,6 +1,6 @@
import { defineSupportCode, TableDefinition } from 'cucumber';

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

defineSupportCode(({ Given }) => {

Expand Down
@@ -1,6 +1,6 @@
import { defineSupportCode, TableDefinition } from 'cucumber';

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

defineSupportCode(({ Given }) => {

Expand Down
7 changes: 7 additions & 0 deletions integration/cucumber-4-runner/.gitignore
@@ -0,0 +1,7 @@
# Node
node_modules
*.log

# Build artifacts
.nyc_output
lib
8 changes: 8 additions & 0 deletions integration/cucumber-4-runner/README.md
@@ -0,0 +1,8 @@
# Cucumber 3.x runner

This is an internal test module that embeds Cucumber 3.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/v3.2.1/docs/support_files/step_definitions.md)
- [Sample event protocol events](https://github.com/cucumber/cucumber-js/blob/v3.2.1/src/formatter/event_protocol_formatter.js)
44 changes: 44 additions & 0 deletions integration/cucumber-4-runner/package.json
@@ -0,0 +1,44 @@
{
"name": "@integration/cucumber-4-runner",
"version": "0.0.0",
"description": "Cucumber JS 4.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": "4.2.1"
},
"devDependencies": {
"@types/cucumber": "4.0.4"
}
}
18 changes: 18 additions & 0 deletions integration/cucumber-4-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-4-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-4-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-4-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-4-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-4-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-4-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"
]
}
1 change: 1 addition & 0 deletions integration/cucumber/package.json
Expand Up @@ -35,6 +35,7 @@
"@integration/cucumber-1-runner": "*",
"@integration/cucumber-2-runner": "*",
"@integration/cucumber-3-runner": "*",
"@integration/cucumber-4-runner": "*",
"@serenity-js/core": "*",
"@serenity-js/cucumber": "*"
}
Expand Down
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)
...cucumberVersions(3, 4)
.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)
...cucumberVersions(3, 4)
.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)
...cucumberVersions(3, 4)
.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)
...cucumberVersions(3, 4)
.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)
...cucumberVersions(3, 4)
.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)
...cucumberVersions(3, 4)
.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)
...cucumberVersions(3, 4)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down
9 changes: 5 additions & 4 deletions integration/cucumber/spec/pending_scenarios.spec.ts
Expand Up @@ -37,12 +37,13 @@ describe('@serenity-js/cucumber', function() {
.withArgs('--name', 'A scenario with steps marked as pending', '--no-strict')
.toRun('features/pending_scenarios.feature'),

...cucumberVersions(3)
...cucumberVersions(3, 4)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
'--format', 'node_modules/@serenity-js/cucumber',
'--name', 'A scenario with steps marked as pending', '--no-strict',
'--name', 'A scenario with steps marked as pending',
'--no-strict',
)
.toRun('features/pending_scenarios.feature'),
]).
Expand Down Expand Up @@ -80,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)
...cucumberVersions(3, 4)
.thatRequires('lib/support/configure_serenity.js')
.withStepDefsIn('synchronous', 'promise', 'callback')
.withArgs(
Expand Down Expand Up @@ -146,7 +147,7 @@ describe('@serenity-js/cucumber', function() {
}));

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

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

0 comments on commit 330d731

Please sign in to comment.