-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 46be620
Showing
9 changed files
with
3,505 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# cypress-on-fix | ||
|
||
> Fixes multiple Cypress plugins subscribing to "on" 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 | ||
|
||
```js | ||
const { defineConfig } = require('cypress') | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
// baseUrl, etc | ||
supportFile: false, | ||
fixturesFolder: false, | ||
setupNodeEvents(cypressOn, config) { | ||
const on = require('.')(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) | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
## Debugging | ||
|
||
This module uses [debug](https://github.com/debug-js/debug#readme) to print verbose log messages. Run Cypress with | ||
|
||
``` | ||
DEBUG=cypress-on-fix npx cypress run ... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { defineConfig } = require('cypress') | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
// baseUrl, etc | ||
supportFile: false, | ||
fixturesFolder: false, | ||
setupNodeEvents(cypressOn, config) { | ||
const on = require('.')(cypressOn) | ||
on('after:spec', (a) => { | ||
console.log('after spec 1', a) | ||
}) | ||
on('after:spec', () => { | ||
console.log('after spec 2') | ||
}) | ||
on('after:spec', () => { | ||
console.log('after spec 3') | ||
}) | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// enables intelligent code completion for Cypress commands | ||
// https://on.cypress.io/intelligent-code-completion | ||
/// <reference types="cypress" /> | ||
|
||
it('works', () => {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// enables intelligent code completion for Cypress commands | ||
// https://on.cypress.io/intelligent-code-completion | ||
/// <reference types="cypress" /> | ||
|
||
it('works 2', () => {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// <reference types="cypress" /> | ||
|
||
const debug = require('debug')('cypress-on-fix') | ||
|
||
/** | ||
* @param {Cypress.PluginEvents} on | ||
*/ | ||
function onProxy(on) { | ||
const listeners = {} | ||
return function proxiedOn(eventName, callback) { | ||
if (eventName === 'task') { | ||
// no need to proxy tasks | ||
return on('task', callback) | ||
} | ||
|
||
debug('registering %s', eventName) | ||
if (listeners[eventName]) { | ||
debug('there are already %d listeners', listeners[eventName].length) | ||
listeners[eventName].push(callback) | ||
} else { | ||
debug('the only listener so far') | ||
listeners[eventName] = [callback] | ||
on(eventName, function () { | ||
debug( | ||
'proxy %s to %d listeners', | ||
eventName, | ||
listeners[eventName].length, | ||
) | ||
listeners[eventName].forEach((fn) => { | ||
fn.apply(null, arguments) | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
module.exports = onProxy |
Oops, something went wrong.