Skip to content

Commit

Permalink
Merge pull request #83 from javierbrea/release
Browse files Browse the repository at this point in the history
Release v2.3.0
  • Loading branch information
javierbrea authored Apr 4, 2021
2 parents 4b5235b + 054f2a3 commit 8e6b7a5
Show file tree
Hide file tree
Showing 28 changed files with 1,554 additions and 392 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
id: extract-branch
- name: Use Node.js
uses: actions/setup-node@v2
with:
Expand All @@ -40,11 +36,6 @@ jobs:
run: npm run lint
- name: Test unit
run: npm run test:unit
- name: Test mutation
run: npm run test:mutation
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.branch }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_TOKEN }}
- name: Test E2E
run: npm run test:e2e:ci
id: test-e2e
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/test-mutation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: test-mutation
on:
push:
branches:
- main
- release
jobs:
test-mutation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
id: extract-branch
- uses: actions/setup-node@v2
with:
node-version: '15.x'
registry-url: 'https://registry.npmjs.org/'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm ci
- name: Test mutation
run: npm run test:mutation
env:
BRANCH_NAME: ${{ steps.extract-branch.outputs.branch }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_TOKEN }}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [2.3.0] - 2021-04-04

### Added
- feat: Add FAIL_FAST_STRATEGY environment variable, allowing to skip tests only in current spec file, in current run or in parallel runs (#29)
- feat: Add configuration allowing to implement fail-fast in parallel runs (#33).

### Changed
- chore(ci): Separate test mutation job to a new workflow
- chore(deps): Update devDependencies

## [2.2.2] - 2021-03-30

### Fixed
Expand Down
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

Enables fail fast in Cypress, skipping the rest of tests on first failure.

It can be configured to skip all remaining tests in current spec file, in current run, or even in parallel runs.

## Table of Contents

- [Installation](#installation)
- [Configuration](#configuration)
* [Environment variables](#environment-variables)
* [Configuration by test](#configuration-by-test)
* [Configuration examples for usual scenarios](#configuration-examples-for-usual-scenarios)
* [Configuration for parallel runs](#configuration-for-parallel-runs)
- [Usage with TypeScript](#usage-with-typescript)

## Installation

Add the plugin to `devDependencies`
Expand Down Expand Up @@ -39,6 +51,10 @@ From now, if one test fail after its last retry, the rest of tests will be skipp

### Environment variables

* __`FAIL_FAST_STRATEGY`__: `'spec'|'run'|'parallel'`
* If `spec`, only remaining tests in current spec file are skipped.
* If `run`, all remaining tests in all spec files are skipped (default value).
* Use `parallel` to [provide your own callbacks](#configuration-for-parallel-runs) allowing to notify from one run to the others when remaining tests should be skipped.
* __`FAIL_FAST_ENABLED`__: `boolean = true` Allows disabling the "fail-fast" feature globally, but it could be still enabled for specific tests or describes using [configuration by test](#configuration-by-test).
* __`FAIL_FAST_PLUGIN`__: `boolean = true` If `false`, it disables the "fail-fast" feature totally, ignoring even plugin [configurations by test](#configuration-by-test).

Expand All @@ -54,7 +70,8 @@ or set the "env" key in the `cypress.json` configuration file:
{
"env":
{
"FAIL_FAST_ENABLED": false
"FAIL_FAST_STRATEGY": "run",
"FAIL_FAST_ENABLED": true
}
}
```
Expand Down Expand Up @@ -130,6 +147,46 @@ Set the `FAIL_FAST_PLUGIN` key in your local `cypress.env.json` configuration fi
}
```

### Configuration for parallel runs

The plugin configuration supports defining two callbacks that, used in combination, allow to skip tests in one run when other run starts skipping tests also. Where, or how do you store the "flag" that allows to communicate your runs is on your hand, the plugin does not care about it.

To implement it, the plugin can receive an object with extra configuration as third argument when it is registered in the `cypress/plugins/index.js` file:

* __`parallelCallbacks`__: Object containing next properties:
* __`onCancel`__: `function()` This callback is executed on first test failure that produces the plugin starts skipping tests.
* __`isCancelled`__: `function(): boolean` If this callback returns `true`, the plugin skips remaining tests.

These callbacks are executed only when the environment variable `FAIL_FAST_STRATEGY` is set to `parallel`.

Here is an example of configuration that would skip tests on many parallel runs when one of them starts skipping tests. It would only work if all parallel runs have access to the folder where the `isCancelled` flag is being stored as a file (easy to achieve if all of your parallel runs are being executed on Docker images on a same machine, for example). _Note that this is only an example, you could also implement it storing the flag in a REST API, etc._

```js
const fs = require("fs");
const path = require("path");

// Flag file is stored in the cypress folder
const isCancelledFlagPath = path.resolve(__dirname, "..", ".run-is-cancelled");

module.exports = (on, config) => {
require("cypress-fail-fast/plugin")(on, config, {
parallelCallbacks: {
onCancel: () => {
// Create flag file when the plugin starts skipping tests
fs.writeFileSync(isCancelledFlagPath);
},
isCancelled: () => {
// If any other run has created the file, start skipping tests
return fs.existsSync(isCancelledFlagPath);
},
},
});

return config;
};
```

Note that this example requires to remove the created file when all of the runs has finished, or tests will always be skipped whenever any run starts again. So, the `FAIL_FAST_STRATEGY` environment variable should be set to `parallel` only on CI pipelines where the workspace is cleaned on finish, for example.

## Usage with TypeScript

Expand Down
Loading

0 comments on commit 8e6b7a5

Please sign in to comment.