mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-12 02:00:06 -06:00
* Refactor connection logic to cri-connection
CDPConnection class instantiates a persistent event emitter, and creates
a CDP Client instance via connect(). When this client emits a disconnect
event, the CDPConnection will automatically attempt to reconnect, if the
connection was not intentionally closed and the connection is created with
the reconnect flag. It only listens to 'event' and 'disconnect' events itself,
making it easy to unsubscribe from events in the event of a disconnection,
helping ease mental load when considering potential memory leaks.
Because it uses its own persistent event emitter, event listeners added
to the CDPConnection do not need to be re-added when the client reconnects.
The CriClient itself no longer handles reconnection logic: it only reacts to
connection state changes in order to re-send failed commands and enablements
when the CDPConnection restores the CDPClient.
* changelog
* clean up event listeners before reconnecting
* changelog
* changelog
* changelog
* unit tests
* lift out of the remote-interface dir
* complete lift from /remote-interface
* further fix imports
* import
* fix disconnect behavior to make integration test pass
* Update packages/server/test/integration/cdp_spec.ts comment
* fix snapgen
* improve debug
* further debug improvements
* do not attach crash handlers on browser level cri clients, add tests
* adds bindingCalled listeners discretely, rather than relying on 'event', which does not trigger for them
* back out of main `event` listener, use discrete listeners, add integration test for service worker bindingCalled
* Revert "back out of main `event` listener, use discrete listeners, add integration test for service worker bindingCalled"
This reverts commit 4855120d42.
* changelog
* adds integration test for various ways to add cdp event listeners
* note in changelog this is a cypress server fix
* ensure enablement promises resolve after reconnect
* Update cli/CHANGELOG.md
Co-authored-by: Matt Schile <mschile@cypress.io>
---------
Co-authored-by: Matt Schile <mschile@cypress.io>
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
const Kinds = Object.freeze({
|
|
CDP_CRASHED: 'cdp_crashed',
|
|
CDP_DISCONNECTED: 'cdp_disconnected',
|
|
CDP_TERMINATED: 'cdp_terminated',
|
|
CDP_ALREADY_CONNECTED: 'cdp_already_connected',
|
|
})
|
|
|
|
type CdpErrorKind = typeof Kinds[keyof typeof Kinds]
|
|
|
|
type MaybeCdpError = Error & { kind?: CdpErrorKind }
|
|
|
|
export class CDPCrashedError extends Error {
|
|
public readonly kind = Kinds.CDP_CRASHED
|
|
|
|
public static isCDPCrashedError (error: MaybeCdpError): error is CDPCrashedError {
|
|
return error.kind === Kinds.CDP_CRASHED
|
|
}
|
|
}
|
|
|
|
export class CDPDisconnectedError extends Error {
|
|
public readonly kind = Kinds.CDP_DISCONNECTED
|
|
|
|
constructor (message: string, public readonly originalError?: Error) {
|
|
super(message)
|
|
}
|
|
|
|
public static isCDPDisconnectedError (error: MaybeCdpError): error is CDPDisconnectedError {
|
|
return error.kind === Kinds.CDP_DISCONNECTED
|
|
}
|
|
}
|
|
|
|
export class CDPTerminatedError extends Error {
|
|
public readonly kind = Kinds.CDP_TERMINATED
|
|
|
|
constructor (message: string, public readonly originalError?: Error) {
|
|
super(message)
|
|
}
|
|
|
|
public static isCDPTerminatedError (error: MaybeCdpError): error is CDPTerminatedError {
|
|
return error.kind === Kinds.CDP_TERMINATED
|
|
}
|
|
}
|
|
|
|
export class CDPAlreadyConnectedError extends Error {
|
|
public readonly kind = Kinds.CDP_ALREADY_CONNECTED
|
|
|
|
constructor (message: string, public readonly originalError?: Error) {
|
|
super(message)
|
|
}
|
|
|
|
public static isCDPAlreadyConnectedError (error: MaybeCdpError): error is CDPAlreadyConnectedError {
|
|
return error.kind === Kinds.CDP_ALREADY_CONNECTED
|
|
}
|
|
}
|