javierbrea / cypress-fail-fast

A Cypress plugin to skip tests on first failure.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plugin is not skipping any tests.

alucardu opened this issue · comments

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",
    

Hi @alucardu ,
It seems that you are not loading the plugin correctly in your node events. You are not importing this plugin's file in your config, but your own local ./cypress/plugins/index file (which I don't know what contains).

Note that in the plugin docs it is clearly indicated how to load the plugin in your config file:

module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      // You must execute here the plugin funcion, passing to it the events handler and the configuration.
      require("cypress-fail-fast/plugin")(on, config);
      return config;
    },
    specPattern: "cypress/integration/**/*.js",
  },
};

So, in your configuration you should change your current plugin importation by:

// cypress.config.ts
import { defineConfig } from 'cypress';
import plugin from 'cypress-fail-fast/plugin';

If you need to load more plugins, I suppose that you should also load them separately, following their respective instructions.

I'm using TypeScript so I cannot use require.

import { defineConfig } from 'cypress';
import plugin from './cypress/plugins/index';
import cypressFailFast from 'cypress-fail-fast/plugin';

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) {
			cypressFailFast(on, config);
			plugin(on, config);
                        return config;
		},
	},
});

Still no tests are skipped after a failed test.

Okay I found my issue. In my cypress/support/index.ts I imported like so import 'cypress-fail-fast/plugin'; but it should be import 'cypress-fail-fast';

I declared cypressFailFast in my plugin file, cypress/plugins/index.ts :

export default function plugin(on, config) {
	cypressFailFast(on, config);
        ....

which is the same as declaring it in my setupNodeEvents in the cypress.config.ts since I just call that plugin function:

setupNodeEvents(on, config) {
  plugin(on, config);
},

image