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-on-fix

v1.0.3

Published

Fixes multiple Cypress plugins subscribing to "on" events

Downloads

327,344

Readme

cypress-on-fix cypress version

Fixes multiple Cypress plugins subscribing to "on" events

See #22428 issue.

Read the blog post Fix For Cypress Plugin Events.

Install

Add this NPM package as a dev dependency

# install using NPM
$ npm i -D cypress-on-fix
# install using Yarn
$ yarn add -D cypress-on-fix

Wrap the on passed by Cypress in your config file

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    // baseUrl, etc
    supportFile: false,
    fixturesFolder: false,
    setupNodeEvents(cypressOn, config) {
      // https://github.com/bahmutov/cypress-on-fix
      const on = require('cypress-on-fix')(cypressOn)
      // use "on" to register plugins, for example
      // https://github.com/bahmutov/cypress-split
      require('cypress-split')(on, config)
      // https://github.com/bahmutov/cypress-watch-and-reload
      require('cypress-watch-and-reload/plugins')(on, config)
      // https://github.com/bahmutov/cypress-code-coverage
      require('@bahmutov/cypress-code-coverage/plugin')(on, config)
    },
  },
})

If there are multiple plugins that returns a value, the last one result will be returned

const on = require('cypress-on-fix')(cypressOn)
on('before:browser:launch', (browser, launchOptions) => {
  if (browser.name === 'chrome') {
    launchOptions.args.push('--window-size=1366,768')
    return launchOptions
  }
})
on('before:browser:launch', (browser, launchOptions) => {
  if (browser.name === 'chrome') {
    launchOptions.args.push('--window-size=1280,720')
    return launchOptions
  }
})

In the situation above, the Chrome browser will be opened with the window size 1280x720

Debugging

This module uses debug to print verbose log messages. Run Cypress with

DEBUG=cypress-on-fix npx cypress run ...

Example

setupNodeEvents(on, config) {
  on('after:spec', (a) => {
    console.log('after spec 1', a.relative)
  })
  on('after:spec', (a) => {
    console.log('after spec 2', a.relative)
  })
  on('after:spec', (a) => {
    console.log('after spec 3', a.relative)
  })
}

Without this plugin only the last event listener is invoked

after spec 3 cypress/e2e/spec1.cy.js

With this proxy, all listeners are invoked

setupNodeEvents(cypressOn, config) {
  // https://github.com/bahmutov/cypress-on-fix
  const on = require('cypress-on-fix')(cypressOn)
  on('after:spec', (a) => {
    console.log('after spec 1', a.relative)
  })
  on('after:spec', (a) => {
    console.log('after spec 2', a.relative)
  })
  on('after:spec', (a) => {
    console.log('after spec 3', a.relative)
  })
}
after spec 1 cypress/e2e/spec1.cy.js
after spec 2 cypress/e2e/spec1.cy.js
after spec 3 cypress/e2e/spec1.cy.js

Small print

Author: Gleb Bahmutov <[email protected]> © 20223

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2023 Gleb Bahmutov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.