-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor documentation (part 1) (#1699)
* add export of cli --help * dont need note about sync * update world docs * document retry * document profiles * start to trim stuff from cli * more on profiles * document parallel * add linsk to readmr
- Loading branch information
1 parent
6e60589
commit 6b09896
Showing
6 changed files
with
136 additions
and
40 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Parallel | ||
|
||
Cucumber supports running scenarios in parallel. The main process becomes a "coordinator" and spins up several separate Node processes to be the "workers". You can enable this with the `--parallel <NUMBER_OF_WORKERS>` CLI option: | ||
|
||
```shell | ||
$ cucumber-js --parallel 3 | ||
``` | ||
|
||
The number you provide is the number of workers that will run scenarios in parallel. | ||
|
||
Each worker receives the following env variables (as well as a copy of `process.env` from the coordinator process): | ||
|
||
* `CUCUMBER_PARALLEL` - set to 'true' | ||
* `CUCUMBER_TOTAL_WORKERS` - set to the number of workers | ||
* `CUCUMBER_WORKER_ID` - ID for worker ('0', '1', '2', etc.) | ||
|
||
### Timing | ||
|
||
When using parallel mode, the last line of the summary output differentiates between real time elapsed during the test run and aggregate time spent actually running steps: | ||
|
||
``` | ||
73 scenarios (73 passed) | ||
512 steps (512 passed) | ||
0m51.627s (executing steps: 4m51.228s) | ||
``` | ||
|
||
### Hooks | ||
|
||
When using parallel mode, any `BeforeAll` and `AfterAll` hooks you have defined will run _once per worker_. |
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,41 @@ | ||
# Profiles | ||
|
||
If you have several permutations of running Cucumber with different CLI options in your project, it might be a bit cumbersome to manage. *Profiles* enable you to declare bundles of configuration and reference them with a single CLI option. | ||
|
||
Let's take the common case of having some things a bit different locally vs in CI. Here's the command we've been running locally: | ||
|
||
```shell | ||
$ cucumber-js --require-module ts-node/register --require 'support/**/*./ts' --world-parameters '{\"appUrl\":\"http://localhost:3000/\"}' --format progress-bar --format html:./cucumber-report.html | ||
``` | ||
|
||
For argument's sake, we'll want these changes in CI: | ||
|
||
- The URL for the app (maybe dynamically provisioned?) | ||
- The formatters we want to use | ||
|
||
To start using Profiles, we just need to create a `cucumber.js` file in our project's root. It's a simple JavaScript module that exports an object with profile names as keys and CLI options as values. We can lean on JavaScript to reduce duplication and grab things dynamically as needed. Here's what we might write to address the needs described above: | ||
|
||
```javascript | ||
const worldParameters = { | ||
appUrl: process.env.MY_APP_URL || "http://localhost:3000/" | ||
} | ||
const common = `--require-module ts-node/register --require 'support/**/*./ts' --world-parameters '${JSON.stringify(worldParameters)}'` | ||
|
||
module.exports = { | ||
'default': `${common} --format progress-bar --format html:./cucumber-report.html`, | ||
'ci': `${common} --format html:./cucumber-report.html --publish` | ||
} | ||
``` | ||
|
||
Now, if we just run `cucumber-js` with no arguments, it will pick up our profiles and use the `default` one. | ||
|
||
In CI, we just need to change the command to specify the "ci" profile: | ||
|
||
```shell | ||
$ cucumber-js --profile ci | ||
``` | ||
|
||
Some notes about how Profiles work: | ||
|
||
- The `--profile` CLI option is repeatable, so you can apply multiple profiles at once. | ||
- You can still supply options directly on the command line when using profiles, they will be appended to whatever comes from profiles. |
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,26 @@ | ||
# Retry | ||
|
||
If you have a flaky scenario (e.g. failing 10% of the time for some reason), you can use *Retry* to have Cucumber attempt it multiple times until either it passes or the maximum number of attempts is reached. You enable this via the `--retry <MAXIMUM_RETRIES>` CLI option, like this: | ||
|
||
```shell | ||
$ cucumber-js --retry 1 | ||
``` | ||
|
||
The number you provide is the number of retries that will be allowed after an initial failure. | ||
|
||
*Note:* Retry isn't recommended for routine use, but can be a good trade-off in some situations where you have a scenario that's too valuable to remove, but it's either not possible or not worth the effort to fix the flakiness. | ||
|
||
Some notes on how Retry works: | ||
|
||
- Only relevant failing scenarios are retried, not the whole test run. | ||
- When a scenario is retried, it runs all hooks and steps again from the start with a fresh [World](./support_files/world.md) - nothing is retained from the failed attempt. | ||
- When a scenario passes on a retry, it's treated as a pass overall in the results, although the details of each attempt are emitted so formatters can access them. | ||
|
||
|
||
## Targeting scenarios | ||
|
||
Using the `--retry` option alone would mean every scenario would be allowed multiple attempts - this almost certainly isn't what you want, assuming you have a small set of flaky scenarios. To target just the relevant scenarios, you can provide a [tag expression](https://cucumber.io/docs/cucumber/api/#tag-expressions) via the `--retry-tag-filter <TAG_EXPRESSION>` CLI option, like this: | ||
|
||
```shell | ||
$ cucumber-js --retry 1 --retry-tag-filter @flaky | ||
``` |
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