# cypress-plugin-init

> cypress-plugin-init is a library that simplifies the process of setting up multiple Cypress plugins in your project

Latest version **0.0.10** (published 2024-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install cypress-plugin-init
pnpm add cypress-plugin-init
yarn add cypress-plugin-init
bun add cypress-plugin-init
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2024-07-04 |
| First published | 2023-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Yevhen Laichenkov |
| Maintainers | elaichenkov |
| Keywords | cypress, e2e, testing, plugin |

## Links

- npm: https://www.npmjs.com/package/cypress-plugin-init
- Repository: https://github.com/elaichenkov/cypress-plugin-init
- Homepage: https://github.com/elaichenkov/cypress-plugin-init#readme
- Issues: https://github.com/elaichenkov/cypress-plugin-init/issues
- npm.io page: https://npm.io/package/cypress-plugin-init

## Alternatives

- [@snazzah/davey](https://npm.io/package/@snazzah/davey.md) — 1.5M weekly downloads
- [@vendure/testing](https://npm.io/package/@vendure/testing.md) — 8.3K weekly downloads
- [vue-simple-context-menu](https://npm.io/package/vue-simple-context-menu.md) — 6.6K weekly downloads
- [cypress-webpack-preprocessor-v5](https://npm.io/package/cypress-webpack-preprocessor-v5.md) — 2.1K weekly downloads
- [@backstage/plugin-catalog-backend-module-puppetdb](https://npm.io/package/@backstage/plugin-catalog-backend-module-puppetdb.md) — 1.3K weekly downloads

## Recent versions

- 0.0.10 (latest) — 2024-07-04
- 0.0.9 — 2024-05-03
- 0.0.8 — 2023-07-06
- 0.0.7 — 2023-03-29
- 0.0.6 — 2023-03-28
- 0.0.5 — 2023-03-28
- 0.0.4 — 2023-03-28
- 0.0.3 — 2023-03-28
- 0.0.2 — 2023-03-28

## README

# 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.

```ts
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:

```bash
(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:

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

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

## Installation

```bash
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.

```ts
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.

```ts
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](LICENSE)

## Author

Yevhen Laichenkov <elaichenkov@gmail.com>

---
_Source: https://npm.io/package/cypress-plugin-init · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
