-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
config: support configuration as objects #1952
Merged
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
dee627a
add testing for esm format
davidjgoss 1c533e8
handle both types somewhat awkwardly
davidjgoss ad9d6f0
convert to file url (will be needed for windows)
davidjgoss d265ffd
Merge branch 'main' into feat/config-import
davidjgoss 010a37f
fix catch clause
davidjgoss 03df338
move some types around
davidjgoss a2d9311
more moving
davidjgoss 764f301
start to build out configuration module
davidjgoss d1f8951
whoops dont need this one
davidjgoss a7874f8
add default config
davidjgoss e0bd615
add todo comment
davidjgoss 59256cf
wip fromFile
davidjgoss c416579
merge main
davidjgoss a7459f6
make a start on file loading
davidjgoss 030bbf1
progress on profiles and merging
davidjgoss 3caeb64
add lodash.mergewith
davidjgoss 3916a65
WIP remove validation from argv parser
davidjgoss c91efda
expand this test a bit
davidjgoss 7ef8db6
a note about strings for later
davidjgoss 8226f34
moar test
davidjgoss 5c5f3c3
more on merge
davidjgoss d519534
start to rework parser
davidjgoss 799f760
remove defaults, fix array merging
davidjgoss e4aa809
simplify
davidjgoss 9a5878d
handle mergeable tag strings
davidjgoss 4a62e10
merge json nicely
davidjgoss c6cbf6f
progress
davidjgoss 17819ca
change profile feature to sometimes use objects
davidjgoss a308cff
last argument wins when specifying stdout formatter
davidjgoss 802fe45
Merge branch 'main' into feat/config-import
davidjgoss 4b10c42
use new config loading mechanism with object support
davidjgoss 288edf8
ensure all array types are merged correctly
davidjgoss 000a069
rename
davidjgoss ae708e5
handle tag expressions correctly when merging
davidjgoss 10fe985
add validation for retry config
davidjgoss 5a8e961
validate config objects against schema, handle default profile correctly
davidjgoss af54d05
update message on retry config validation
davidjgoss aea3511
move and simplify some types
davidjgoss 0c681fc
more moving and renaming
davidjgoss d9d47e1
rework - less defaulting
davidjgoss 16d6fa0
dogfood loadConfiguration in tests
davidjgoss 000069d
dogfood loadConfiguration in cli, shrink api surface
davidjgoss e5ccce9
add -i shorthand for --import
davidjgoss 4e14290
support json config file
davidjgoss 0fc765f
fix pickle order typing
davidjgoss 3a7970b
overhaul documentation
davidjgoss ad6ea28
change our own config to json
davidjgoss befcd9c
simplify config handing in cli
davidjgoss 27e3c41
simplify typing
davidjgoss 5b87d8e
add changelog entry
davidjgoss ae77a17
fix typo
davidjgoss 26d6289
whoops
davidjgoss 1aeb7ef
add --force-exit alias for --exit, rename property on object
davidjgoss 397cc9d
single source of `isTruthyString`
davidjgoss 73c5fa4
correct wrong format name
davidjgoss 1a3cbd3
remove pointless reindent
davidjgoss 280d694
add tests for other formats in from_file_spec.ts
davidjgoss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"default": { | ||
"requireModule": [ | ||
"ts-node/register" | ||
], | ||
"require": [ | ||
"features/**/*.ts" | ||
], | ||
"format": [ | ||
"progress-bar", | ||
"rerun:@rerun.txt", | ||
"usage:reports/usage.txt", | ||
"message:reports/messages.ndjson", | ||
"html:reports/html-formatter.html" | ||
], | ||
"retry": 2, | ||
"retryTagFilter": "@flaky", | ||
"publishQuiet": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,178 +1,59 @@ | ||
# CLI | ||
|
||
Cucumber.js includes an executable file to run the features. After installing Cucumber in your project, you can run it with: | ||
Cucumber includes an executable file to run your scenarios. After installing the `@cucumber/cucumber` package, you can run it directly: | ||
|
||
``` shell | ||
$ ./node_modules/.bin/cucumber-js | ||
``` | ||
|
||
**Note on global installs:** Cucumber does not work when installed globally because cucumber | ||
needs to be required in your support files and globally installed modules cannot be required. | ||
|
||
## Running specific features | ||
|
||
* Specify a [glob](https://github.com/isaacs/node-glob) pattern | ||
* `$ cucumber-js features/**/*.feature` | ||
* Specify a feature directory | ||
* `$ cucumber-js features/dir` | ||
* Specify a feature file | ||
* `$ cucumber-js features/my_feature.feature` | ||
* Specify a scenario by its line number | ||
* `$ cucumber-js features/my_feature.feature:3` | ||
* Specify a scenario by its name matching a regular expression | ||
* `$ cucumber-js --name "topic 1"` | ||
* `$ cucumber-js --name "^start.+end$"` | ||
* If used multiple times, the scenario name needs to match only one of the names supplied | ||
* To escape special regex characters in scenario name, use backslash e.g., `\(Scenario Name\)` | ||
* Use [Tags](#tags) | ||
|
||
## Loading support files | ||
|
||
By default, the following files are loaded: | ||
* If the features live in a `features` directory (at any level) | ||
* `features/**/*.(js|mjs)` | ||
* Otherwise | ||
* `<DIR>/**/*.(js|mjs)` for each directory containing the selected features | ||
Or via a [`package.json` script](https://docs.npmjs.com/cli/v8/using-npm/scripts): | ||
|
||
With the defaults described above, `.js` files are loaded via `require()`, whereas `.mjs` files are loaded via `import()`. | ||
|
||
Alternatively, you can use either or both of these options to explicitly load support files before executing the features: | ||
```json | ||
{ | ||
"scripts": { | ||
"cucumber": "cucumber-js" | ||
} | ||
} | ||
``` | ||
|
||
- `--require <GLOB|DIR|FILE>` - loads via `require()` (legacy) | ||
- `--import <GLOB|DIR|FILE>` - loads via `import()` | ||
Or via [npx](https://docs.npmjs.com/cli/v8/commands/npx): | ||
|
||
Both options use [glob](https://github.com/isaacs/node-glob) patterns and may be used multiple times in order to e.g. load files from several different locations. | ||
``` shell | ||
$ npx cucumber-js | ||
``` | ||
|
||
_Note that once you specify any `--require` or `--import` options, the defaults described above are no longer applied._ | ||
**Note on global installs:** Cucumber does not work when installed globally because `@cucumber/cucumber` | ||
needs to be required in your support files and globally installed modules cannot be required. | ||
|
||
## Formats | ||
## Options | ||
|
||
Use `--format <TYPE[:PATH]>` to specify the format of the output. | ||
All the [standard configuration options](./configuration.md#options) can be provided via the CLI. | ||
|
||
See [Formatters](./formatters.md). | ||
Additionally, there are a few options that are specific to the CLI: | ||
|
||
### Officially-supported standalone formatters | ||
| Option | Type | Repeatable | Description | | ||
|--------------------|------------|------------|-----------------------------------------------------------------------------------------| | ||
| `--config`, `-c` | `string` | No | Path to your configuration file - see [Files](./configuration.md#files) | | ||
| `--profile`, `-p` | `string[]` | Yes | Profiles from which to include configuration - see [Profiles](./profiles.md) | | ||
| `--version`, `-v` | `boolean` | No | Print the currently installed version of Cucumber, then exit immediately | | ||
| `--i18n-keywords` | `string` | No | Print the Gherkin keywords for the given ISO-639-1 language code, then exit immediately | | ||
| `--i18n-languages` | `boolean` | No | Print the supported languages for Gherkin, then exit immediately | | ||
|
||
* [@cucumber/pretty-formatter](https://www.npmjs.com/package/@cucumber/pretty-formatter) - prints the feature with inline results, colours and custom themes. | ||
To see the available options for your installed version, run: | ||
|
||
### Format Options | ||
```shell | ||
$ cucumber-js --help | ||
``` | ||
|
||
You can pass in format options with `--format-options <JSON>`. | ||
## Exiting | ||
|
||
See [Formatters](./formatters.md). | ||
By default, cucumber exits when the event loop drains. Use the `forceExit` configuration option in order to force shutdown of the event loop when the test run has finished: | ||
|
||
## Exiting | ||
- In a configuration file `{ forceExit: true }` | ||
- On the CLI `$ cucumber-js --force-exit` | ||
|
||
By default, cucumber exits when the event loop drains. Use the `--exit` flag in order to force shutdown of the event loop when the test run has finished. This is discouraged, as fixing the issues that causes the hang is a better long term solution. Some potential resources for that are: | ||
This is discouraged, as fixing the issues that causes the hang is a better long term solution. Some potential resources for that are: | ||
* [Node.js guide to debugging](https://nodejs.org/en/docs/inspector/) | ||
* NPM package [why-is-node-running](https://www.npmjs.com/package/why-is-node-running) | ||
* [Node.js Async Hooks](https://nodejs.org/dist/latest-v8.x/docs/api/async_hooks.html) | ||
* Isolating what scenario or scenarios causes the hang | ||
|
||
## --no-strict | ||
|
||
disable _strict_ mode. | ||
|
||
By default, cucumber works in _strict_ mode, meaning it will fail if there are pending steps. | ||
|
||
## Parallel | ||
|
||
See [Parallel](./parallel.md). | ||
|
||
## Printing Attachments Details | ||
|
||
Printing attachments details can be disabled with | ||
`--fomat-options '{"printAttachments": false}'`. | ||
|
||
This option applies to the progress formatter and the summary formatter. | ||
|
||
## Profiles | ||
|
||
See [Profiles](./profiles.md). | ||
|
||
## Tags | ||
|
||
Use `--tags <EXPRESSION>` to run specific features or scenarios. This option is repeatable and the expressions will be merged with an `and` operator. | ||
`<EXPRESSION>` is a [cucumber tag expression](https://docs.cucumber.io/cucumber/api/#tag-expressions). | ||
|
||
## --fail-fast | ||
|
||
abort the run on first failure (default: false) | ||
|
||
By default, cucumber-js runs the entire suite and reports all the failures. This flag allows a developer workflow where you work on one failure at a time. Combining this feature with rerun files allows you to work through all failures in an efficient manner. | ||
|
||
A note on using in conjunction with `--retry`: we consider a test case to have failed if it exhausts retries and still fails, but passed if it passes on a retry having failed previous attempts, so `--fail-fast` does still allow retries to happen. | ||
|
||
## Retry failing tests | ||
|
||
See [Retry](./retry.md) | ||
|
||
## Transpilation | ||
|
||
Step definitions and support files can be written in other languages that transpile to JavaScript. | ||
|
||
### Simple ES6 support | ||
|
||
For instance, for ES6 support with [Babel](https://babeljs.io/) 7 add: | ||
|
||
``` | ||
--require-module @babel/register | ||
``` | ||
|
||
This will effectively call `require('@babel/register')` prior to requiring any support files. | ||
|
||
If your files end with an extension other than `js`, make sure to also include the `--require` option to state the required support files. For example, if using [CoffeeScript](https://www.npmjs.com/package/coffeescript): | ||
|
||
``` | ||
--require-module coffeescript/register --require 'features/**/*.coffee' | ||
``` | ||
|
||
### TypeScript | ||
|
||
Your `tsconfig.json` should have the `resolveJsonModule` compiler option switched on. Other than that, a pretty standard TypeScript setup should work as expected. | ||
|
||
#### With ts-node | ||
|
||
If you are using [ts-node](https://github.com/TypeStrong/ts-node): | ||
|
||
``` | ||
--require-module ts-node/register --require 'step-definitions/**/*.ts' | ||
``` | ||
|
||
> ⚠️ Some TypeScript setups use `esnext` modules by default, | ||
> which doesn't marry well with Node. You may consider using commonjs instead. | ||
> See how to add [extra configuration](#extra-configuration) below. | ||
|
||
#### With babel | ||
|
||
If you are using babel with [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript): | ||
|
||
``` | ||
--require-module @babel/register --require 'step-definitions/**/*.ts' | ||
``` | ||
|
||
### Extra Configuration | ||
|
||
Sometimes the required module (say `@ts-node/register`) needs extra configuration. For example, you might want to configure it such that it prevents the compiled JS being written out to files, and pass some compiler options. In such cases, create a script (say, `tests.setup.js`): | ||
|
||
```js | ||
require('ts-node').register({ | ||
transpileOnly: true, | ||
compilerOptions: { | ||
"module": "commonjs", | ||
"resolveJsonModule": true, | ||
}, | ||
}); | ||
``` | ||
|
||
And then require it using the `--require` option: | ||
|
||
``` | ||
--require tests.setup.js --require 'features/**/*.ts' | ||
``` | ||
|
||
Note that the first `--require tests.setup.js` overrides the default require glob, so we'll need to `--require` our support code explicitly too. | ||
|
||
## World Parameters | ||
|
||
See [World](./support_files/world.md). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good example of what configuration can look like now.