Closed edme88 closed 7 months ago
Hi @edme88. It looks like the same Cypress multiple on
events issue as #177
So basically we can't listen on the same on
events more than once, and often time when we use many plugins together, this would make the internal plugin functions broken. Here is the quick workaround:
// cypress.config.js
// define OnWrapper
const isObject = require('lodash/isObject')
const merge = require('lodash/merge')
class OnWrapper {
constructor(on) {
this.listeners = {}
this.originalOn = on
}
on(event, handler) {
if (event === 'task') return this.originalOn('task', handler)
if (this.listeners[event] === undefined) {
this.listeners[event] = []
}
return this.listeners[event].push(handler)
}
forward() {
Object.entries(this.listeners).forEach(([event, handlers]) => {
this.originalOn(event, async (...args) => {
let result = {}
for (const handler of handlers) {
const res = await handler(...args)
// some `on` events need to return the configuration object
// merge them if we can, otherwise the last one will be returned
result = isObject(res) ? merge(result, res) : res
}
return result
})
})
}
}
// define cypress config
module.exports = defineConfig({
e2e: {
async setupNodeEvents(cypressOn, config) {
const wrapper = new OnWrapper(cypressOn)
wrapper.on("file:preprocessor", () => {
console.log('my file:preprocessor event')
});
await addCucumberPreprocessorPlugin(wrapper.on.bind(wrapper), config);
const cypressImageDiffConfig = getCompareSnapshotsPlugin(wrapper.on.bind(wrapper), config);
// remember to forward all events to the original cypress on
wrapper.forward()
return cypressImageDiffConfig
}
}
});
Thanks in adcance! I will try to apply this solution 👍
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 30 days since being marked as stale.
In a project with cypress-cucumber, I have the following configuration:
In cypress.confog.js:
In cypress/support/e2e.js:
In package.json:
Since I install and use cypress-image-diff-js, only the ndjson report is generated. json report abd html report are not generated.
There is something wrong with my configuration? Or there is a problem with the integration of cypress-image diff in a cucumber project?