Skip to content

Commit

Permalink
misc: ensure 'its' function type excludes null and undefined (#28872) (
Browse files Browse the repository at this point in the history
…#28904)

* refactor: ensure 'its' function type excludes null and undefined (#28872)

This fix addresses an issue where the 'its' function could return null or undefined, causing unexpected behavior in certain scenarios. The change introduces a more robust type check to ensure that the returned value is always non-null and non-undefined.

* resolve linting issues related to TypeScript types

* Update changelog

* resolved lint errors

* Update cli/types/cypress.d.ts

Co-authored-by: Ryan Manuel <ryanm@cypress.io>

* Update cli/types/cypress.d.ts

* move to correct changelog entry

---------

Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
  • Loading branch information
3 people authored Apr 23, 2024
1 parent 8db1b23 commit 45cff01
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 124 deletions.
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ _Released 4/23/2024 (PENDING)_
- Fixed a bug introduced in [`13.6.0`](https://docs.cypress.io/guides/references/changelog#13-6-0) where Cypress would occasionally exit with status code 1, even when a test run was successfully, due to an unhandled WebSocket exception (`Error: WebSocket connection closed`). Addresses [#28523](https://github.com/cypress-io/cypress/issues/28523).
- Fixed an issue where Cypress would hang on some commands when an invalid `timeout` option was provided. Fixes [#29323](https://github.com/cypress-io/cypress/issues/29323).

**Misc:**

- `.its()` type now excludes null and undefined. Fixes [#28872](https://github.com/cypress-io/cypress/issues/28872).

**Dependency Updates:**

- Updated zod from `3.20.3` to `3.22.5`. Addressed in [#29367](https://github.com/cypress-io/cypress/pull/29367).
Expand Down
48 changes: 24 additions & 24 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,13 @@ declare namespace Cypress {
* Add a custom parent command
* @see https://on.cypress.io/api/commands#Parent-Commands
*/
add<T extends keyof Chainable>(name: T, options: CommandOptions & {prevSubject: false}, fn: CommandFn<T>): void
add<T extends keyof Chainable>(name: T, options: CommandOptions & { prevSubject: false }, fn: CommandFn<T>): void

/**
* Add a custom child command
* @see https://on.cypress.io/api/commands#Child-Commands
*/
add<T extends keyof Chainable, S = any>(name: T, options: CommandOptions & {prevSubject: true}, fn: CommandFnWithSubject<T, S>): void
add<T extends keyof Chainable, S = any>(name: T, options: CommandOptions & { prevSubject: true }, fn: CommandFnWithSubject<T, S>): void

/**
* Add a custom child or dual command
Expand Down Expand Up @@ -627,7 +627,7 @@ declare namespace Cypress {
* Add one or more custom parent commands
* @see https://on.cypress.io/api/commands#Parent-Commands
*/
addAll<T extends keyof Chainable>(options: CommandOptions & {prevSubject: false}, fns: CommandFns): void
addAll<T extends keyof Chainable>(options: CommandOptions & { prevSubject: false }, fns: CommandFns): void

/**
* Add one or more custom child commands
Expand Down Expand Up @@ -822,7 +822,7 @@ declare namespace Cypress {
* Trigger action
* @private
*/
action: <T = (any[] | void)>(action: string, ...args: any[]) => T
action: <T = (any[] | void) >(action: string, ...args: any[]) => T

/**
* Load files
Expand All @@ -834,8 +834,8 @@ declare namespace Cypress {
type CanReturnChainable = void | Chainable | Promise<unknown>
type ThenReturn<S, R> =
R extends void ? Chainable<S> :
R extends R | undefined ? Chainable<S | Exclude<R, undefined>> :
Chainable<S>
R extends R | undefined ? Chainable<S | Exclude<R, undefined>> :
Chainable<S>

/**
* Chainable interface for non-array Subjects
Expand Down Expand Up @@ -950,7 +950,7 @@ declare namespace Cypress {
*
* @see https://on.cypress.io/clearallcookies
*/
clearAllCookies(options?: Partial<Loggable & Timeoutable>): Chainable<null>
clearAllCookies(options?: Partial<Loggable & Timeoutable>): Chainable<null>

/**
* Get local storage for all origins.
Expand Down Expand Up @@ -983,7 +983,7 @@ declare namespace Cypress {
*
* @see https://on.cypress.io/clearallsessionstorage
*/
clearAllSessionStorage(options?: Partial<Loggable>): Chainable<null>
clearAllSessionStorage(options?: Partial<Loggable>): Chainable<null>

/**
* Clear data in local storage for the current origin.
Expand Down Expand Up @@ -1518,7 +1518,7 @@ declare namespace Cypress {
* // Drill into nested properties by using dot notation
* cy.wrap({foo: {bar: {baz: 1}}}).its('foo.bar.baz')
*/
its<K extends keyof Subject>(propertyName: K, options?: Partial<Loggable & Timeoutable>): Chainable<Subject[K]>
its<K extends keyof Subject>(propertyName: K, options?: Partial<Loggable & Timeoutable>): Chainable<NonNullable<Subject[K]>>
its(propertyPath: string, options?: Partial<Loggable & Timeoutable>): Chainable

/**
Expand Down Expand Up @@ -2542,8 +2542,8 @@ declare namespace Cypress {

type ChainableMethods<Subject = any> = {
[P in keyof Chainable<Subject>]: Chainable<Subject>[P] extends ((...args: any[]) => any)
? Chainable<Subject>[P]
: never
? Chainable<Subject>[P]
: never
}

interface SinonSpyAgent<A extends sinon.SinonSpy> {
Expand Down Expand Up @@ -3244,7 +3244,7 @@ declare namespace Cypress {
/**
* Hosts mappings to IP addresses.
*/
hosts: null | {[key: string]: string}
hosts: null | { [key: string]: string }
/**
* Whether Cypress was launched via 'cypress open' (interactive mode)
*/
Expand Down Expand Up @@ -3519,7 +3519,7 @@ declare namespace Cypress {
type DevServerFn<ComponentDevServerOpts = any> = (cypressDevServerConfig: DevServerConfig, devServerConfig: ComponentDevServerOpts) => ResolvedDevServerConfig | Promise<ResolvedDevServerConfig>

type ConfigHandler<T> = T
| (() => T | Promise<T>)
| (() => T | Promise<T>)

type DevServerConfigOptions = {
bundler: 'webpack'
Expand Down Expand Up @@ -3561,7 +3561,7 @@ declare namespace Cypress {
/**
* Hosts mappings to IP addresses.
*/
hosts?: null | {[key: string]: string}
hosts?: null | { [key: string]: string }
}

interface PluginConfigOptions extends ResolvedConfigOptions, RuntimeConfigOptions {
Expand Down Expand Up @@ -3759,7 +3759,7 @@ declare namespace Cypress {
validate?: SessionOptions['validate']
}

interface ServerSessionData extends Omit<SessionData, 'setup' |'validate'> {
interface ServerSessionData extends Omit<SessionData, 'setup' | 'validate'> {
setup: string
validate?: string
}
Expand Down Expand Up @@ -6406,15 +6406,15 @@ declare namespace Cypress {
}

type TypedArray =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array

type FileReference = string | BufferType | FileReferenceObject | TypedArray
interface FileReferenceObject {
Expand Down
Loading

5 comments on commit 45cff01

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 45cff01 Apr 23, 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/13.8.1/linux-arm64/develop-45cff01df702ff6b5b4c6962c8a7bfc38d133e92/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 45cff01 Apr 23, 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/13.8.1/linux-x64/develop-45cff01df702ff6b5b4c6962c8a7bfc38d133e92/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 45cff01 Apr 23, 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 win32 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/13.8.1/win32-x64/develop-45cff01df702ff6b5b4c6962c8a7bfc38d133e92/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 45cff01 Apr 23, 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 darwin 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/13.8.1/darwin-arm64/develop-45cff01df702ff6b5b4c6962c8a7bfc38d133e92/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 45cff01 Apr 23, 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 darwin 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/13.8.1/darwin-x64/develop-45cff01df702ff6b5b4c6962c8a7bfc38d133e92/cypress.tgz

Please sign in to comment.