Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove experimentalRunEvents flag #15276

Merged
merged 5 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@
"default": "bundled",
"description": "If set to 'system', Cypress will try to find a Node.js executable on your path to use when executing your plugins. Otherwise, Cypress will use the Node version bundled with Cypress."
},
"experimentalRunEvents": {
"type": "boolean",
"default": false,
"description": "Allows listening to the `before:run`, `after:run`, `before:spec`, and `after:spec` events in the plugins file."
},
"experimentalSourceRewriting": {
"type": "boolean",
"default": false,
Expand Down
5 changes: 0 additions & 5 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2582,11 +2582,6 @@ declare namespace Cypress {
* @default { runMode: 1, openMode: null }
*/
firefoxGcInterval: Nullable<number | { runMode: Nullable<number>, openMode: Nullable<number> }>
/**
* Allows listening to the `before:run`, `after:run`, `before:spec`, and `after:spec` events in the plugins file.
* @default false
*/
experimentalRunEvents: boolean
/**
* Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement
* algorithm.
Expand Down
6 changes: 5 additions & 1 deletion packages/server/__snapshots__/3_plugins_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,13 @@ The following validation error was thrown by your plugins file (\`/foo/bar/.proj
You passed: \`invalid:event\`

The following are valid events:
- dev-server:start
- after:run
- after:screenshot
- after:spec
- before:browser:launch
- before:run
- before:spec
- dev-server:start
- file:preprocessor
- task

Expand Down
36 changes: 12 additions & 24 deletions packages/server/__snapshots__/4_plugin_run_events_spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ exports['e2e plugin run events / sends events'] = `
(Run Starting)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 2 found (run_events_spec_1.js, run_events_spec_2.js) │
│ Searched: cypress/integration/* │
│ Experiments: experimentalRunEvents=true │
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 2 found (run_events_spec_1.js, run_events_spec_2.js) │
│ Searched: cypress/integration/* │
└────────────────────────────────────────────────────────────────────────────────────────────────┘

before:run: cypress/integration/run_events_spec_1.js electron
Expand Down Expand Up @@ -98,11 +97,10 @@ exports['e2e plugin run events / handles video being deleted in after:spec'] = `
(Run Starting)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (after_spec_deletes_video.js) │
│ Searched: cypress/integration/* │
│ Experiments: experimentalRunEvents=true │
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (after_spec_deletes_video.js) │
│ Searched: cypress/integration/* │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


Expand Down Expand Up @@ -150,27 +148,17 @@ This error will not alter the exit code.

`

exports['e2e plugin run events / fails if experimentalRunEvents is not enabled'] = `
The following validation error was thrown by your plugins file (\`/foo/bar/.projects/plugin-run-events/cypress/plugins/index.js\`).

Error: The \`before:run\` event requires the experimentalRunEvents flag to be enabled.

To enable it, set \`"experimentalRunEvents": true\` in your cypress.json
[stack trace lines]
`

exports['e2e plugin run events / fails run if event handler throws'] = `

====================================================================================================

(Run Starting)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (run_event_throws_spec.js) │
│ Searched: cypress/integration/* │
│ Experiments: experimentalRunEvents=true │
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (run_event_throws_spec.js) │
│ Searched: cypress/integration/* │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


Expand Down
17 changes: 8 additions & 9 deletions packages/server/lib/config_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ export const options = [
defaultValue: false,
validation: v.isBoolean,
isExperimental: true,
}, {
name: 'experimentalRunEvents',
defaultValue: false,
validation: v.isBoolean,
isExperimental: true,
Comment on lines -77 to -81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be good to add this to breakingOptions at the bottom of this file, so users get a warning that it's no longer required to pass this option?

}, {
name: 'experimentalSourceRewriting',
defaultValue: false,
Expand Down Expand Up @@ -303,13 +298,17 @@ export const breakingOptions = [
name: 'experimentalGetCookiesSameSite',
errorKey: 'EXPERIMENTAL_SAMESITE_REMOVED',
isWarning: true,
}, {
name: 'experimentalShadowDomSupport',
errorKey: 'EXPERIMENTAL_SHADOW_DOM_REMOVED',
isWarning: true,
}, {
name: 'experimentalNetworkStubbing',
errorKey: 'EXPERIMENTAL_NETWORK_STUBBING_REMOVED',
isWarning: true,
}, {
name: 'experimentalRunEvents',
errorKey: 'EXPERIMENTAL_RUN_EVENTS_REMOVED',
isWarning: true,
}, {
name: 'experimentalShadowDomSupport',
errorKey: 'EXPERIMENTAL_SHADOW_DOM_REMOVED',
isWarning: true,
},
]
5 changes: 5 additions & 0 deletions packages/server/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,11 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) {
The \`experimentalNetworkStubbing\` configuration option was removed in Cypress version \`6.0.0\`.
It is no longer necessary for using \`cy.intercept()\` (formerly \`cy.route2()\`).

You can safely remove this option from your config.`
case 'EXPERIMENTAL_RUN_EVENTS_REMOVED':
return stripIndent`\
The \`experimentalRunEvents\` configuration option was removed in Cypress version \`6.7.0\`. It is no longer necessary when listening to run events in the plugins file.

You can safely remove this option from your config.`
case 'INCOMPATIBLE_PLUGIN_RETRIES':
return stripIndent`\
Expand Down
2 changes: 0 additions & 2 deletions packages/server/lib/experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ interface StringValues {
const _summaries: StringValues = {
experimentalComponentTesting: 'Framework-specific component testing, uses `componentFolder` to load component specs.',
experimentalFetchPolyfill: 'Polyfills `window.fetch` to enable Network spying and stubbing.',
experimentalRunEvents: 'Allows listening to the `before:run`, `after:run`, `before:spec`, and `after:spec` events in the plugins file.',
experimentalSourceRewriting: 'Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm.',
experimentalStudio: 'Generate and save commands directly to your test suite by interacting with your app as an end user would.',
}
Expand All @@ -71,7 +70,6 @@ const _summaries: StringValues = {
const _names: StringValues = {
experimentalComponentTesting: 'Component Testing',
experimentalFetchPolyfill: 'Fetch polyfill',
experimentalRunEvents: 'Run Events',
experimentalSourceRewriting: 'Improved source rewriting',
experimentalStudio: 'Studio',
}
Expand Down
31 changes: 7 additions & 24 deletions packages/server/lib/plugins/child/validate_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,25 @@ const isFunction = (event, handler) => {
return validate(_.isFunction, handler, `The handler for the event \`${event}\` must be a function`)
}

const isValidRunEvent = (event, handler, config) => {
if (!config.experimentalRunEvents) {
return createErrorResult(`The \`${event}\` event requires the experimentalRunEvents flag to be enabled.

To enable it, set \`"experimentalRunEvents": true\` in your cypress.json`)
}

return isFunction(event, handler)
}

const isObject = (event, handler) => {
return validate(_.isPlainObject, handler, `The handler for the event \`${event}\` must be an object`)
}

const eventValidators = {
'dev-server:start': isFunction,
'_get:task:body': isFunction,
'_get:task:keys': isFunction,
'after:run': isFunction,
'after:screenshot': isFunction,
'after:spec': isFunction,
'before:browser:launch': isFunction,
'before:run': isFunction,
'before:spec': isFunction,
'dev-server:start': isFunction,
'file:preprocessor': isFunction,
'task': isObject,
'_get:task:keys': isFunction,
'_get:task:body': isFunction,
}

const runEvents = {
'after:run': true,
'after:spec': true,
'before:run': true,
'before:spec': true,
}

const validateEvent = (event, handler, config) => {
if (runEvents[event]) {
return isValidRunEvent(event, handler, config)
}

const validator = eventValidators[event]

if (!validator) {
Expand Down
2 changes: 0 additions & 2 deletions packages/server/lib/plugins/run_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const plugins = require('../plugins')

module.exports = {
execute: Promise.method((eventName, config = {}, ...args) => {
if (!config.experimentalRunEvents) return

if (!plugins.has(eventName)) return

return plugins.execute(eventName, ...args)
Expand Down
12 changes: 0 additions & 12 deletions packages/server/test/e2e/4_plugin_run_events_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ describe('e2e plugin run events', () => {
snapshot: true,
})

e2e.it('fails if experimentalRunEvents is not enabled', {
browser: 'electron',
project: Fixtures.projectPath('plugin-run-events'),
spec: '*',
snapshot: true,
expectedExitCode: 1,
config: {
experimentalRunEvents: false,
video: false,
},
})

e2e.it('fails run if event handler throws', {
browser: 'electron',
project: Fixtures.projectPath('plugin-run-event-throws'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"experimentalRunEvents": true,
"fixturesFolder": false,
"supportFile": false
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"experimentalRunEvents": true,
"fixturesFolder": false,
"supportFile": false
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"experimentalRunEvents": true,
"fixturesFolder": false,
"supportFile": false
}
12 changes: 10 additions & 2 deletions packages/server/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,16 @@ describe('lib/config', () => {
expect(warning).to.be.calledWith('EXPERIMENTAL_SHADOW_DOM_REMOVED')
})

it('warns if experimentalRunEvents is passed', async function () {
const warning = sinon.spy(errors, 'warning')

await this.defaults('experimentalRunEvents', true, {
experimentalRunEvents: true,
})

expect(warning).to.be.calledWith('EXPERIMENTAL_RUN_EVENTS_REMOVED')
})

// @see https://github.com/cypress-io/cypress/pull/9185
it('warns if experimentalNetworkStubbing is passed', async function () {
const warning = sinon.spy(errors, 'warning')
Expand Down Expand Up @@ -1247,7 +1257,6 @@ describe('lib/config', () => {
execTimeout: { value: 60000, from: 'default' },
experimentalComponentTesting: { value: false, from: 'default' },
experimentalFetchPolyfill: { value: false, from: 'default' },
experimentalRunEvents: { value: false, from: 'default' },
experimentalSourceRewriting: { value: false, from: 'default' },
experimentalStudio: { value: false, from: 'default' },
fileServerFolder: { value: '', from: 'default' },
Expand Down Expand Up @@ -1328,7 +1337,6 @@ describe('lib/config', () => {
execTimeout: { value: 60000, from: 'default' },
experimentalComponentTesting: { value: false, from: 'default' },
experimentalFetchPolyfill: { value: false, from: 'default' },
experimentalRunEvents: { value: false, from: 'default' },
experimentalSourceRewriting: { value: false, from: 'default' },
experimentalStudio: { value: false, from: 'default' },
env: {
Expand Down
53 changes: 16 additions & 37 deletions packages/server/test/unit/plugins/child/validate_event_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ const _ = require('lodash')
const validateEvent = require('../../../../lib/plugins/child/validate_event')

const events = [
['after:run', 'a function', () => {}],
['after:screenshot', 'a function', () => {}],
['after:spec', 'a function', () => {}],
['before:browser:launch', 'a function', () => {}],
['before:run', 'a function', () => {}],
['before:spec', 'a function', () => {}],
['dev-server:start', 'a function', () => {}],
['file:preprocessor', 'a function', () => {}],
['before:browser:launch', 'a function', () => {}],
['after:screenshot', 'a function', () => {}],
['task', 'an object', {}],
]

Expand All @@ -21,9 +25,13 @@ describe('lib/plugins/child/validate_event', () => {
You passed: \`undefined\`

The following are valid events:
- dev-server:start
- after:run
- after:screenshot
- after:spec
- before:browser:launch
- before:run
- before:spec
- dev-server:start
- file:preprocessor
- task
`)
Expand All @@ -45,9 +53,13 @@ The following are valid events:
You passed: \`invalid:event:name\`

The following are valid events:
- dev-server:start
- after:run
- after:screenshot
- after:spec
- before:browser:launch
- before:run
- before:spec
- dev-server:start
- file:preprocessor
- task
`)
Expand All @@ -69,37 +81,4 @@ The following are valid events:
expect(isValid).to.be.true
})
})

describe('run events', () => {
const runEvents = [
'after:run',
'before:run',
'before:spec',
'after:spec',
]

_.each(runEvents, (event) => {
it(`returns error when ${event} event is registed without experimentalRunEvents flag enabled`, () => {
const { isValid, error } = validateEvent(event, {}, { experimentalRunEvents: false })

expect(isValid).to.be.false
expect(error.message).to.equal(`The \`${event}\` event requires the experimentalRunEvents flag to be enabled.

To enable it, set \`"experimentalRunEvents": true\` in your cypress.json`)
})

it(`returns error when event handler of ${event} is not a function`, () => {
const { isValid, error } = validateEvent(event, 'invalid type', { experimentalRunEvents: true })

expect(isValid).to.be.false
expect(error.message).to.equal(`The handler for the event \`${event}\` must be a function`)
})

it(`returns success when event handler of ${event} is a function`, () => {
const { isValid } = validateEvent(event, () => {}, { experimentalRunEvents: true })

expect(isValid).to.be.true
})
})
})
})
Loading