-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Add types for cypress-cdp #66237
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
Merged
Merged
Add types for cypress-cdp #66237
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import 'cypress'; | ||
| import 'cypress-cdp'; | ||
|
|
||
| //#region CDP | ||
| // $ExpectType Chainable<void> | ||
| cy.CDP('Console.enable', {}); | ||
|
|
||
| // $ExpectType Chainable<EnableResponse> | ||
| cy.CDP('Debugger.enable', {}); | ||
|
|
||
| // @ts-expect-error | ||
| cy.CDP('Debugger.enable'); | ||
|
|
||
| // @ts-expect-error | ||
| cy.CDP('Non-existent.command', {}); | ||
| //#endregion | ||
|
|
||
| //#region getCDPNodeId | ||
| // $ExpectType Chainable<number> | ||
| cy.getCDPNodeId('body'); | ||
|
|
||
| // @ts-expect-error | ||
| cy.getCDPNodeId(1); | ||
| //#endregion | ||
|
|
||
| //#region hasEventListeners | ||
| // $ExpectType Chainable<GetEventListenersResponse> | ||
| cy.hasEventListeners('button#one'); | ||
|
|
||
| // @ts-expect-error | ||
| cy.hasEventListeners(1); | ||
| //#endregion |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Type definitions for cypress-cdp 1.3 | ||
| // Project: https://github.com/bahmutov/cypress-cdp#readme | ||
| // Definitions by: Anthony Froissant <https://github.com/froissant> | ||
| // Louis Loiseau-Billon <https://github.com/LouisLoiseau> | ||
| // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
|
||
| /// <reference types="cypress" /> | ||
|
|
||
| import type Protocol from 'devtools-protocol/types/protocol'; | ||
| import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping'; | ||
|
|
||
| declare global { | ||
| // Augment the Cypress namespace to include type definitions for cypress-cdp. | ||
| namespace Cypress { | ||
| namespace CDP { | ||
| //#region CDP | ||
| type RdpCommands = ProtocolMapping.Commands; | ||
| type RdpCommandNames = keyof RdpCommands; | ||
|
|
||
| type CdpCommandFnParams<RdpCommandName extends RdpCommandNames> = | ||
| RdpCommands[RdpCommandName]['paramsType'][number] extends never | ||
| ? Record<string, never> | ||
| : RdpCommands[RdpCommandName]['paramsType'][number]; | ||
| type CdpCommandFnReturnType<RdpCommandName extends RdpCommandNames> = | ||
| RdpCommands[RdpCommandName]['returnType']; | ||
| interface CdpCommandFnOptions { | ||
| log: LogConfig; | ||
| } | ||
| type CdpCommandFn = <RdpCommandName extends RdpCommandNames>( | ||
| rdpCommand: RdpCommandName, | ||
| params: CdpCommandFnParams<RdpCommandName>, | ||
| options?: CdpCommandFnOptions, | ||
| ) => Chainable<CdpCommandFnReturnType<RdpCommandName>>; | ||
| //#endregion | ||
|
|
||
| //#region getCDPNodeId | ||
| type getCDPNodeIdFn = (selector: string) => Chainable<number>; | ||
| //#endregion | ||
|
|
||
| //#region hasEventListeners | ||
| interface hasEventListenersFnOptions { | ||
| log: LogConfig; | ||
| type: string; | ||
| } | ||
| type hasEventListenersFn = ( | ||
| selector: string, | ||
| options?: hasEventListenersFnOptions, | ||
| ) => Chainable<Protocol.DOMDebugger.GetEventListenersResponse>; | ||
| //#endregion | ||
| } | ||
|
|
||
| interface Chainable<Subject = any> { | ||
| /** | ||
| * Custom command to send a RDP command to Chrome DevTools. | ||
| * @example | ||
| * const selector = 'button#one' | ||
| * cy.CDP('Runtime.evaluate', { | ||
| * expression: 'frames[0].document.querySelector("' + selector + '")', | ||
| * }).should((v) => { | ||
| * expect(v.result).to.have.property('objectId') | ||
| * }) | ||
| */ | ||
| CDP: CDP.CdpCommandFn; | ||
|
|
||
| /** | ||
| * Custom command to return the internal element's Node Id that can be used to query the run-time properties, for example the rendered font. | ||
| * @example | ||
| * cy.getCDPNodeId('body').then((nodeId) => { | ||
| * cy.CDP('CSS.getPlatformFontsForNode', { | ||
| * nodeId | ||
| * }); | ||
| * }); | ||
| */ | ||
| getCDPNodeId: CDP.getCDPNodeIdFn; | ||
|
|
||
| /** | ||
| * Custom command to get listeners attached to a DOM element. | ||
| * @example | ||
| * cy.hasEventListeners('button#one') | ||
| * @example | ||
| * cy.hasEventListeners('button#one', { type: 'click' }) | ||
| */ | ||
| hasEventListeners: CDP.hasEventListenersFn; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "private": true, | ||
| "dependencies": { | ||
| "cypress": "9.7.0", | ||
| "devtools-protocol": "0.0.1173815" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "lib": [ | ||
| "es6", | ||
| "DOM" | ||
| ], | ||
| "noImplicitAny": true, | ||
| "noImplicitThis": true, | ||
| "strictFunctionTypes": true, | ||
| "strictNullChecks": true, | ||
| "baseUrl": "../", | ||
| "typeRoots": [ | ||
| "../" | ||
| ], | ||
| "types": [], | ||
| "noEmit": true, | ||
| "forceConsistentCasingInFileNames": true | ||
| }, | ||
| "files": [ | ||
| "index.d.ts", | ||
| "cypress-cdp-tests.ts" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { "extends": "@definitelytyped/dtslint/dt.json" } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.