mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-07 07:20:42 -05:00
feat: defer protocol manager initialization to after script load (#27347)
This commit is contained in:
@@ -19,8 +19,9 @@ import * as enc from './encryption'
|
||||
import getEnvInformationForProjectRoot from './environment'
|
||||
|
||||
import type { OptionsWithUrl } from 'request-promise'
|
||||
import type { ProtocolManagerShape } from '@packages/types'
|
||||
import { fs } from '../util/fs'
|
||||
import ProtocolManager from './protocol'
|
||||
import type { ProjectBase } from '../project-base'
|
||||
|
||||
const THIRTY_SECONDS = humanInterval('30 seconds')
|
||||
const SIXTY_SECONDS = humanInterval('60 seconds')
|
||||
@@ -250,7 +251,7 @@ export type CreateRunOptions = {
|
||||
tags: string[]
|
||||
testingType: 'e2e' | 'component'
|
||||
timeout?: number
|
||||
protocolManager?: ProtocolManagerShape
|
||||
project: ProjectBase<any>
|
||||
}
|
||||
|
||||
type CreateRunResponse = {
|
||||
@@ -379,17 +380,20 @@ module.exports = {
|
||||
})
|
||||
})
|
||||
.then(async (result: CreateRunResponse) => {
|
||||
let protocolManager = new ProtocolManager()
|
||||
|
||||
try {
|
||||
if (options.protocolManager && (result.captureProtocolUrl || process.env.CYPRESS_LOCAL_PROTOCOL_PATH)) {
|
||||
if (result.captureProtocolUrl || process.env.CYPRESS_LOCAL_PROTOCOL_PATH) {
|
||||
const script = await this.getCaptureProtocolScript(result.captureProtocolUrl || process.env.CYPRESS_LOCAL_PROTOCOL_PATH)
|
||||
|
||||
if (script) {
|
||||
await options.protocolManager.setupProtocol(script, result.runId)
|
||||
options.project.protocolManager = protocolManager
|
||||
await options.project.protocolManager.setupProtocol(script, result.runId)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (CAPTURE_ERRORS) {
|
||||
options.protocolManager?.sendErrors([
|
||||
await protocolManager.sendErrors([
|
||||
{
|
||||
args: [result.captureProtocolUrl],
|
||||
captureMethod: 'getCaptureProtocolScript',
|
||||
|
||||
@@ -344,7 +344,7 @@ const createRun = Promise.method((options = {}) => {
|
||||
ciBuildId: null,
|
||||
})
|
||||
|
||||
let { projectRoot, projectId, recordKey, platform, git, specPattern, specs, parallel, ciBuildId, group, tags, testingType, autoCancelAfterFailures, protocolManager } = options
|
||||
let { projectRoot, projectId, recordKey, platform, git, specPattern, specs, parallel, ciBuildId, group, tags, testingType, autoCancelAfterFailures, project } = options
|
||||
|
||||
if (recordKey == null) {
|
||||
recordKey = env.get('CYPRESS_RECORD_KEY')
|
||||
@@ -401,7 +401,7 @@ const createRun = Promise.method((options = {}) => {
|
||||
ci,
|
||||
commit,
|
||||
autoCancelAfterFailures,
|
||||
protocolManager,
|
||||
project,
|
||||
})
|
||||
.tap((response) => {
|
||||
if (!(response && response.warnings && response.warnings.length)) {
|
||||
@@ -675,7 +675,6 @@ const createRunAndRecordSpecs = (options = {}) => {
|
||||
testingType,
|
||||
quiet,
|
||||
autoCancelAfterFailures,
|
||||
protocolManager,
|
||||
} = options
|
||||
const recordKey = options.key
|
||||
|
||||
@@ -711,7 +710,7 @@ const createRunAndRecordSpecs = (options = {}) => {
|
||||
testingType,
|
||||
configFile: config ? config.configFile : null,
|
||||
autoCancelAfterFailures,
|
||||
protocolManager,
|
||||
project,
|
||||
})
|
||||
.then((resp) => {
|
||||
if (!resp) {
|
||||
@@ -806,7 +805,7 @@ const createRunAndRecordSpecs = (options = {}) => {
|
||||
screenshots,
|
||||
videoUploadUrl,
|
||||
captureUploadUrl,
|
||||
protocolManager,
|
||||
protocolManager: project.protocolManager,
|
||||
screenshotUploadUrls,
|
||||
quiet,
|
||||
})
|
||||
|
||||
@@ -25,7 +25,7 @@ import type { SpecWithRelativeRoot, SpecFile, TestingType, OpenProjectLaunchOpts
|
||||
import type { Cfg } from '../project-base'
|
||||
import type { Browser } from '../browsers/types'
|
||||
import * as printResults from '../util/print-run'
|
||||
import { ProtocolManager } from '../cloud/protocol'
|
||||
import type { ProtocolManager } from '../cloud/protocol'
|
||||
import { telemetry } from '@packages/telemetry'
|
||||
|
||||
type SetScreenshotMetadata = (data: TakeScreenshotProps) => void
|
||||
@@ -1067,16 +1067,8 @@ async function ready (options: { projectRoot: string, record: boolean, key: stri
|
||||
errors.throwErr('UNSUPPORTED_BROWSER_VERSION', browser.warning)
|
||||
}
|
||||
|
||||
let protocolManager: ProtocolManager | undefined
|
||||
|
||||
if (browser.family === 'chromium') {
|
||||
chromePolicyCheck.run(onWarning)
|
||||
|
||||
if (record) {
|
||||
protocolManager = new ProtocolManager()
|
||||
|
||||
project.setProtocolManager(protocolManager)
|
||||
}
|
||||
}
|
||||
|
||||
async function runAllSpecs ({ beforeSpecRun, afterSpecRun, runUrl, parallel }: { beforeSpecRun?: BeforeSpecRun, afterSpecRun?: AfterSpecRun, runUrl?: string, parallel?: boolean }) {
|
||||
@@ -1108,7 +1100,7 @@ async function ready (options: { projectRoot: string, record: boolean, key: stri
|
||||
testingType: options.testingType,
|
||||
exit: options.exit,
|
||||
webSecurity: options.webSecurity,
|
||||
protocolManager,
|
||||
protocolManager: project.protocolManager,
|
||||
})
|
||||
|
||||
if (!options.quiet) {
|
||||
@@ -1142,7 +1134,6 @@ async function ready (options: { projectRoot: string, record: boolean, key: stri
|
||||
runAllSpecs,
|
||||
onError,
|
||||
quiet: options.quiet,
|
||||
protocolManager,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,10 @@ import { SocketE2E } from './socket-e2e'
|
||||
import { ensureProp } from './util/class-helpers'
|
||||
|
||||
import system from './util/system'
|
||||
import type { BannersState, FoundBrowser, FoundSpec, OpenProjectLaunchOptions, ReceivedCypressOptions, ResolvedConfigurationOptions, TestingType, VideoRecording, ProtocolManagerShape } from '@packages/types'
|
||||
import type { BannersState, FoundBrowser, FoundSpec, OpenProjectLaunchOptions, ReceivedCypressOptions, ResolvedConfigurationOptions, TestingType, VideoRecording } from '@packages/types'
|
||||
import { DataContext, getCtx } from '@packages/data-context'
|
||||
import { createHmac } from 'crypto'
|
||||
import type ProtocolManager from './cloud/protocol'
|
||||
|
||||
export interface Cfg extends ReceivedCypressOptions {
|
||||
projectId?: string
|
||||
@@ -59,7 +60,7 @@ export class ProjectBase<TServer extends Server> extends EE {
|
||||
protected _cfg?: Cfg
|
||||
protected _server?: TServer
|
||||
protected _automation?: Automation
|
||||
private _protocolManager?: ProtocolManagerShape
|
||||
private _protocolManager?: ProtocolManager
|
||||
private _recordTests?: any = null
|
||||
private _isServerOpen: boolean = false
|
||||
|
||||
@@ -427,7 +428,11 @@ export class ProjectBase<TServer extends Server> extends EE {
|
||||
this.browser = browser
|
||||
}
|
||||
|
||||
setProtocolManager (protocolManager: ProtocolManagerShape) {
|
||||
get protocolManager (): ProtocolManager | undefined {
|
||||
return this._protocolManager
|
||||
}
|
||||
|
||||
set protocolManager (protocolManager: ProtocolManager | undefined) {
|
||||
this._protocolManager = protocolManager
|
||||
|
||||
this._server?.setProtocolManager(protocolManager)
|
||||
|
||||
@@ -182,7 +182,7 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
|
||||
return this._remoteStates
|
||||
}
|
||||
|
||||
setProtocolManager (protocolManager: ProtocolManagerShape) {
|
||||
setProtocolManager (protocolManager: ProtocolManagerShape | undefined) {
|
||||
this._protocolManager = protocolManager
|
||||
|
||||
this._socket?.setProtocolManager(protocolManager)
|
||||
|
||||
@@ -628,7 +628,7 @@ export class SocketBase {
|
||||
return this.toRunner('update:telemetry:context', context)
|
||||
}
|
||||
|
||||
setProtocolManager (protocolManager: ProtocolManagerShape) {
|
||||
setProtocolManager (protocolManager: ProtocolManagerShape | undefined) {
|
||||
this._protocolManager = protocolManager
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,9 +580,19 @@ describe('lib/cloud/api', () => {
|
||||
captureProtocolUrl: 'http://localhost:1234/capture-protocol/script/protocolStub.js',
|
||||
})
|
||||
|
||||
const protocolManager = this.protocolManager
|
||||
const project = {
|
||||
set protocolManager (val) {
|
||||
// don't override with the setter so that the protocol manager is always the same
|
||||
},
|
||||
get protocolManager () {
|
||||
return protocolManager
|
||||
},
|
||||
}
|
||||
|
||||
return api.createRun({
|
||||
...this.buildProps,
|
||||
protocolManager: this.protocolManager,
|
||||
project,
|
||||
})
|
||||
.then((ret) => {
|
||||
expect(ret).to.deep.eq({
|
||||
@@ -627,9 +637,19 @@ describe('lib/cloud/api', () => {
|
||||
}))
|
||||
}))
|
||||
|
||||
const protocolManager = this.protocolManager
|
||||
const project = {
|
||||
set protocolManager (val) {
|
||||
// don't override with the setter so that the protocol manager is always the same
|
||||
},
|
||||
get protocolManager () {
|
||||
return protocolManager
|
||||
},
|
||||
}
|
||||
|
||||
return api.createRun({
|
||||
...this.buildProps,
|
||||
protocolManager: this.protocolManager,
|
||||
project,
|
||||
})
|
||||
.then((ret) => {
|
||||
expect(ret).to.deep.eq({
|
||||
|
||||
@@ -285,6 +285,7 @@ describe('lib/modes/record', () => {
|
||||
const tag = 'nightly,develop'
|
||||
const testingType = 'e2e'
|
||||
const autoCancelAfterFailures = 4
|
||||
const project = {}
|
||||
|
||||
return recordMode.createRunAndRecordSpecs({
|
||||
key,
|
||||
@@ -301,6 +302,7 @@ describe('lib/modes/record', () => {
|
||||
tag,
|
||||
testingType,
|
||||
autoCancelAfterFailures,
|
||||
project,
|
||||
})
|
||||
.then(() => {
|
||||
expect(commitInfo.commitInfo).to.be.calledWith(projectRoot)
|
||||
@@ -339,7 +341,7 @@ describe('lib/modes/record', () => {
|
||||
},
|
||||
tags: ['nightly', 'develop'],
|
||||
autoCancelAfterFailures: 4,
|
||||
protocolManager: undefined,
|
||||
project,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -226,9 +226,9 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
|
||||
|
||||
context('#getConfig', () => {
|
||||
it('returns the enabled state of the protocol manager if it is defined', function () {
|
||||
this.project.setProtocolManager({
|
||||
this.project.protocolManager = {
|
||||
protocolEnabled: true,
|
||||
})
|
||||
}
|
||||
|
||||
const config = this.project.getConfig()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user