From ddaa21478dbd64cef9ebe7e3f4dfaf7da1f2a627 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Wed, 21 Jul 2021 12:36:04 +1000 Subject: [PATCH] simplify object passed to createRoutes --- packages/server-ct/src/routes-ct.ts | 13 +++++++------ packages/server-ct/src/runner-ct.ts | 4 ++-- packages/server-ct/src/server-ct.ts | 2 +- packages/server/lib/controllers/runner.js | 6 +++--- packages/server/lib/project-base.ts | 4 ++-- packages/server/lib/routes.ts | 12 ++++++------ packages/server/lib/server-base.ts | 13 ++++++------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/server-ct/src/routes-ct.ts b/packages/server-ct/src/routes-ct.ts index eb7fd2b2e8..ceb53b5962 100644 --- a/packages/server-ct/src/routes-ct.ts +++ b/packages/server-ct/src/routes-ct.ts @@ -6,9 +6,9 @@ import { NetworkProxy } from '@packages/proxy' import { handle, serve, serveChunk } from './runner-ct' import xhrs from '@packages/server/lib/controllers/xhrs' import { SpecsStore } from '@packages/server/lib/specs-store' -import { Cfg } from '../../server/lib/project-base' +import { Cfg } from '@packages/server/lib/project-base' import { getPathToDist } from '@packages/resolve-dist' -import { Browser } from '../../launcher' +import { Browser } from '@packages/launcher' const debug = Debug('cypress:server:routes') @@ -16,8 +16,8 @@ export interface InitializeRoutes { app: Express specsStore: SpecsStore config: Cfg - spec: Cypress.Cypress['spec'] | null - browser: Browser + getSpec: () => Cypress.Cypress['spec'] | null + getCurrentBrowser: () => Browser nodeProxy: httpProxy networkProxy: NetworkProxy getRemoteState: () => any @@ -30,7 +30,8 @@ export const createRoutes = ({ specsStore, nodeProxy, networkProxy, - browser, + getCurrentBrowser, + getSpec, }: InitializeRoutes) => { app.get('/__cypress/runner/*', handle) @@ -90,7 +91,7 @@ export const createRoutes = ({ serve(req, res, { config, - browser, + getCurrentBrowser, specsStore, }) }) diff --git a/packages/server-ct/src/runner-ct.ts b/packages/server-ct/src/runner-ct.ts index 42e91874bf..3e381968f3 100644 --- a/packages/server-ct/src/runner-ct.ts +++ b/packages/server-ct/src/runner-ct.ts @@ -9,7 +9,7 @@ import { Browser } from '../../launcher' interface ServeOptions { config: Cfg // project: ProjectBase - browser: Browser + getCurrentBrowser: () => Browser specsStore: SpecsStore } @@ -25,7 +25,7 @@ export const handle = (req, res) => { export const serve = (req, res, options: ServeOptions) => { const config = { ...options.config, - browser: options.browser, + browser: options.getCurrentBrowser(), specs: options.specsStore.specFiles, } as Cfg diff --git a/packages/server-ct/src/server-ct.ts b/packages/server-ct/src/server-ct.ts index f9171e7b9e..71e64855b0 100644 --- a/packages/server-ct/src/server-ct.ts +++ b/packages/server-ct/src/server-ct.ts @@ -3,7 +3,7 @@ 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 { SocketCt } from './socket-ct' -import { Cfg } from '../../server/lib/project-base' +import { Cfg } from '@packages/server/lib/project-base' type WarningErr = Record diff --git a/packages/server/lib/controllers/runner.js b/packages/server/lib/controllers/runner.js index 4a380d4427..2e06a166fb 100644 --- a/packages/server/lib/controllers/runner.js +++ b/packages/server/lib/controllers/runner.js @@ -27,16 +27,16 @@ module.exports = { return _serveNonProxiedError(res) } - let { config, getRemoteState, spec, browser, specsStore } = options + let { config, getRemoteState, getCurrentBrowser, getSpec, specsStore } = options config = _.clone(config) config.remote = getRemoteState() config.version = pkg.version config.platform = os.platform() config.arch = os.arch() - config.spec = spec + config.spec = getSpec() config.specs = specsStore.specFiles - config.browser = browser + config.browser = getCurrentBrowser() debug('serving runner index.html with config %o', _.pick(config, 'version', 'platform', 'arch', 'projectName')) diff --git a/packages/server/lib/project-base.ts b/packages/server/lib/project-base.ts index a9b0187023..f2c979779d 100644 --- a/packages/server/lib/project-base.ts +++ b/packages/server/lib/project-base.ts @@ -207,8 +207,8 @@ export class ProjectBase extends EE { } const [port, warning] = await this._server.open(cfg, { - browser: this.browser, - spec: this.spec, + getCurrentBrowser: () => this.browser, + getSpec: () => this.spec, onError: this.options.onError, onWarning: this.options.onWarning, shouldCorrelatePreRequests: this.shouldCorrelatePreRequests, diff --git a/packages/server/lib/routes.ts b/packages/server/lib/routes.ts index e65b53cbbd..883dbfb72a 100644 --- a/packages/server/lib/routes.ts +++ b/packages/server/lib/routes.ts @@ -22,8 +22,8 @@ export const createRoutes = ({ specsStore, getRemoteState, networkProxy, - spec, - browser, + getSpec, + getCurrentBrowser, onError, }: InitializeRoutes) => { // routing for the actual specs which are processed automatically @@ -59,12 +59,12 @@ export const createRoutes = ({ // routing for the dynamic iframe html app.get('/__cypress/iframes/*', (req, res) => { const extraOptions = { - specFilter: spec?.specFilter, + specFilter: getSpec()?.specFilter, specType: 'integration', } debug('handling iframe for project spec %o', { - spec, + spec: getSpec(), extraOptions, }) @@ -102,8 +102,8 @@ export const createRoutes = ({ runner.serve(req, res, { config, - spec, - browser, + getSpec, + getCurrentBrowser, getRemoteState, specsStore, }) diff --git a/packages/server/lib/server-base.ts b/packages/server/lib/server-base.ts index cd7ca3279a..4ce774e4db 100644 --- a/packages/server/lib/server-base.ts +++ b/packages/server/lib/server-base.ts @@ -92,14 +92,13 @@ const notSSE = (req, res) => { export type WarningErr = Record export interface OpenServerOptions { - // project: ProjectBase - browser: Browser - spec: Cypress.Cypress['spec'] | null SocketCtor: typeof SocketE2E | typeof SocketCt specsStore: SpecsStore projectType: 'ct' | 'e2e' onError: any onWarning: any + getCurrentBrowser: () => Browser + getSpec: () => Cypress.Cypress['spec'] | null shouldCorrelatePreRequests: () => boolean createRoutes: (args: InitializeRoutes) => any } @@ -169,8 +168,8 @@ export abstract class ServerBase { ): Bluebird<[number, WarningErr?]> open (config: Cfg, { - spec, - browser, + getSpec, + getCurrentBrowser, onError, onWarning, shouldCorrelatePreRequests, @@ -220,8 +219,8 @@ export abstract class ServerBase { nodeProxy: this.nodeProxy, networkProxy: this._networkProxy!, onError, - spec, - browser, + getSpec, + getCurrentBrowser, }) return this.createServer(app, config, onWarning)