npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-plugin-init

v0.0.10

Published

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

Downloads

23,653

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.

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 [email protected]