diff --git a/system-tests/projects/plugin-run-events-multiple/cypress.config.js b/system-tests/projects/plugin-run-events-multiple/cypress.config.js new file mode 100644 index 000000000000..c2c05a24d8dd --- /dev/null +++ b/system-tests/projects/plugin-run-events-multiple/cypress.config.js @@ -0,0 +1,77 @@ +/* eslint-disable no-console */ +const EventEmitter = require('events') + +class EventBugFix { + constructor (on_reference) { + this.emitter = new EventEmitter() + this.on_reference = on_reference + this.proxied_events = [ + 'before:run', + 'after:run', + 'before:spec', + 'after:spec', + ] + + this.proxied_events.forEach((event) => { + on_reference(event, (...args) => { + this.emitter.emit(event, ...args) + }) + }) + } + on (event, ...args) { + if (this.proxied_events.indexOf(event) !== -1) { + this.emitter.on(event, ...args) + } else { + this.on_reference(event, ...args) + } + } +} + +module.exports = { + 'fixturesFolder': false, + 'e2e': { + 'supportFile': false, + setupNodeEvents (on, config) { + // Run test with RUN_MULTIPLE_PASS=true to show test pass + if (process.env.RUN_MULTIPLE_PASS) { + const _bugFix = new EventBugFix(on) + + on = _bugFix.on.bind(_bugFix) + } + + on('before:run', (runDetails) => { + console.log('before:run first handler') + }) + + on('before:run', (runDetails) => { + console.log('before:run second handler') + }) + + on('after:run', (results) => { + console.log('after:run first handler') + }) + + on('after:run', (results) => { + console.log('after:run second handler') + }) + + on('before:spec', (spec) => { + console.log('before:spec first handler') + }) + + on('before:spec', (spec) => { + console.log('before:spec second handler') + }) + + on('after:spec', (spec, results) => { + console.log('after:spec first handler') + }) + + on('after:spec', (spec, results) => { + console.log('after:spec second handler') + }) + + return config + }, + }, +} diff --git a/system-tests/projects/plugin-run-events-multiple/cypress/e2e/run_events_spec_1.cy.js b/system-tests/projects/plugin-run-events-multiple/cypress/e2e/run_events_spec_1.cy.js new file mode 100644 index 000000000000..582cc9815ade --- /dev/null +++ b/system-tests/projects/plugin-run-events-multiple/cypress/e2e/run_events_spec_1.cy.js @@ -0,0 +1 @@ +it('is true', () => {}) diff --git a/system-tests/projects/plugin-run-events-multiple/cypress/e2e/run_events_spec_2.cy.js b/system-tests/projects/plugin-run-events-multiple/cypress/e2e/run_events_spec_2.cy.js new file mode 100644 index 000000000000..582cc9815ade --- /dev/null +++ b/system-tests/projects/plugin-run-events-multiple/cypress/e2e/run_events_spec_2.cy.js @@ -0,0 +1 @@ +it('is true', () => {}) diff --git a/system-tests/test/plugin_run_events_multiple_spec.ts b/system-tests/test/plugin_run_events_multiple_spec.ts new file mode 100644 index 000000000000..fcd8514bae1d --- /dev/null +++ b/system-tests/test/plugin_run_events_multiple_spec.ts @@ -0,0 +1,25 @@ +import systemTests, { expect } from '../lib/system-tests' + +describe('e2e plugin run events', () => { + systemTests.setup() + const events = ['before:run', 'after:run', 'before:spec', 'after:spec'] + + events.forEach((event) => { + systemTests.it(`${event} supports multiple event listeners`, { + browser: 'electron', + project: 'plugin-run-events-multiple', + spec: '*', + snapshot: false, + config: { + video: false, + }, + async onRun (exec) { + const res = await exec() + const normOut = systemTests.normalizeStdout(res.stdout) + + expect(normOut).to.contain(`${event} first handler`) + expect(normOut).to.contain(`${event} second handler`) + }, + }) + }) +})