Files
cypress/packages/socket/lib/browser.ts
Jennifer Shehane 92e428a357 chore: add type linting + compilation checks to packages (#30776)
* chore: add type linting + compilation checks to runner package

* empty commit

* A bunch of tslint fixes

* wow it is building

* Fix issue with CT not mounting correctly with comments within it

* Fix net-stubbing.ct.ts failures

* Fix tslint: disable comment

* move target into compilerOptions

* fix tslint disable comment

* update proxy-logging to undo changes

* standardize the tslint:disable comments

* fix comment

* fix the banner content not displaying and write a test for this situation

* fix ct reference

* put target to es2020

* actually set the property with replaced title

* Update packages/reporter/src/hooks/hook-model.ts

Co-authored-by: Ryan Manuel <ryanm@cypress.io>

* Fix eslint/tslint settings for system-tests with vue 3

* bump CI cache

* update types/react resolution

* add return

* lint fix

* tslint disable for empty blocks

* exclude dist files from ts linting

* update to exclude all dist folder

* exclude dist file

* change to await

* fix line numbers of stack trace with linting updating vue file

---------

Co-authored-by: Ryan Manuel <ryanm@cypress.io>
2025-01-23 14:55:52 -05:00

63 lines
2.3 KiB
TypeScript

import io, { ManagerOptions, SocketOptions } from 'socket.io-client'
import { CDPBrowserSocket } from './cdp-browser'
import type { SocketShape } from './types'
export type { Socket } from 'socket.io-client'
declare global {
interface Window {
cypressSockets: {[key: string]: CDPBrowserSocket}
}
}
let chromium = false
export function client (uri: string, opts?: Partial<ManagerOptions & SocketOptions>): SocketShape {
if (chromium) {
const fullNamespace = `${opts?.path}${uri}`
// When running in Chromium and with a baseUrl set to something that includes basic auth: (e.g. http://user:pass@localhost:1234), the assets
// will load twice. Thus, we need to add the cypress sockets to the window object rather than just relying on a local variable.
window.cypressSockets ||= {}
if (!window.cypressSockets[fullNamespace]) {
window.cypressSockets[fullNamespace] = new CDPBrowserSocket(fullNamespace)
}
// Connect the socket regardless of whether or not we have newly created it
window.cypressSockets[fullNamespace].connect()
// @ts-expect-error TODO: fix type
return window.cypressSockets[fullNamespace]
}
return io(uri, opts)
}
export function createWebsocket ({ path, browserFamily }: { path: string, browserFamily: string}): SocketShape {
if (browserFamily === 'chromium') {
chromium = true
const fullNamespace = `${path}/default`
// When running in Chromium and with a baseUrl set to something that includes basic auth: (e.g. http://user:pass@localhost:1234), the assets
// will load twice. Thus, we need to add the cypress sockets to the window object rather than just relying on a local variable.
window.cypressSockets ||= {}
if (!window.cypressSockets[fullNamespace]) {
window.cypressSockets[fullNamespace] = new CDPBrowserSocket(fullNamespace)
}
// Connect the socket regardless of whether or not we have newly created it
window.cypressSockets[fullNamespace].connect()
// @ts-expect-error TODO: fix type
return window.cypressSockets[fullNamespace]
}
return io({
path,
// TODO(webkit): the websocket socket.io transport is busted in WebKit, need polling
// https://github.com/cypress-io/cypress/issues/23807
transports: browserFamily === 'webkit' ? ['polling'] : ['websocket'],
})
}