Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/supporting cucumber cli options #2978

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/cucumber-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ $ npm i @cucumber/cucumber --save-dev
}
```

## CLI Options
gravityvi marked this conversation as resolved.
Show resolved Hide resolved
| option | description |
|------------------------|------------------------------|
| --dry-run | Do all the aggregation work of looking at your feature files, loading your support code etc but without actually executing the tests. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/dry_run.md)
| --name | Specify a scenario by its name matching a regular expression. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#running-specific-features)
| --tags | Use tags to run specific scenario or features. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#tags)
| --require | Use `--require <GLOB OR DIR OR FILE>` to explicitly require support files before executing the features. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#requiring-support-files)
| --format | Use `--format <TYPE[:PATH]>` to specify the format of the output. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#formats)
| --format-options | Many formatters, including the built-in ones, support some configurability via options. You can provide this data as a JSON literal via the --format-options CLI option. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md#options)
| --fail-fast | Abort the run on first failure (default: false). [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#--fail-fast)
| --retries | Use `--retries <NUMBER-OF-ATTEMPT>` to have Cucumber attempt it multiple times until either it passes or the maximum number of attempts is reached. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md#retry)
| --retry-tag-filter | Use `--retry-tag-filter` to retry failed scenarios based on tags. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md#targeting-scenarios)
| --require-module | [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#transpilation)
| --no-strict | By default, cucumber runner works in strict mode, meaning it will fail if there are pending steps.
| --parallel | Use `--parallel <NUMBER-OF-WORKER-THREADS>` to run your scenarios in parallel. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md#parallel)
| --profile | As of now only `cucumber.js` is considered while picking up profiles. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/profiles.md)
| --world-parameters | Provide this data as a JSON literal via the `--world-parameters`. [read more](https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md#world-parameters)


## Running
Cucumber spec files/step definition files can be provided in `src_folders` in Nightwatch config or as a CLI argument.

Expand Down
30 changes: 28 additions & 2 deletions lib/runner/test-runners/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CucumberSuite extends TestSuite {
const initialRequires = [
'--require', cucumberSetupFile
];

const profiles = [];
let extraRequires = this.argv.require;
if (extraRequires) {
if (isString(extraRequires)) {
Expand All @@ -101,6 +101,26 @@ class CucumberSuite extends TestSuite {
});
}

let requiredModules = this.argv['require-module'];
if (requiredModules) {
if (isString(requiredModules)) {
requiredModules = [requiredModules];
}
requiredModules.forEach((module)=>{
initialRequires.push('--require-module', module);
});
}
gravityvi marked this conversation as resolved.
Show resolved Hide resolved

let profileOption = this.argv.profile;
if (profileOption) {
if (isString(profileOption)) {
profileOption = [profileOption];
}
profileOption.forEach((profile)=>{
profiles.push('--profile', profile);
});
}

const specs = this.allModulePaths.reduce((prev, spec) => {
prev.push('--require', spec);

Expand All @@ -115,6 +135,7 @@ class CucumberSuite extends TestSuite {
const {feature_path} = options;
const parallelArgs = this.usingCucumberWorkers ? ['--parallel', this.usingCucumberWorkers]: [];
const tagsOption = this.argv.tags ? ['--tags', this.argv.tags] : [];
const retryTagsOption = this.argv['retry-tag-filter'] ? ['--retry-tag-filter', this.argv['retry-tag-filter']] : [];
const extraParams = ['--world-parameters', JSON.stringify(this.argv)];
let formatArg = this.argv.format || [];
if (!Array.isArray(formatArg)) {
Expand All @@ -127,11 +148,16 @@ class CucumberSuite extends TestSuite {
}, []);

const formatOptions = this.argv['format-options'] ? ['--format-options', this.argv['format-options']] : [];
const dryRun = this.argv['dry-run'] ? ['--dry-run'] : [];
const failFast = this.argv['fail-fast'] ? ['--fail-fast'] : [];
const retryOption = this.argv['retries'] ? ['--retry', Number(this.argv['retries'])] : [];
const noStrict = this.argv['no-strict'] ? ['--no-strict'] : [];
const featureNameFilter = this.argv['name'] ? ['--name', this.argv['name']] : [];
gravityvi marked this conversation as resolved.
Show resolved Hide resolved

return [
process.execPath,
require.resolve('@cucumber/cucumber')
].concat(feature_path, parallelArgs, specs, tagsOption, formatArg, formatOptions, extraParams);
].concat(feature_path, parallelArgs, specs, tagsOption, formatArg, formatOptions, extraParams, dryRun, failFast, retryOption, profiles, noStrict, featureNameFilter, retryTagsOption);
}

onTestSuiteFinished(result) {
Expand Down
75 changes: 75 additions & 0 deletions test/src/runner/cucumber-integration/testCliArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const assert = require('assert');
const path = require('path');
const mockery = require('mockery');
const common = require('../../../common.js');
const CucumberRunner = common.require('runner/test-runners/cucumber.js');




gravityvi marked this conversation as resolved.
Show resolved Hide resolved
describe('Cucumber cli arguements', function(){
let cliArgs;

this.beforeAll(function(){
mockery.enable();
mockery.registerMock('@cucumber/cucumber/lib/cli/index',
{
default: class CucumberCli {
constructor({
argv, cwd, stdout
}){
cliArgs =argv;
}
}

});
});

this.afterAll(function(){
mockery.deregisterAll();
mockery.disable();
});

it('Cucumber cli args --require-modules', function(){
const runner = new CucumberRunner({test_runner: {
type: 'cucumber',
options: {}
}}, {'require-module': ['coffeescript/register', 'ts-node/register']});
runner.createTestSuite({modules: [path.join(__dirname, '../../../cucumbertests/testSample.js')], modulePath: [path.join(__dirname, '../../../cucumbertests/testSample.js')]});
assert.ok(cliArgs.includes('--require-module'));
let index = cliArgs.indexOf('--require-module')+1;
assert.strictEqual(cliArgs[index], 'coffeescript/register');
index = cliArgs.indexOf('--require-module', index)+1;
assert.strictEqual(cliArgs[index], 'ts-node/register');
});

it('Cucumber cli args', function(){
const runner = new CucumberRunner({test_runner: {
type: 'cucumber',
options: {}
}}, {'no-strict': true, retries: 2, profile: 'local', 'fail-fast': true, parallel: 3, name: 'sample', 'retry-tag-filter': '@nightwatch'}, {});
runner.createTestSuite({modules: [path.join(__dirname, '../../../cucumbertests/testSample.js')], modulePath: [path.join(__dirname, '../../../cucumbertests/testSample.js')]});
assert.ok(cliArgs.includes('--name'));
assert.strictEqual(cliArgs[cliArgs.indexOf('--name')+1], 'sample');
assert.ok(cliArgs.includes('--fail-fast'));
assert.ok(cliArgs.includes('--retry'));
assert.strictEqual(cliArgs[cliArgs.indexOf('--retry')+1], 2);
assert.ok(cliArgs.includes('--retry-tag-filter'));
assert.strictEqual(cliArgs[cliArgs.indexOf('--retry-tag-filter')+1], '@nightwatch');
assert.ok(cliArgs.includes('--profile'));
assert.strictEqual(cliArgs[cliArgs.indexOf('--profile')+1], 'local');
assert.ok(cliArgs.includes('--no-strict'));
assert.ok(cliArgs.includes('--parallel'));
assert.strictEqual(cliArgs[cliArgs.indexOf('--parallel')+1], 3);
});

it('Cucumber cli arg --dry-run', function(){
const runner = new CucumberRunner({test_runner: {
type: 'cucumber',
options: {}
}}, {'dry-run': true}, {});
runner.createTestSuite({modules: [path.join(__dirname, '../../../cucumbertests/testSample.js')], modulePath: [path.join(__dirname, '../../../cucumbertests/testSample.js')]});
assert.ok(cliArgs.includes('--dry-run'));
});

});