Skip to content

Commit

Permalink
fix: example
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 3, 2023
1 parent 46be620 commit 4cda6be
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
cypress/videos/
92 changes: 91 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

> Fixes multiple Cypress plugins subscribing to "on" events
See [#22428](https://github.com/cypress-io/cypress/issues/22428) issue.

## Install

Add this NPM package as a dev dependency
Expand All @@ -24,7 +26,7 @@ module.exports = defineConfig({
supportFile: false,
fixturesFolder: false,
setupNodeEvents(cypressOn, config) {
const on = require('.')(cypressOn)
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)
Expand All @@ -44,3 +46,91 @@ This module uses [debug](https://github.com/debug-js/debug#readme) to print verb
```
DEBUG=cypress-on-fix npx cypress run ...
```

## Example

```js
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

```js
setupNodeEvents(cypressOn, config) {
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 <gleb.bahmutov@gmail.com> © 20223

- [@bahmutov](https://twitter.com/bahmutov)
- [glebbahmutov.com](https://glebbahmutov.com)
- [blog](https://glebbahmutov.com/blog)
- [videos](https://www.youtube.com/glebbahmutov)
- [presentations](https://slides.com/bahmutov)
- [cypress.tips](https://cypress.tips)
- [Cypress Tips & Tricks Newsletter](https://cypresstips.substack.com/)
- [my Cypress courses](https://cypress.tips/courses)

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](https://github.com/bahmutov/cypress-on-fix/issues) on Github

## MIT License

Copyright (c) 2023 Gleb Bahmutov <gleb.bahmutov@gmail.com>

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.
10 changes: 5 additions & 5 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module.exports = defineConfig({
setupNodeEvents(cypressOn, config) {
const on = require('.')(cypressOn)
on('after:spec', (a) => {
console.log('after spec 1', a)
console.log('after spec 1', a.relative)
})
on('after:spec', () => {
console.log('after spec 2')
on('after:spec', (a) => {
console.log('after spec 2', a.relative)
})
on('after:spec', () => {
console.log('after spec 3')
on('after:spec', (a) => {
console.log('after spec 3', a.relative)
})
},
},
Expand Down

0 comments on commit 4cda6be

Please sign in to comment.