Skip to content

Commit

Permalink
breaking: remove deprecated before:browser:launch signature code that…
Browse files Browse the repository at this point in the history
… allowed Arrays (#30460)

* chore: release 13.15.1 (#30454)

* chore: Update Chrome (beta) to 131.0.6778.13 (#30451)

Co-authored-by: cypress-bot[bot] <41898282+cypress-bot[bot]@users.noreply.github.com>

* remove deprecated before:browser:launch signature code

* Update changelog

* Update snapshots & failing tests

BREAKING: remove deprecated before:browser:launch signature code that allowed Arrays

* Add back options

* update test spec to use non deprecated before:browser:launch signature

* removed test for deprecated before:browser:launch signature

---------

Co-authored-by: Bill Glesias <bglesias@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: cypress-bot[bot] <41898282+cypress-bot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 28, 2024
1 parent fd8c2a3 commit 7f6e030
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 715 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _Released 12/3/2024 (PENDING)_

- Removed support for Node.js 16 and Node.js 21. Addresses [#29930](https://github.com/cypress-io/cypress/issues/29930).
- Prebuilt binaries for Linux are no longer compatible with Linux distributions based on glibc <2.28, for example: Ubuntu 14-18, RHEL 7, CentOS 7, Amazon Linux 2. Addresses [#29601](https://github.com/cypress-io/cypress/issues/29601).
- We removed yielding the second argument of `before:browser:launch` as an array of browser arguments. This behavior has been deprecated since Cypress 4.0.0. Addressed in [#30460](https://github.com/cypress-io/cypress/pull/30460).
- The `cypress open-ct` and `cypress run-ct` CLI commands were removed. Please use `cypress open --component` or `cypress run --component` respectively instead. Addressed in [#30456](https://github.com/cypress-io/cypress/pull/30456)
- The undocumented methods `Cypress.backend('firefox:force:gc')` and `Cypress.backend('log:memory:pressure')` were removed. Addresses [#30222](https://github.com/cypress-io/cypress/issues/30222).

Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions packages/errors/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,6 @@ export const AllCypressErrors = {
https://on.cypress.io/auto-cancellation-mismatch`
},
DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS: () => {
return errTemplate`\
Deprecation Warning: The ${fmt.highlight(`before:browser:launch`)} plugin event changed its signature in ${fmt.cypressVersion(`4.0.0`)}
The event switched from yielding the second argument as an ${fmt.highlightSecondary(`array`)} of browser arguments to an options ${fmt.highlightSecondary(`object`)} with an ${fmt.highlightSecondary(`args`)} property.
We've detected that your code is still using the previous, deprecated interface signature.
This code will not work in a future version of Cypress. Please see the upgrade guide: https://on.cypress.io/deprecated-before-browser-launch-args`
},
DUPLICATE_TASK_KEY: (arg1: string[]) => {
return errTemplate`\
Warning: Multiple attempts to register the following task(s):
Expand Down
5 changes: 0 additions & 5 deletions packages/errors/test/unit/visualSnapshotErrors_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,6 @@ describe('visual error templates', () => {
}],
}
},
DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS: () => {
return {
default: [],
}
},
DUPLICATE_TASK_KEY: () => {
const tasks = ['foo', 'bar', 'baz']

Expand Down
1 change: 0 additions & 1 deletion packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,6 @@ enum ErrorTypeEnum {
CONFIG_VALIDATION_MSG_ERROR
COULD_NOT_PARSE_ARGUMENTS
DEFAULT_SUPPORT_FILE_NOT_FOUND
DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS
DEV_SERVER_CONFIG_FILE_NOT_FOUND
DUPLICATE_TASK_KEY
ERROR_READING_FILE
Expand Down
44 changes: 12 additions & 32 deletions packages/server/lib/browsers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable no-redeclare */
import Bluebird from 'bluebird'
import _ from 'lodash'
import type { BrowserLaunchOpts, FoundBrowser } from '@packages/types'
import type { FoundBrowser } from '@packages/types'
import * as errors from '../errors'
import * as plugins from '../plugins'
import { getError } from '@packages/errors'
import * as launcher from '@packages/launcher'
import type { Automation } from '../automation'
import type { Browser } from './types'
Expand Down Expand Up @@ -179,36 +178,17 @@ async function executeAfterBrowserLaunch (browser: Browser, options: AfterBrowse
}
}

function extendLaunchOptionsFromPlugins (launchOptions, pluginConfigResult, options: BrowserLaunchOpts) {
// if we returned an array from the plugin
// then we know the user is using the deprecated
// interface and we need to warn them
// TODO: remove this logic in >= v5.0.0
if (pluginConfigResult[0]) {
// eslint-disable-next-line no-console
(options.onWarning || console.warn)(getError(
'DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS',
))

_.extend(pluginConfigResult, {
args: _.filter(pluginConfigResult, (_val, key) => {
return _.isNumber(key)
}),
extensions: [],
})
} else {
// either warn about the array or potentially error on invalid props, but not both

// strip out all the known launch option properties from the resulting object
const unexpectedProperties: string[] = _
.chain(pluginConfigResult)
.omit(KNOWN_LAUNCH_OPTION_PROPERTIES)
.keys()
.value()

if (unexpectedProperties.length) {
errors.throwErr('UNEXPECTED_BEFORE_BROWSER_LAUNCH_PROPERTIES', unexpectedProperties, KNOWN_LAUNCH_OPTION_PROPERTIES)
}
function extendLaunchOptionsFromPlugins (launchOptions, pluginConfigResult, options) {
// strip out all the known launch option properties from the resulting object
const unexpectedProperties: string[] = _
.chain(pluginConfigResult)
.omit(KNOWN_LAUNCH_OPTION_PROPERTIES)
.keys()
.value()

if (unexpectedProperties.length) {
// error on invalid props
errors.throwErr('UNEXPECTED_BEFORE_BROWSER_LAUNCH_PROPERTIES', unexpectedProperties, KNOWN_LAUNCH_OPTION_PROPERTIES)
}

_.forEach(launchOptions, (val, key) => {
Expand Down
37 changes: 0 additions & 37 deletions packages/server/lib/plugins/child/browser_launch.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
const util = require('../util')

const ARRAY_METHODS = ['concat', 'push', 'unshift', 'slice', 'pop', 'shift', 'slice', 'splice', 'filter', 'map', 'forEach', 'reduce', 'reverse', 'splice', 'includes']

module.exports = {
wrapBefore (ipc, invoke, ids, args) {
// TODO: remove in next breaking release
// This will send a warning message when a deprecated API is used
// define array-like functions on this object so we can warn about using deprecated array API
// while still fulfilling desired behavior
const [, launchOptions] = args

let hasEmittedWarning = false

ARRAY_METHODS.forEach((name) => {
const boundFn = launchOptions.args[name].bind(launchOptions.args)

launchOptions[name] = function () {
if (hasEmittedWarning) return

hasEmittedWarning = true

const warning = require('@packages/errors').getError(
'DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS',
)

ipc.send('warning', util.serializeError(warning))

// eslint-disable-next-line prefer-rest-params
return boundFn.apply(this, arguments)
}
})

Object.defineProperty(launchOptions, 'length', {
get () {
return this.args.length
},
})

launchOptions[Symbol.iterator] = launchOptions.args[Symbol.iterator].bind(launchOptions.args)

util.wrapChildPromise(ipc, invoke, ids, args)
},
}
15 changes: 0 additions & 15 deletions packages/server/test/unit/browsers/browsers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,6 @@ describe('lib/browsers/index', () => {
// this error is snapshotted in an e2e test, no need to do it here
expect(fn).to.throw({ type: 'UNEXPECTED_BEFORE_BROWSER_LAUNCH_PROPERTIES' })
})

it('warns if array passed and changes it to args', () => {
const onWarning = sinon.stub()

const result = utils.extendLaunchOptionsFromPlugins({ args: [] }, ['foo'], { onWarning })

expect(result).to.deep.eq({
args: ['foo'],
})

// this error is snapshotted in e2e tests, no need to do it here
expect(onWarning).to.be.calledOnce

expect(onWarning).to.be.calledWithMatch({ type: 'DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS' })
})
})

context('.getMajorVersion', () => {
Expand Down
24 changes: 0 additions & 24 deletions packages/server/test/unit/browsers/chrome_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,30 +224,6 @@ describe('lib/browsers/chrome', () => {
})
})

it('DEPRECATED: normalizes --load-extension if provided in plugin', function () {
plugins.registerEvent('before:browser:launch', (browser, config) => {
return Promise.resolve(['--foo=bar', '--load-extension=/foo/bar/baz.js'])
})

const pathToTheme = extension.getPathToTheme()

const onWarning = sinon.stub()

return chrome.open({ isHeaded: true }, 'http://', { onWarning, onError: () => {} }, this.automation)
.then(() => {
const args = launch.launch.firstCall.args[3]

expect(args).to.deep.eq([
'--foo=bar',
`--load-extension=/foo/bar/baz.js,/path/to/ext,${pathToTheme}`,
'--user-data-dir=/profile/dir',
'--disk-cache-dir=/profile/dir/CypressCache',
])

expect(onWarning).calledOnce
})
})

it('normalizes --load-extension if provided in plugin', function () {
plugins.registerEvent('before:browser:launch', (browser, config) => {
return Promise.resolve({
Expand Down
Loading

2 comments on commit 7f6e030

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7f6e030 Oct 28, 2024

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.0/linux-x64/release/14.0.0-7f6e0309a043964ff59b379d8aacd88819195151/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7f6e030 Oct 28, 2024

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.0/linux-arm64/release/14.0.0-7f6e0309a043964ff59b379d8aacd88819195151/cypress.tgz

Please sign in to comment.