GitXplorerGitXplorer
e

cypress-plugin-init

public
5 stars
0 forks
2 issues

Commits

List of commits on branch main.
Verified
5a6278133110a75070616be3aee86e8640c016e8

Merge pull request #167 from elaichenkov/dependabot/npm_and_yarn/release-it-18.0.0

eelaichenkov committed 7 days ago
Verified
bc1c3885b8245befd2cc7292806709d114992800

Merge pull request #166 from elaichenkov/dependabot/npm_and_yarn/types/node-22.10.5

eelaichenkov committed 7 days ago
Verified
6fbf7b53f0122c60af4f16f33a964c6cc3a6f1e3

build(deps-dev): bump release-it from 17.10.0 to 18.0.0

ddependabot[bot] committed 12 days ago
Verified
eac4414a8383c3529e6f55266c4bd3290d362bbf

build(deps-dev): bump @types/node from 22.10.2 to 22.10.5

ddependabot[bot] committed 12 days ago
Verified
3a5c023f3a0f215ee522d0dacf3b0f050884c8de

Merge pull request #164 from elaichenkov/dependabot/npm_and_yarn/cypress-13.17.0

eelaichenkov committed 22 days ago
Verified
79354ae626da047b031e488618113d233e64d627

Merge pull request #163 from elaichenkov/dependabot/npm_and_yarn/types/node-22.10.2

eelaichenkov committed 22 days ago

README

The README file for this repository.

cypress-plugin-init

This library was designed to overcome the limitations of the Cypress plugin system to have multiple listeners. So, it allows you to initialize all needed plugins in one place. Futhermore, this allows you to use the Cypress plugin system to its full potential.

Motivation

The Cypress plugin system is a great way to extend the Cypress functionality. However, it has some limitations. One of them is that you can only have one listener for a specific event. This means that if you want to use multiple plugins that listen to the same event, you can't do it. This library was designed to overcome this limitation.

For instance, if you have two plugins that are listening to the before:run event, you can initialize both of them with this library.

import { defineConfig } from 'cypress';
import { initPlugins } from 'cypress-plugin-init';

const plugin1 = (on: Cypress.PluginEvents) => {
  on('before:run', (_) => console.log('[Plugin #1] Running before:run'));
};

const plugin2 = (on: Cypress.PluginEvents) => {
  on('before:run', (_) => console.log('[Plugin #2] Running before:run'));
};

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      initPlugins(on, [plugin1, plugin2]);
    },
  },
});

The output of the code above will be:

(Run Starting)
...
[Plugin #1] Running before:run
[Plugin #2] Running before:run
...
(Run Finished)

If you run the same code without this library, the output will be:

(Run Starting)
...
[Plugin #2] Running before:run
...
(Run Finished)

Hence, you can see that the only the last one will be executed.

Installation

npm install cypress-plugin-init

Usage

It's pretty simple to use. Just import the initPlugins function and call the initPlugins function with the plugins you want to initialize in your cypress.config.ts file.

import { initPlugins } from 'cypress-plugin-init';

export default defineConfig({
  e2e: {
    // ...

    setupNodeEvents(on, config) {
      // Initialize all plugins you want to use in your project
      initPlugins(on, [plugin1, plugin2]);
    },

    // ...
  },
});

If any of the plugins you want to initialize is expecting config as a parameter, you can pass it as a third parameter to the initPlugins function.

import { initPlugins } from 'cypress-plugin-init';

export default defineConfig({
  e2e: {
    // ...

    setupNodeEvents(on, config) {
      // Initialize all plugins you want to use in your project
      initPlugins(on, [plugin1, plugin2], config);
    },

    // ...
  },
});

License

MIT

Author

Yevhen Laichenkov elaichenkov@gmail.com