mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-22 23:20:24 -05:00
ab401ecd35
* chore: use import type across repo * chore: use import type across repo * chore: use import type across repo * chore: use import type across repo * update exports * update test * update import type * update types * use import type in driver * correctly export function * revert test * remove unrelated code * revert code * improve type imports * override for reporter
32 lines
843 B
TypeScript
32 lines
843 B
TypeScript
import type net from 'net'
|
|
|
|
/**
|
|
* `allowDestroy` adds a `destroy` method to a `net.Server`. `destroy(cb)`
|
|
* will kill all open connections and call `cb` when the server is closed.
|
|
*
|
|
* Note: `server-destroy` NPM package cannot be used - it does not track
|
|
* `secureConnection` events.
|
|
*/
|
|
export function allowDestroy (server: net.Server) {
|
|
let connections: net.Socket[] = []
|
|
|
|
function trackConn (conn) {
|
|
connections.push(conn)
|
|
|
|
conn.on('close', () => {
|
|
connections = connections.filter((connection) => connection !== conn)
|
|
})
|
|
}
|
|
|
|
server.on('connection', trackConn)
|
|
server.on('secureConnection', trackConn)
|
|
|
|
// @ts-ignore Property 'destroy' does not exist on type 'Server'.
|
|
server.destroy = function (cb) {
|
|
server.close(cb)
|
|
connections.map((connection) => connection.destroy())
|
|
}
|
|
|
|
return server
|
|
}
|