Skip to content

Commit b08bc27

Browse files
chore: remove dead code -- lives in data-context/src/sources/HtmlDataSource.ts now (#23542)
1 parent f6eaad4 commit b08bc27

File tree

4 files changed

+4
-120
lines changed

4 files changed

+4
-120
lines changed
+3-93
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,11 @@
1-
import _ from 'lodash'
21
import type { Request, Response } from 'express'
32
import send from 'send'
4-
import os from 'os'
5-
import { fs } from '../util/fs'
6-
import path from 'path'
7-
import Debug from 'debug'
8-
import pkg from '@packages/root'
9-
import { getPathToDist, getPathToIndex, RunnerPkg } from '@packages/resolve-dist'
10-
import type { InitializeRoutes } from '../routes'
11-
import type { PlatformName } from '@packages/types'
12-
import type { Cfg } from '../project-base'
13-
14-
const debug = Debug('cypress:server:runner')
15-
16-
const PATH_TO_NON_PROXIED_ERROR = path.join(__dirname, '..', 'html', 'non_proxied_error.html')
17-
18-
const _serveNonProxiedError = (res: Response) => {
19-
return fs.readFile(PATH_TO_NON_PROXIED_ERROR)
20-
.then((html) => {
21-
return res.type('html').end(html)
22-
})
23-
}
24-
25-
export interface ServeOptions extends Pick<InitializeRoutes, 'getSpec' | 'config' | 'getCurrentBrowser' | 'remoteStates' | 'exit'> {
26-
testingType: Cypress.TestingType
27-
}
28-
29-
export const serveRunner = (runnerPkg: RunnerPkg, config: Cfg, res: Response) => {
30-
// base64 before embedding so user-supplied contents can't break out of <script>
31-
// https://github.com/cypress-io/cypress/issues/4952
32-
const base64Config = Buffer.from(JSON.stringify(config)).toString('base64')
33-
34-
const runnerPath = process.env.CYPRESS_INTERNAL_RUNNER_PATH || getPathToIndex(runnerPkg)
35-
36-
// Chrome plans to make document.domain immutable in Chrome 106, with the default value
37-
// of the Origin-Agent-Cluster header becoming 'true'. We explicitly disable this header
38-
// so that we can continue to support tests that visit multiple subdomains in a single spec.
39-
// https://github.com/cypress-io/cypress/issues/20147
40-
res.setHeader('Origin-Agent-Cluster', '?0')
41-
42-
return res.render(runnerPath, {
43-
base64Config,
44-
projectName: config.projectName,
45-
namespace: config.namespace,
46-
})
47-
}
3+
import { getPathToDist } from '@packages/resolve-dist'
484

495
export const runner = {
50-
serve (req, res, runnerPkg: RunnerPkg, options: ServeOptions) {
51-
if (req.proxiedUrl.startsWith('/')) {
52-
debug('request was not proxied via Cypress, erroring %o', _.pick(req, 'proxiedUrl'))
53-
54-
return _serveNonProxiedError(res)
55-
}
56-
57-
let { config, remoteStates, getCurrentBrowser, getSpec, exit } = options
58-
59-
config = _.clone(config)
60-
// at any given point, rather than just arbitrarily modifying it.
61-
// @ts-ignore
62-
config.testingType = options.testingType
63-
64-
// TODO #1: bug. Passing `remote.domainName` breaks CT for unknown reasons.
65-
// If you pass a remote object with a domainName key, we get cross-origin
66-
// iframe access errors.
67-
// repro:
68-
// {
69-
// "domainName": "localhost"
70-
// }
71-
// TODO: Find out what the problem.
72-
if (options.testingType === 'e2e') {
73-
config.remote = remoteStates.getPrimary()
74-
}
75-
76-
const spec = getSpec()
77-
78-
config.version = pkg.version
79-
config.platform = os.platform() as PlatformName
80-
config.arch = os.arch()
81-
config.spec = spec ? { ...spec, name: spec.baseName } : null
82-
// coerce type to allow string to be cast to BrowserFamily
83-
config.browser = getCurrentBrowser() as Cypress.Browser
84-
config.exit = exit ?? true
85-
86-
debug('serving runner index.html with config %o',
87-
_.pick(config, 'version', 'platform', 'arch', 'projectName'))
88-
89-
// log the env object's keys without values to avoid leaking sensitive info
90-
debug('env object has the following keys: %s', _.keys(config.env).join(', '))
91-
92-
return serveRunner(runnerPkg, config, res)
93-
},
94-
95-
handle (testingType, req: Request, res: Response) {
6+
handle (req: Request, res: Response) {
967
const pathToFile = getPathToDist('runner', req.params[0])
978

98-
return send(req, pathToFile)
99-
.pipe(res)
9+
return send(req, pathToFile).pipe(res)
10010
},
10111
}

packages/server/lib/routes.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ErrorRequestHandler, Request, Router } from 'express'
44
import send from 'send'
55
import { getPathToDist } from '@packages/resolve-dist'
66

7-
import type { Browser } from './browsers/types'
87
import type { NetworkProxy } from '@packages/proxy'
98
import type { Cfg } from './project-base'
109
import xhrs from './controllers/xhrs'
@@ -20,24 +19,20 @@ const debug = Debug('cypress:server:routes')
2019
export interface InitializeRoutes {
2120
config: Cfg
2221
getSpec: () => FoundSpec | null
23-
getCurrentBrowser: () => Browser
2422
nodeProxy: httpProxy
2523
networkProxy: NetworkProxy
2624
remoteStates: RemoteStates
2725
onError: (...args: unknown[]) => any
2826
testingType: Cypress.TestingType
29-
exit?: boolean
3027
}
3128

3229
export const createCommonRoutes = ({
3330
config,
3431
networkProxy,
3532
testingType,
3633
getSpec,
37-
getCurrentBrowser,
3834
remoteStates,
3935
nodeProxy,
40-
exit,
4136
}: InitializeRoutes) => {
4237
const router = Router()
4338
const { clientRoute, namespace } = config
@@ -61,7 +56,7 @@ export const createCommonRoutes = ({
6156
router.use(`/${namespace}/graphql/*`, graphQLHTTP)
6257

6358
router.get(`/${namespace}/runner/*`, (req, res) => {
64-
runner.handle(testingType, req, res)
59+
runner.handle(req, res)
6560
})
6661

6762
router.all(`/${namespace}/xhrs/*`, (req, res, next) => {

packages/server/lib/server-base.ts

-2
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,7 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
241241
networkProxy: this._networkProxy!,
242242
onError,
243243
getSpec,
244-
getCurrentBrowser,
245244
testingType,
246-
exit,
247245
}
248246

249247
this.getCurrentBrowser = getCurrentBrowser

packages/server/test/unit/runner_spec.js

-19
This file was deleted.

0 commit comments

Comments
 (0)