mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-03 21:40:28 -05:00
only pass necessary values to createRoutes
This commit is contained in:
@@ -6,8 +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, ProjectBase } from '../../server/lib/project-base'
|
||||
import { Cfg } from '../../server/lib/project-base'
|
||||
import { getPathToDist } from '@packages/resolve-dist'
|
||||
import { Browser } from '../../launcher'
|
||||
|
||||
const debug = Debug('cypress:server:routes')
|
||||
|
||||
@@ -15,7 +16,8 @@ export interface InitializeRoutes {
|
||||
app: Express
|
||||
specsStore: SpecsStore
|
||||
config: Cfg
|
||||
project: ProjectBase<any>
|
||||
spec: Cypress.Cypress['spec'] | null
|
||||
browser: Browser
|
||||
nodeProxy: httpProxy
|
||||
networkProxy: NetworkProxy
|
||||
getRemoteState: () => any
|
||||
@@ -28,7 +30,7 @@ export const createRoutes = ({
|
||||
specsStore,
|
||||
nodeProxy,
|
||||
networkProxy,
|
||||
project,
|
||||
browser,
|
||||
}: InitializeRoutes) => {
|
||||
app.get('/__cypress/runner/*', handle)
|
||||
|
||||
@@ -88,7 +90,7 @@ export const createRoutes = ({
|
||||
|
||||
serve(req, res, {
|
||||
config,
|
||||
project,
|
||||
browser,
|
||||
specsStore,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,12 +3,13 @@ import _ from 'lodash'
|
||||
import send from 'send'
|
||||
import { SpecsStore } from '@packages/server/lib/specs-store'
|
||||
import { getPathToIndex, getPathToDist } from '@packages/resolve-dist'
|
||||
import { Cfg, ProjectBase } from '@packages/server/lib/project-base'
|
||||
import { ServerCt } from '../../server-ct'
|
||||
import { Cfg } from '@packages/server/lib/project-base'
|
||||
import { Browser } from '../../launcher'
|
||||
|
||||
interface ServeOptions {
|
||||
config: Cfg
|
||||
project: ProjectBase<ServerCt>
|
||||
// project: ProjectBase<ServerCt>
|
||||
browser: Browser
|
||||
specsStore: SpecsStore
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ export const handle = (req, res) => {
|
||||
export const serve = (req, res, options: ServeOptions) => {
|
||||
const config = {
|
||||
...options.config,
|
||||
browser: options.project.browser,
|
||||
browser: options.browser,
|
||||
specs: options.specsStore.specFiles,
|
||||
} as Cfg
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export class ServerCt extends ServerBase<SocketCt> {
|
||||
return super.open(config, { ...options, projectType: 'ct' })
|
||||
}
|
||||
|
||||
createServer (app, config, project, request, onWarning): Bluebird<[number, WarningErr?]> {
|
||||
createServer (app, config, onWarning): Bluebird<[number, WarningErr?]> {
|
||||
return new Bluebird((resolve, reject) => {
|
||||
const { port, baseUrl, socketIoRoute } = config
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ module.exports = {
|
||||
return _serveNonProxiedError(res)
|
||||
}
|
||||
|
||||
let { config, getRemoteState, project, specsStore } = options
|
||||
|
||||
const { spec, browser } = project.getCurrentSpecAndBrowser()
|
||||
let { config, getRemoteState, spec, browser, specsStore } = options
|
||||
|
||||
config = _.clone(config)
|
||||
config.remote = getRemoteState()
|
||||
|
||||
@@ -207,7 +207,8 @@ export class ProjectBase<TServer extends ServerE2E | ServerCt> extends EE {
|
||||
}
|
||||
|
||||
const [port, warning] = await this._server.open(cfg, {
|
||||
project: this,
|
||||
browser: this.browser,
|
||||
spec: this.spec,
|
||||
onError: this.options.onError,
|
||||
onWarning: this.options.onWarning,
|
||||
shouldCorrelatePreRequests: this.shouldCorrelatePreRequests,
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import path from 'path'
|
||||
import la from 'lazy-ass'
|
||||
import check from 'check-more-types'
|
||||
import _ from 'lodash'
|
||||
import Debug from 'debug'
|
||||
|
||||
import { InitializeRoutes } from '@packages/server-ct/src/routes-ct'
|
||||
import AppData from './util/app_data'
|
||||
import CacheBuster from './util/cache_buster'
|
||||
import spec from './controllers/spec'
|
||||
import specController from './controllers/spec'
|
||||
import reporter from './controllers/reporter'
|
||||
import runner from './controllers/runner'
|
||||
import xhrs from './controllers/xhrs'
|
||||
@@ -23,7 +22,8 @@ export const createRoutes = ({
|
||||
specsStore,
|
||||
getRemoteState,
|
||||
networkProxy,
|
||||
project,
|
||||
spec,
|
||||
browser,
|
||||
onError,
|
||||
}: InitializeRoutes) => {
|
||||
// routing for the actual specs which are processed automatically
|
||||
@@ -32,7 +32,7 @@ export const createRoutes = ({
|
||||
// slice out the cache buster
|
||||
const test = CacheBuster.strip(req.query.p)
|
||||
|
||||
spec.handle(test, req, res, config, next, onError)
|
||||
specController.handle(test, req, res, config, next, onError)
|
||||
})
|
||||
|
||||
app.get('/__cypress/socket.io.js', (req, res) => {
|
||||
@@ -59,13 +59,12 @@ export const createRoutes = ({
|
||||
// routing for the dynamic iframe html
|
||||
app.get('/__cypress/iframes/*', (req, res) => {
|
||||
const extraOptions = {
|
||||
specFilter: _.get(project, 'spec.specFilter'),
|
||||
specType: _.get(project, 'spec.specType', 'integration'),
|
||||
specFilter: spec?.specFilter,
|
||||
specType: 'integration',
|
||||
}
|
||||
|
||||
debug('project %o', project)
|
||||
debug('handling iframe for project spec %o', {
|
||||
spec: project.spec,
|
||||
spec,
|
||||
extraOptions,
|
||||
})
|
||||
|
||||
@@ -103,7 +102,8 @@ export const createRoutes = ({
|
||||
|
||||
runner.serve(req, res, {
|
||||
config,
|
||||
project,
|
||||
spec,
|
||||
browser,
|
||||
getRemoteState,
|
||||
specsStore,
|
||||
})
|
||||
|
||||
@@ -27,7 +27,8 @@ import { SocketAllowed } from './util/socket_allowed'
|
||||
import { createInitialWorkers } from '@packages/rewriter'
|
||||
import { RunnerType, SpecsStore } from './specs-store'
|
||||
import { InitializeRoutes } from '../../server-ct/src/routes-ct'
|
||||
import { Cfg, ProjectBase } from './project-base'
|
||||
import { Cfg } from './project-base'
|
||||
import { Browser } from '../../launcher'
|
||||
|
||||
const ALLOWED_PROXY_BYPASS_URLS = [
|
||||
'/',
|
||||
@@ -91,7 +92,9 @@ const notSSE = (req, res) => {
|
||||
export type WarningErr = Record<string, any>
|
||||
|
||||
export interface OpenServerOptions {
|
||||
project: ProjectBase<any>
|
||||
// project: ProjectBase<any>
|
||||
browser: Browser
|
||||
spec: Cypress.Cypress['spec'] | null
|
||||
SocketCtor: typeof SocketE2E | typeof SocketCt
|
||||
specsStore: SpecsStore
|
||||
projectType: 'ct' | 'e2e'
|
||||
@@ -162,13 +165,12 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
|
||||
abstract createServer (
|
||||
app: Express,
|
||||
config: Cfg,
|
||||
project: ProjectBase<any>,
|
||||
request: unknown,
|
||||
onWarning: unknown,
|
||||
): Bluebird<[number, WarningErr?]>
|
||||
|
||||
open (config: Cfg, {
|
||||
project,
|
||||
spec,
|
||||
browser,
|
||||
onError,
|
||||
onWarning,
|
||||
shouldCorrelatePreRequests,
|
||||
@@ -218,10 +220,11 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
|
||||
nodeProxy: this.nodeProxy,
|
||||
networkProxy: this._networkProxy!,
|
||||
onError,
|
||||
project,
|
||||
spec,
|
||||
browser,
|
||||
})
|
||||
|
||||
return this.createServer(app, config, project, this.request, onWarning)
|
||||
return this.createServer(app, config, onWarning)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export class ServerE2E extends ServerBase<SocketE2E> {
|
||||
return super.open(config, { ...options, projectType: 'e2e' })
|
||||
}
|
||||
|
||||
createServer (app, config, project, request, onWarning): Bluebird<[number, WarningErr?]> {
|
||||
createServer (app, config, onWarning): Bluebird<[number, WarningErr?]> {
|
||||
return new Bluebird((resolve, reject) => {
|
||||
const { port, fileServerFolder, socketIoRoute, baseUrl } = config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user