Files
cypress/packages/server/lib/socket-ct.ts
T
Tim Griesser d2ef2c1393 feat: capture protocol delivery (#26421)
Co-authored-by: Matt Schile <mschile@cypress.io>
Co-authored-by: David Rowe <95636404+davidr-cy@users.noreply.github.com>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
2023-05-15 14:06:27 -05:00

47 lines
1.4 KiB
TypeScript

import Debug from 'debug'
import devServer from '@packages/server/lib/plugins/dev-server'
import { SocketBase } from '@packages/server/lib/socket-base'
import dfd from 'p-defer'
import type { Socket } from '@packages/socket'
import type { DestroyableHttpServer } from '@packages/server/lib/util/server_destroy'
import assert from 'assert'
import type { ProtocolManagerShape } from '@packages/types'
const debug = Debug('cypress:server:socket-ct')
export class SocketCt extends SocketBase {
#destroyAutPromise?: dfd.DeferredPromise<void>
constructor (config: Record<string, any>, protocolManager?: ProtocolManagerShape) {
super(config, protocolManager)
// should we use this option at all for component testing 😕?
if (config.watchForFileChanges) {
devServer.emitter.on('dev-server:compile:success', ({ specFile }) => {
this.toRunner('dev-server:compile:success', { specFile })
})
}
}
startListening (server: DestroyableHttpServer, automation, config, options) {
return super.startListening(server, automation, config, options, {
onSocketConnection: (socket: Socket) => {
debug('do onSocketConnection')
socket.on('aut:destroy:complete', () => {
assert(this.#destroyAutPromise)
this.#destroyAutPromise.resolve()
})
},
})
}
destroyAut () {
this.#destroyAutPromise = dfd()
this.toRunner('aut:destroy:init')
return this.#destroyAutPromise.promise
}
}