/
index.d.ts
87 lines (78 loc) · 3.04 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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
// copied from https://github.com/DefinitelyTyped/DefinitelyTyped/pull/66237
/// <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
}
}
}