Code Monkey home page Code Monkey logo

cypress-fail-fast's Introduction

Build status Coverage Status Quality Gate Mutation testing badge

Renovate Last commit Last release

NPM downloads License

Cypress Fail Fast

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

Add the plugin to devDependencies

npm i --save-dev cypress-fail-fast

Now, depending on your Cypress version, use one of the next methods:

Installation on Cypress 10

Inside cypress.config.js file:

module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      require("cypress-fail-fast/plugin")(on, config);
      return config;
    },
    specPattern: "cypress/integration/**/*.js",
  },
};

Note: This example shows how to install the plugin for e2e testing type. Read Cypress configuration docs for further info.

At the top of your support file (usually cypress/support/e2e.js for e2e testing type)

import "cypress-fail-fast";

Installation on Cypress versions lower than 10

Inside cypress/plugins/index.js:

module.exports = (on, config) => {
  require("cypress-fail-fast/plugin")(on, config);
  return config;
};

At the top of cypress/support/index.js:

import "cypress-fail-fast";

From now, if one test fail after its last retry, the rest of tests will be skipped:

Cypress results screenshot

Limitations and notes

  • All spec files will be loaded, even after entering "skip mode", but every tests and hooks inside them will be skipped.
  • The spec strategy does not work in headed mode, because for Cypress events it is like running a single spec, so all remaining tests will be skipped.

Configuration

Environment variables

  • FAIL_FAST_STRATEGY: 'spec'|'run'|'parallel'
    • If spec, only remaining tests in current spec file are skipped. This mode only works in "headless" mode.
    • If run, all remaining tests in all spec files are skipped (default value).
    • Use parallel to provide your own callbacks 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.
  • FAIL_FAST_PLUGIN: boolean = true If false, it disables the "fail-fast" feature totally, ignoring even plugin configurations by test.
  • FAIL_FAST_BAIL: Number = 1 Enable the skip mode immediately upon n number of failing test suite. Defaults to 1.

Examples

CYPRESS_FAIL_FAST_PLUGIN=false npm run cypress

or set the "env" key in the cypress.json configuration file:

{
  "env":
  {
    "FAIL_FAST_STRATEGY": "run",
    "FAIL_FAST_ENABLED": true,
    "FAIL_FAST_BAIL": 2,
  }
}

Configuration by test

If you want to configure the plugin on a specific test, you can set this by using the failFast property in test configuration. The plugin allows next config values:

  • failFast: Configuration for the plugin, containing any of next properties:
    • enabled : Indicates wheter a failure of the current test or children tests (if configuration is applied to a suite) should produce to skip the rest of tests or not. Note that the value defined in this property has priority over the value of the environment variable CYPRESS_FAIL_FAST_ENABLED (but not over CYPRESS_FAIL_FAST_PLUGIN, which disables the plugin totally).

Example

In the next example, tests are configured to "fail-fast" only in case the test with the "sanity test" description fails. If any of the other tests fails, "fail-fast" will not be applied.

describe("All tests", {
  failFast: {
    enabled: false, // Children tests and describes will inherit this configuration
  },
}, () => {
  it("sanity test", {
    failFast: {
      enabled: true, // Overwrite configuration defined in parents
    },
  }, () => {
    // Will skip the rest of tests if this one fails
    expect(true).to.be.true;
  });

  it("second test",() => {
    // Will continue executing tests if this one fails
    expect(true).to.be.true;
  });
});

Configuration examples for usual scenarios

You want to disable "fail-fast" in all specs except one:

Set the FAIL_FAST_ENABLED key in the cypress.json configuration file:

{
  "env":
  {
    "FAIL_FAST_ENABLED": false
  }
}

Enable "fail-fast" in those specs you want using configurations by test:

describe("All tests", { failFast: { enabled: true } }, () => {
  // If any test in this describe fails, the rest of tests and specs will be skipped
});
You want to totally disable "fail-fast" in your local environment:

Set the FAIL_FAST_PLUGIN key in your local cypress.env.json configuration file:

{
  "env":
  {
    "FAIL_FAST_PLUGIN": false
  }
}

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 in your hands, 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.

// Example valid for Cypress versions lower than 10. Use config file on Cypress 10

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

// Flag file is stored in the /cypress folder
const isCancelledFlagFile = 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(isCancelledFlagFile, "");
      },
      isCancelled: () => {
        // If any other run has created the file, start skipping tests
        return fs.existsSync(isCancelledFlagFile);
      },
    },
  });

  return config;
};

Note that this example requires to remove the created file when all of the runs have 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 in CI pipelines where the workspace is cleaned on finish, for example.

Usage with TypeScript

If you are using TypeScript in the Cypress plugins file, this plugin includes TypeScript declarations and can be imported like the following:

import cypressFailFast = require("cypress-fail-fast/plugin");

export default (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): Cypress.PluginConfigOptions => {
  cypressFailFast(on, config);
  return config;
};

Note: The example above is only valid for Cypress versions lower than 10. Use the configuration file in Cypress 10.

Tests

To ensure the plugin stability, the current major version is being tested with Cypress major versions 9.x, 10.x, 11.x, 12.x and 13.x, and new releases will be published for each new Cypress minor or major releases, updating the E2E tests.

Minor versions used in the E2E tests can be checked in the devDependencies of the package.json files of the E2E tests:

Even when current major version may work with previous Cypress versions, it is not currently tested, so, to be sure it works you should use:

  • Cypress 8.x may work, but it was tested until cypress-fail-fast 7.0.x
  • If you need Cypress 7 support, use cypress-fail-fast 6.x
  • If you need Cypress 6 support, use cypress-fail-fast 5.x
  • If you need Cypress 5 or lower, use cypress-fail-fast <= 4.x

If you find any issue for a specific Cypress version, please report it at https://github.com/javierbrea/cypress-fail-fast/issues.

Acknowledgements

This plugin has been developed based on the solutions proposed by the community on this Cypress issue, so thanks to all! I hope this plugin can be deprecated soon, as soon as the Cypress team adds native support for this feature. ๐Ÿ˜ƒ

Contributing

Contributors are welcome. Please read the contributing guidelines and code of conduct.

License

MIT, see LICENSE for details.

cypress-fail-fast's People

Contributors

danielyang-at avatar javierbrea avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cypress-fail-fast's Issues

Cypress upgraded to v8.0.0: Update peerDependencies

Bug

Cypress upgraded to v8.0.0: Update peerDependencies

Audit

 cypress  ^7.7.0  โ†’  ^8.0.0

Run npm install to install new versions.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: [email protected]
npm ERR! node_modules/cypress
npm ERR!   dev cypress@"^8.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer cypress@"5.x || 6.x || 7.x" from [email protected]
npm ERR! node_modules/cypress-fail-fast
npm ERR!   dev cypress-fail-fast@"^3.0.0" from the root project

Add the possibility to add another task when tests are skipped with cypress-failure-fast plugin

Is your feature request related to a problem? Please describe.
I have a server opened every time my tests are running, and I would like to close it when some tests fails, otherwise my server will stay open for hours..

Describe the solution you'd like
Add the possibility to perform some other tasks when tests are skipped with cypress-failure-fast plugin, like my server-close command..

Instead of skipping the test case, can we fail the trailing tests for reporting purposes?

Is your feature request related to a problem? Please describe.

The library is helping to skip the test cases. But the CI reporting will report the skipped test cases as untested and this gives the wrong presentation for the management and gives less confidence to take to release.

Describe the solution you'd like
Though skipping test cases is a wise solution, can we fail the trailing test cases, at least the report gets generated as tested and failed instead of untested?

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or examples about the feature request here.

Allow to disable fail-fast in all tests except those specifically enabled

Describe the bug
A clear and concise description of what the bug is.

I have followed steps to install cypress-fail-fast in the Readme section, and yet tests were continue to get executed.

Untitled8

To Reproduce
Steps to reproduce the behavior

describe.only("suite", { "failFast": {"enabled": true} }, function() {
it('test1', function() { // do something})
it('test2', function() {// do something})
})

Expected behavior
A clear and concise description of what you expected to happen.

I have only configured failFast option in 1 describe block as seen in above codes. I would have expected test2 and the rest in that describe block to not get executed when test1 failed.

Logs
If applicable, add logs to help explain your problem.

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS: [e.g. Ubuntu 18.04] - Mac 11.0.1
  • Node.js: [e.g. 8.11.1] - node: '12.18.4'
  • npm: [e.g. 5.6.0] - npm: '6.14.10',
  • Browser: [e.g. Chrome 73.0.3683] - Chrome: 87.0.4280.141
  • Cypress: tried 5.6.0 & 6.2.1

Additional context
Add any other context about the problem here.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Do not log "Enabling skip mode" in every failed test

Originally reported by @josefsmrz in a comment in #186:

I am currently testing it in our project and I've noticed these messages:
[fail-fast] Enabling skip mode
appear after every failed test. Perhaps this could be replaced by a message counting the number of failed tests so far, something like:
[fail-fast] Failed tests: x/y

To Reproduce
When BAIL option is used, the skip mode might not be enabled in first failing tests, but the message is displayed each time a test fails.

Expected behavior
Do not log "Enabling skip mode" until the plugin actually enables the skip mode. If a test fails but the bail limit is not reached, then log the number of failed tests and the bail limit: [fail-fast] Failed tests: x/y

Getting this Error(1) "after each" hook in "{root}") and not progressing further

Getting this Error(1) "after each" hook in "{root}") and not progressing further

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS: CentOS 7
  • Node.js: v14.16.0
  • npm: 6.14.11
  • Browser: Firefox-91
  • Cypress: 6.4,0

Additional context

I given the sample code here.
plugin/index.js:
module.exports = (on, config) => {

const failfastObj = require('cypress-fail-fast/plugin')(on, config);
console.log('failFast:',failfastObj);
}
support/index.js:
import "cypress-fail-fast";
cypress.json:
env:{
"FAIL_FAST_STRATEGY": "spec",
"FAIL_FAST_ENABLED": true,
"FAIL_FAST_BAIL": 1,
}
integration/spec1.js:
I have these below of how my spec file looks like.
describe('test", ()=>{
before("", ()=>{
Getting value from fixtures and assign into global variable
});
beforeEach("", ()=>{
setting cookies
})
it("test1", ()=>{
cy.log('Test1");
});
it("test2", ()=>{
cy.log('Test2");
});
.
.
.
});

Run Cypress After Hook For Skipped Spec Files

Is your feature request related to a problem? Please describe.
When fail fast kicks in, cypress' after hook also gets skipped. This creates an issue with plugins like cypress-terminal-reporter that rely on the hook to output details for debugging.

Describe the solution you'd like

  • Whether or not to run the after hook could be configurable .

Parallel setting not working

Describe the bug
I would like to use the setting to skip all tests in parallel runs. But I am getting the following error after my failed test:

"after each" hook for "<Test Title>":
     CypressError: `cy.task('failFastShouldSkip')` failed with the following error:
> The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
https://on.cypress.io/api/task
Because this error occurred during a `after each` hook we are skipping all of the remaining tests.

None of the specs afterwards or the ones in the parallel jobs skip after this failure, they just run as usual

To Reproduce
This is happening in a GitLab CI job. This is the command used to run the tests:

cypress run-ct --spec <spec_file_1>, <spec_file_2>, ...

I set the configuration for parallel runs the same as the example in the README.

The "run" mode works as expected (skips remaining tests within a job if one fails), it's just with "parallel" that I am experiencing this.

Expected behavior
Remaining tests in job and the ones running in parallel should skip as soon as this test fails

Operating system, Node.js an npm versions, or browser version (please complete the following information):

  • Node.js: v16.14.2
  • Cypress: 9.7.0
  • Browser: Electron 100 (headless)

Handle possible errors in parallel callbacks

Currently, an error in parallel callbacks would produce the plugin tasks to fail without any further information.

It is desired to catch errors in parallel callbacks, ignore them, and give some information about it to the plugin users. Using logs in in red color would be enough.

Exit cypress when there is a failure

Is your feature request related to a problem? Please describe.
I would like to abort all tests suits, and exit from cypress task as soon as there is one failure.

Currently, cypress-fail-fast will only abort all the tests in one file, but it will continue with other test files

Nested beforeEach runs despite error in parent beforeEach

EDIT: This "first comment" seems duplicate of #124 - whilst the second comment seems to be a specific issue resulting from #124.

Describe the bug
Multiple beforeEach blocks are executed, even when a previous one failed. This means that the cypress-fail-fast plugin executes more code than vanilla Cypress does in this case.

To Reproduce

// Register a failing task in plugins/index.js
on('task', {
    'some-bad-task': () => {
        return new Promise((resolve, reject) => {
            reject("Hello rejected world");
        })
    }
})

// Later in the spec tests:
describe('the issue', () => {
        beforeEach(() => {
                // Do something that WILL fail
                cy.task('some-bad-task')
        })

        describe('a sub issue', () => {
                beforeEach(() => {
                        // Do something that may fail - in this case because of invalid file type (not HTML)
                        // This will hide the previous error in beforeEach. The issue is, that this line executes:
                        cy.visit('cypress/integration/test_spec.js')
                })
    
                it('works', () => {
                        // Randomly do stuff
                        cy.window()    
                })
        })
})

Expected behavior
Both of these:

  1. The nested beforeEach to not run at all.
  2. The error of the parent beforeEach to be given as output.

Logs
Multiple browsers and OSes:

  • Ubuntu 18 & Debian Docker images
  • Chrome & Firefox & Electron
  • Headless & Headed

Additional context
Add any other context about the problem here.

LocalStorage resets on failure

Is your feature request related to a problem? Please describe.
Cypress best practice recommends that you don't clear data until you start your next test

Describe the solution you'd like
Would like to be able to stay logged in (LocalStorage not killed) so I can keep testing the app session when it fails

Describe alternatives you've considered
I'm using my own simple runner.stop hack but would like to use the plugin

afterEach(function () {
  if (this.currentTest.state === "failed") {
    Cypress.runner.stop();
  }
});

Additional context

Support Cypress v6.x

E2E tests using Cypress v6.x should be added. It should also be added to peerDependencies

Before hook from spec is called in headless mode

Is your feature request related to a problem? Please describe.
Before hook's implemented in spec files (eg. DB setup) are still called after failure. It should be skipped to save CI time.

Describe the solution you'd like
When SHOULD_SKIP_TASK flag is set to true - it should not run spec's before hook.

"spec" strategy does not work in headed mode

Describe the bug
A clear and concise description of what the bug is.

When test file A fails (with failFast enabled), failFast plugin is skipping future test spec that also has failFast enabled.

To Reproduce
Steps to reproduce the behavior

cypress.json
"env": { "FAIL_FAST_PLUGIN": true, "FAIL_FAST_ENABLED": false },

failFast1.js
describe('in failFast1', { "failFast": {"enabled": true} }, function() { it('failFast1', function() { cy.log('testing in failFast1 file'); expect(1).equal(0); }) })

failFast2.js
describe('in failFast2', { "failFast": {"enabled": true} }, function() { it('failFast2', function() { cy.log('testing in failFast2 file'); expect(2).equal(1); }) })

failFast3.js
describe('in failFast3', { "failFast": {"enabled": true} }, function() { it('failFast3', function() { cy.log('testing in failFast3 file'); expect(3).equal(2); }) })

Expected behavior
A clear and concise description of what you expected to happen.

I assume it would only failFast the describe in existing test spec, and not future ones.

Logs
If applicable, add logs to help explain your problem.

image

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS: [e.g. Ubuntu 18.04] - Mac
  • Node.js: [e.g. 8.11.1] - v12.18.4
  • npm: [e.g. 5.6.0] - 6.14.10
  • Browser: [e.g. Chrome 73.0.3683] - Electron 87
  • failFast: 2.3.2

Additional context
Add any other context about the problem here.

Failure on before hook skips all tests but marks execution as passed

When there is an error in a "before" hook, all tests in the spec file are skipped, but the execution is marked as "passed", as no one test has failed.

It is desirable to mark the spec execution as "failed" somehow, or to force the next test to fail, so the execution will be marked as failed. It is also desirable to get traces about the error in the hook.

Examples

Describe the bug
Continues to run other specs when enabled.
To Reproduce
image
image
image

Expected behavior
It doesn't run the subsequent features.
Logs
If applicable, add logs to help explain your problem.

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS:Windows 10
  • Node.js: 16.13.0
  • npm: 8.1.0
  • Browser: Electron

Additional context

Ideally it would be great to get some sample projects added to the repo so I can reverse engineer how its done.

Configure renovate to ignore Cypress dependency in E2E tests

Renovate is trying to upgrade Cypress dependency in E2E tests to latest major version, which is not desired because the project is being tested with the last two major versions.

It should be configured to keep the latest minor version of v5.x in the version 5 tests, and the latest v6.x version in the version 6 tests.

Add support for node 16

Is your feature request related to a problem? Please describe.
We would like to use node 16 in our project

Describe the solution you'd like
Update CFF to use with node 16

Additional context
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '[email protected]',
npm WARN EBADENGINE required: { node: '10.x || 12.x || 14.x || 15.x' },
npm WARN EBADENGINE current: { node: 'v16.7.0', npm: '7.20.3' }
npm WARN EBADENGINE }

Make number of failed tests configurable

Is your feature request related to a problem? Please describe.
Hi, I would like to use this plugin, because sometimes I encounter test runs where all the tests are failing and this uses a lot of resources. However, I'd like to have the number of failing tests configurable, because it can happen, that a test is failing and I still want to execute the whole test run.

Describe the solution you'd like
It would be good to have an env variable where I could set a number of failing tests after which all of the remaining tests should be skipped.

Custom Callback On Test Fail

Is your feature request related to a problem? Please describe.
I need to perform some specific "cleanup" logic when a test fails. Currently, if a test fails and I'm using this plugin, the other tests get skipped properly, but I need to perform cleanup logic prior to the test runner exiting.

Describe the solution you'd like
The usage would be:

cypress/plugins/index.js

...
module.exports = (on, config) => {
  require('cypress-fail-fast/plugin')(on, config, { 
    cleanup: () => {
      // custom cleanup function
    }
  });
  return config;
};
...

The implementation would be

cypress-fail-fast/src/plugin.js

...
[SHOULD_SKIP_TASK]: function (value) {
  if (value === true) {
    if (cleanup) {
      cleanup()
    }
    if (onCancelCallback) {
      onCancelCallback()
    }
  }
}
...

Describe alternatives you've considered
Using parallelCallbacks. However, since I'm not genuinely using parallel tests, the plugin sets parallelCallbacks to false, and the if (onCancelCallback) line never gets hit.

Additional context
N/A

Support custom fail-fast strategies

It is a very usual practice to run different Cypress specs in parallel in CI pipelines. Currently, there is no a mechanism to skip the rest of parallel executions when one fails.

A possible solution (or workaround), may be to give an option to write/read a fail-fast flag to a json file as a kind of storage, so, if one test fails, the rest of parallel batteries will start skipping tests too. Obviously, all parallel executions should be able to access to the shared file. This is not an ideal solution, but could do the trick in scenarios where all Cypress executions are running in the same machine. If they are executed inside Docker containers, the folder in which the json file is shared should be mounted as a volume in all of them.

The user should be able to decide the path for the json file in which the failure will be saved, so the option could look like:

{
  "env": {
    "FAIL_FAST_STORAGE_FILE": ".tmp/cypress-fail-fast.json"
  }
}

Add "describe" strategy to skip only tests inside same describe

Describe the bug
A clear and concise description of what the bug is.

This is probably related to #100. This ticket is to report an issue where failFast behavior from previous describe is affecting next describe. See image. Notice that when a test fails in previous failfast, it is skipping all the tests in the next describe.

To Reproduce
Steps to reproduce the behavior

Expected behavior
A clear and concise description of what you expected to happen.

Logs
If applicable, add logs to help explain your problem.

describe('in failFast1, describe 1', { "failFast": {"enabled": true} }, function() { it('failFast1', function() { cy.log('testing in failFast1 file'); expect(1).equal(0); }) }) describe('in failFast1, describe 2', { "failFast": {"enabled": true} }, function() { it('failFast1', function() { cy.log('testing in failFast1 file'); expect(6).equal(0); }) })

image

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

OS: [e.g. Ubuntu 18.04] - Mac
Node.js: [e.g. 8.11.1] - v12.18.4
npm: [e.g. 5.6.0] - 6.14.10
Browser: [e.g. Chrome 73.0.3683] - Electron 87
failFast: 2.3.2

Additional context
Add any other context about the problem here.

Question - test:after:run event

I am adding context to display screenshots and videos from failed test.

Cypress.on('test:after:run', (test, runnable) => {
  if (test.state === 'failed') {
    addContext({ test }, `screenshots/${Cypress.spec.name}/${runnable.parent.title} -- ${test.title} (failed).png``);
    addContext({ test },  `videos/${Cypress.spec.name}.mp4`);
  }
});

However when cypress-fast-fail plugin is enabled, adding context is not executed at all.
Could you tell me what am I doing wrong or provide some workaround for this issue?

Bug: cypress-fail-fast does not totally stop testing after finding failure

Problem

If cypress/integrations has multiple specs, cypress-fail-fast does not total stop all future testing after failing test.

Cypress Integrations with multiple Specs

Within my Cypress integrations folder has 20+ specs:

cypress/integration
โ””โ”€โ”€ service
    โ””โ”€โ”€ actions
        โ”œโ”€โ”€ stage_0_config
        โ”‚ย ย  โ””โ”€โ”€ cypress.config.spec.ts
        โ”œโ”€โ”€ stage_1_admin
        โ”‚ย ย  โ”œโ”€โ”€ admin.0.login.csrf.spec.ts
        โ”‚ย ย  โ”œโ”€โ”€ admin.1.verify.spec.ts
        โ”‚ย ย  โ””โ”€โ”€ admin.2.act.enabled.verify.spec.ts
       ....

Example forced test failure

To checkout cypress-fail-fast, within first spec cypress.config.spec.ts added the follow hard-coded failure:

  it('TEST Expect Fail Fast', done => {
    done(new Error('Expect Fail Fast'));
  });

Test Run

First Spec with hard coded test failure fast failed, as expected

During test run, when it hit the hard-coded failure, all future tests within that spec were skipped, as expected ๐Ÿ˜ƒ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Tests:        12                                                                               โ”‚
  โ”‚ Passing:      1                                                                                โ”‚
  โ”‚ Failing:      1                                                                                โ”‚
  โ”‚ Pending:      0                                                                                โ”‚
  โ”‚ Skipped:      10                                                                               โ”‚
  โ”‚ Screenshots:  3                                                                                โ”‚
  โ”‚ Video:        true                                                                             โ”‚
  โ”‚ Duration:     0 seconds                                                                        โ”‚
  โ”‚ Estimated:    0 seconds                                                                        โ”‚
  โ”‚ Spec Ran:     service/actions/stage_0_config/cypress.config.spec.ts                            โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Next Specs: did run first test for every Spec, even though console log shows skipped

So, I had expected that all future tests within all future specs under cypress/integrations would also be skipped.

However, what happened, the first test of every spec ran, but console shows that they were skipped.

Example of one of the Spec's showing first test ran:

Example of First Test running in Spec

However, console shows that they were skipped:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Tests:        7                                                                                โ”‚
โ”‚ Passing:      0                                                                                โ”‚
โ”‚ Failing:      0                                                                                โ”‚
โ”‚ Pending:      0                                                                                โ”‚
โ”‚ Skipped:      7                                                                                โ”‚
โ”‚ Screenshots:  0                                                                                โ”‚
โ”‚ Video:        true                                                                             โ”‚
โ”‚ Duration:     0 seconds                                                                        โ”‚
โ”‚ Estimated:    16 seconds                                                                       โ”‚
โ”‚ Spec Ran:     service/actions/stage_1_admin/admin.0.login.csrf.spec.ts           โ”‚  
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Parallel run example in README produces an error

The example in the README.md file about parallel runs contains an error. The fs.writeFileSync requires at least two arguments, and in the example only one is passed. So, it would not work if copied as it is.

It is desired to add a second argument in the example, an empty string would be enough to make it work.

This issue was originally discovered by @marboleda in #244

Support async parallel callbacks

The plugin should support parallel callbacks returning a promise. This would be useful to allow to perform async tasks when checking whether the plugin should stop the execution or not when running multiple Cypress processes in parallel, as suggested in a comment in #244 .

Tests are not skipped on specs

Describe the bug
I am using the default configuration of cypress-fail-fast( for FAIL_FAST_STRATEGY the default is run)
Tests are being skipped only for current spec, but the next specs are running with all tests.

To Reproduce
I have 4 spec.js files.
I run cypress run --browser chrome --headed --spec cypress/tests/integration/sanity/*
test fail on flow0.spec.js and all tests are skipped in the flow0.spec.js
flow1.spec.js is running with all tests

Expected behavior
With FAIL_FAST_STRATEGY run I expect that specs (flow1,flow2,flow3) wont run if a test fails on flow0.spec.js

Logs
If applicable, add logs to help explain your problem.

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS: win10
  • Node.js:18.12.0
  • npm: 6.14.13
  • Browser: Chrome 106.0.5249.119

Additional context
Add any other context about the problem here.

Option to apply fail-fast only in current spec file

It is desirable to add an option which would make make fast-fail to be applied only to the rest of tests in the current file or to apply it to all of the rest of files too, as currently. It could work as suggested in #27:

FAIL_FAST_STRATEGY: 'spec' | 'run'

So, setting a FAIL_FAST_STRATEGY as spec would make skip tests only in the current file, and setting it as run would make skip all tests in the rest of files too.

No cypress-cucumber-preprocessor reports are created for failed/skipped tests

Is your feature request related to a problem? Please describe.
I'm using cypress-cucumber-preprocessor to create cucumber-json reports for the results of the tests.
However, if I want to use cypress-fail-fast plugin, no reports are created for the failed/skipped specs/features.

Describe the solution you'd like
Let cypress-cucumber-preprocessor create proper cucumber-json reports for the failed/skipped tests when cypress-fail-fast is active.

Environment

  • OS: MacOS Mojave 10.14.6
  • Node.js: v16.13.0
  • npm: 8.1.0

package.json:

  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
    "cucumberJson": {
      "generate": true,
      "outputFolder": "cypress/cucumber-json",
      "filePrefix": "",
      "fileSuffix": ".cucumber"
    }
  },

cypress.json:

  "env": {
    "TAGS": "not @ignore",
    "FAIL_FAST_STRATEGY": "spec"
  },

Additional context
Not sure if that's really a bug or a feature.
It seems somehow related to #88 as well and may be same behaviour as reported in Shelex/cypress-allure-plugin#57

Great job, and thank you!

Plugin enabled by default

Currently the environment variable CYPRESS_FAIL_FAST has to be explicitly set as true to make the plugin works. It is desirable to invert this behavior, and make the plugin works by default once it is installed.

It should be still possible to disable it setting CYPRESS_FAIL_FAST as false when desired.

This change could be considered as a breaking change, so it should be released in a major version.

Option to enable fail-fast only in specific tests or describes

Is your feature request related to a problem? Please describe.

there is a certain percentage where we write test independent of other tests, and dependent of other tests. At the time of writing this request, this plugin fails fast when a test fails in a test file.

Describe the solution you'd like

This request is to only fail on dependent test(s). So some kind of configuration to say fail fast in this describe if we want to, but don't fail fast on other test files when a failure occurred.

Avoid clashing global types between Cypress and Jest

Hello. Thank you for this library.
Describe the bug
I use cypress-fail-fast in a project with common cypress config for other projects. It has jest test for custom cypress commands. After install cypress-fail-fast I have typescript error
"Property 'toEqual' does not exist on type 'Assertion'. Did you mean 'equal'? ts(2551)
index. d. ts (206, 9): 'equal' is declared here."
If delete /// <reference types="cypress" /> in the plugin. d. ts and index. d. ts errors disappears. So I suggest delete these two lines from cypress-fail-fast. I tried it and it is ok.

Disable plugin local and enable on CI

I want to disable cypress-fail-fast local but enable it on CI. I tried to use this config Env: {FAIL_FAST_ENABLED: false,},
and run tests with command CYPRESS_FAIL_FAST_PLUGIN=true yarn cypress for enable plugin on CI, but it is not working.
Is it another way?

Cypress time travel log for Fail Fast something logs in next test

Describe the bug
In some edge cases (stopping and restarting the Cypress Test Runner tests multiple times) will cause the Cypress time travel logs to be printed in the next test.

To Reproduce

  • Start the Cypress Test runner (npx cypress open)
  • Run the tests
  • Leave to run for 1 or 2 tests to finish
  • Stop and restart the tests
  • Do this 3-4-5 times
  • At some point the Time Travel Logs from Test#1 are printed in Test#2

Expected behavior
The logs should always be printed in the test they belong to, not the following one.

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS: Windows
  • Node.js: 14.16
  • npm: 6.14
  • Browser: Electron

tsc finds recursive reference with TestConfigOverrides

Does the TestConfigOverrides need to partial extend itself? I get a tsc recursive reference when checking with npx tsc with this package implemented. I tried removing extends Partial<TestConfigOverrides> in my local node_modules and it appears to have worked.

interface TestConfigOverrides extends Partial<TestConfigOverrides> {

error TS2310: Type 'TestConfigOverrides' recursively references itself as a base type

Skip all other before hooks when one fails

Currently, when one "before" hook fails, the rest "before" or "beforeEach" of hooks are executed until the first test is forced to fail and skip starts. It is desirable to skip also the rest of hooks.

Plugin is not skipping any tests.

Describe the bug
The plugin is not skipping any tests after a test failed:

image

To Reproduce
I've got my Cypress configured to work with TypeScript. This is the setup:

// cypress.config.ts
import { defineConfig } from 'cypress';
import plugin from './cypress/plugins/index';

export default defineConfig({
	projectId: 'xx',
	fixturesFolder: 'cypress/fixtures',
	video: true,
	viewportHeight: 1000,
	viewportWidth: 1600,
	e2e: {
		env: {
			API_URL: 'xx',
			CYPRESS_PASSWORD: 'xx',
		},
		supportFile: 'cypress/support/index.ts',
		baseUrl: 'http://localhost:4200',
		experimentalInteractiveRunEvents: true,
		setupNodeEvents(on, config) {
			plugin(on, config);
		},
	},
});
// cypress/support.index.ts
import './commands';
import './hooks';
import 'cypress-real-events/support';
import 'cypress-file-upload';
import 'cypress-fail-fast/plugin';
/cypress/tsconfig.json
{
	"extends": "../tsconfig.json",
	"include": ["**/**/*.ts"],
	"compilerOptions": {
		"sourceMap": false,
		"types": ["cypress", "node", "cypress-file-upload", "cypress-real-events", "cypress-fail-fast"]
	}
}

If I remove the /plugin from the import in cypress/support/index.ts > import 'cypress-fail-fast/plugin'; I get this:

CypressError: "before all" hook failed: cy.task('failFastShouldSkip') failed with the following error:
The task 'failFastShouldSkip' was not handled in the setupNodeEvents method. The following tasks are registered: >?createSession, log, createCompany, updateRefreshToken, getCompany, getUsers

Expected behavior
With the plugin enable Cypress should skip the tests after a failed test.

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • Node.js: 14.20
  • npm: 6.14.17
  •  "cypress": "^10.4.0",
     "cypress-fail-fast": "^5.0.1",
    

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency cypress to v12.17.4
  • chore(deps): update martinbeentjes/npm-get-version-action action to v1.3.1

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency babel-plugin-module-resolver to v5.0.2
  • chore(deps): update dependency serve to v14.2.3
  • chore(deps): update endbug/version-check action to v2.1.4
  • chore(deps): update mindsers/changelog-reader-action action to v2.2.3
  • chore(deps): update dependency @babel/eslint-parser to v7.24.1
  • chore(deps): update dependency eslint to v8.57.0
  • chore(deps): update dependency eslint-config-prettier to v9.1.0
  • chore(deps): update dependency eslint-plugin-prettier to v5.1.3
  • chore(deps): update dependency eslint-plugin-react to v7.34.1
  • chore(deps): update dependency fs-extra to v11.2.0
  • chore(deps): update dependency lint-staged to v15.2.2
  • chore(deps): update dependency prettier to v3.2.5
  • chore(deps): update dependency typescript to v5.4.5
  • chore(deps): update dependency webpack to v5.91.0
  • chore(deps): update actions/cache action to v4
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @cypress/webpack-preprocessor to v6
  • chore(deps): update dependency cypress to v13.8.1
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency husky to v9
  • chore(deps): update github artifact actions to v4 (major) (actions/download-artifact, actions/upload-artifact)
  • chore(deps): update stryker-js monorepo to v8 (major) (@stryker-mutator/core, @stryker-mutator/jest-runner)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/upload-artifact v3
  • actions/checkout v3
  • actions/download-artifact v3
.github/workflows/check-package-version.yml
  • actions/checkout v3
  • EndBug/version-check v2.1.1
  • martinbeentjes/npm-get-version-action v1.2.3
  • mindsers/changelog-reader-action v2.2.2
  • christian-draeger/read-properties 1.1.1
.github/workflows/publish-to-github-registry.yml
  • actions/checkout v3
  • actions/setup-node v3
  • MerthinTechnologies/edit-json-action v1
.github/workflows/publish-to-npm.yml
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/test-mutation.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
npm
package.json
  • chalk 4.1.2
  • @babel/eslint-parser 7.23.3
  • @stryker-mutator/core 7.3.0
  • @stryker-mutator/jest-runner 7.3.0
  • cross-env 7.0.3
  • cypress 13.5.1
  • eslint 8.54.0
  • eslint-config-prettier 9.0.0
  • eslint-plugin-prettier 5.0.1
  • eslint-plugin-react 7.33.2
  • husky 8.0.3
  • is-ci 3.0.1
  • jest 29.7.0
  • lint-staged 15.1.0
  • prettier 3.1.0
  • sinon 17.0.1
  • typescript 5.3.2
  • cypress >=8.0.0
  • node >=14.0.0
test-e2e/cypress-variants/cypress-10/package.json
  • @cypress/webpack-preprocessor 5.17.1
  • babel-loader 9.1.3
  • babel-plugin-module-resolver 5.0.0
  • cross-env 7.0.3
  • cypress 10.11.0
  • fs-extra 11.1.1
  • mochawesome 7.1.3
  • mochawesome-merge 4.3.0
  • mochawesome-report-generator 6.2.0
  • webpack 5.89.0
test-e2e/cypress-variants/cypress-11/package.json
  • @cypress/webpack-preprocessor 5.17.1
  • babel-loader 9.1.3
  • babel-plugin-module-resolver 5.0.0
  • cross-env 7.0.3
  • cypress 11.2.0
  • fs-extra 11.1.1
  • mochawesome 7.1.3
  • mochawesome-merge 4.3.0
  • mochawesome-report-generator 6.2.0
  • webpack 5.89.0
test-e2e/cypress-variants/cypress-12/package.json
  • @cypress/webpack-preprocessor 5.17.1
  • babel-loader 9.1.3
  • babel-plugin-module-resolver 5.0.0
  • cross-env 7.0.3
  • cypress 12.17.3
  • fs-extra 11.1.1
  • mochawesome 7.1.3
  • mochawesome-merge 4.3.0
  • mochawesome-report-generator 6.2.0
  • webpack 5.89.0
test-e2e/cypress-variants/cypress-13/package.json
  • @cypress/webpack-preprocessor 5.17.1
  • babel-loader 9.1.3
  • babel-plugin-module-resolver 5.0.0
  • cross-env 7.0.3
  • cypress 12.17.3
  • fs-extra 11.1.1
  • mochawesome 7.1.3
  • mochawesome-merge 4.3.0
  • mochawesome-report-generator 6.2.0
  • webpack 5.89.0
test-e2e/cypress-variants/cypress-9/package.json
  • @cypress/webpack-preprocessor 5.17.1
  • babel-loader 9.1.3
  • babel-plugin-module-resolver 5.0.0
  • cross-env 7.0.3
  • cypress 9.7.0
  • fs-extra 11.1.1
  • mochawesome 7.1.3
  • mochawesome-merge 4.3.0
  • mochawesome-report-generator 6.2.0
  • webpack 5.89.0
test-e2e/cypress-variants/typescript/package.json
  • cross-env 7.0.3
  • cypress 12.17.3
  • fs-extra 11.1.1
  • mochawesome 7.1.3
  • mochawesome-merge 4.3.0
  • mochawesome-report-generator 6.2.0
  • typescript 5.3.2
test-e2e/package.json
  • cross-env 7.0.3
  • fs-extra 11.1.1
  • jest 29.7.0
  • serve 14.2.1
  • start-server-and-test 2.0.3

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.