Files
cypress/packages/server/lib/server-ct.ts
Lachlan Miller 91beb9012c feat: experimental single tab run mode for component testing (#23104)
* revive logic to run CT in a single tab

* add feature flag: experimentalSingleTabRunMode

* remove log

* reset browser state between tests

* document single tab run mode experiment;

* add system test for experimental run mode

* fix snapshots

* use more simple project for testing

* additional guard;

* fix test

* Apply suggestions from code review

Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>

* destroy aut after each spec

* update snapshot

* fix types

* add experiment flag error

* add warning when using experimental flag with e2e

* build binaries for experimentalSingleTabRunMode feature

* build binaries take 2

* make error message more open ended

* destroy AUT later in run mode lifecycle

* add additional assertion around experimental flag

* simplify error

* remove test code from production code

Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
2022-08-16 10:44:14 +10:00

56 lines
1.8 KiB
TypeScript

import Bluebird from 'bluebird'
import httpsProxy from '@packages/https-proxy'
import { OpenServerOptions, ServerBase } from '@packages/server/lib/server-base'
import appData from '@packages/server/lib/util/app_data'
import type { SocketCt } from './socket-ct'
import type { Cfg } from '@packages/server/lib/project-base'
import { graphqlWS } from '@packages/graphql/src/makeGraphQLServer'
type WarningErr = Record<string, any>
export class ServerCt extends ServerBase<SocketCt> {
open (config: Cfg, options: OpenServerOptions) {
return super.open(config, { ...options, testingType: 'component' })
}
createServer (app, config, onWarning): Bluebird<[number, WarningErr?]> {
return new Bluebird((resolve, reject) => {
const { port, baseUrl, socketIoRoute } = config
this._server = this._createHttpServer(app)
this.server.on('connect', this.onConnect.bind(this))
this.server.on('upgrade', (req, socket, head) => this.onUpgrade(req, socket, head, socketIoRoute))
this._graphqlWS = graphqlWS(this.server, `${socketIoRoute}-graphql`)
return this._listen(port, (err) => {
if (err.code === 'EADDRINUSE') {
reject(`Port ${port} is already in use`)
}
reject(err)
})
.then((port) => {
httpsProxy.create(appData.path('proxy'), port, {
onRequest: this.callListeners.bind(this),
onUpgrade: this.onSniUpgrade.bind(this),
})
.then((httpsProxy) => {
this._httpsProxy = httpsProxy
// once we open set the domain to root by default
// which prevents a situation where navigating
// to http sites redirects to /__/ cypress
this._remoteStates.set(baseUrl)
return resolve([port])
})
})
})
}
destroyAut () {
return this.socket.destroyAut()
}
}