simplify object passed to createRoutes

This commit is contained in:
Lachlan Miller
2021-07-21 12:36:04 +10:00
parent 8d13188730
commit ddaa21478d
7 changed files with 27 additions and 27 deletions

View File

@@ -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,
})
})

View File

@@ -9,7 +9,7 @@ import { Browser } from '../../launcher'
interface ServeOptions {
config: Cfg
// project: ProjectBase<ServerCt>
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

View File

@@ -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<string, any>

View File

@@ -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'))

View File

@@ -207,8 +207,8 @@ export class ProjectBase<TServer extends ServerE2E | ServerCt> 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,

View File

@@ -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,
})

View File

@@ -92,14 +92,13 @@ const notSSE = (req, res) => {
export type WarningErr = Record<string, any>
export interface OpenServerOptions {
// project: ProjectBase<any>
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<TSocket extends SocketE2E | SocketCt> {
): Bluebird<[number, WarningErr?]>
open (config: Cfg, {
spec,
browser,
getSpec,
getCurrentBrowser,
onError,
onWarning,
shouldCorrelatePreRequests,
@@ -220,8 +219,8 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
nodeProxy: this.nodeProxy,
networkProxy: this._networkProxy!,
onError,
spec,
browser,
getSpec,
getCurrentBrowser,
})
return this.createServer(app, config, onWarning)