chore: remove dead code -- lives in data-context/src/sources/HtmlDataSource.ts now (#23542)

This commit is contained in:
Emily Rohrbough
2022-08-28 21:15:05 -05:00
committed by GitHub
parent f6eaad40e1
commit b08bc270e9
4 changed files with 4 additions and 120 deletions

View File

@@ -1,101 +1,11 @@
import _ from 'lodash'
import type { Request, Response } from 'express'
import send from 'send'
import os from 'os'
import { fs } from '../util/fs'
import path from 'path'
import Debug from 'debug'
import pkg from '@packages/root'
import { getPathToDist, getPathToIndex, RunnerPkg } from '@packages/resolve-dist'
import type { InitializeRoutes } from '../routes'
import type { PlatformName } from '@packages/types'
import type { Cfg } from '../project-base'
const debug = Debug('cypress:server:runner')
const PATH_TO_NON_PROXIED_ERROR = path.join(__dirname, '..', 'html', 'non_proxied_error.html')
const _serveNonProxiedError = (res: Response) => {
return fs.readFile(PATH_TO_NON_PROXIED_ERROR)
.then((html) => {
return res.type('html').end(html)
})
}
export interface ServeOptions extends Pick<InitializeRoutes, 'getSpec' | 'config' | 'getCurrentBrowser' | 'remoteStates' | 'exit'> {
testingType: Cypress.TestingType
}
export const serveRunner = (runnerPkg: RunnerPkg, config: Cfg, res: Response) => {
// base64 before embedding so user-supplied contents can't break out of <script>
// https://github.com/cypress-io/cypress/issues/4952
const base64Config = Buffer.from(JSON.stringify(config)).toString('base64')
const runnerPath = process.env.CYPRESS_INTERNAL_RUNNER_PATH || getPathToIndex(runnerPkg)
// Chrome plans to make document.domain immutable in Chrome 106, with the default value
// of the Origin-Agent-Cluster header becoming 'true'. We explicitly disable this header
// so that we can continue to support tests that visit multiple subdomains in a single spec.
// https://github.com/cypress-io/cypress/issues/20147
res.setHeader('Origin-Agent-Cluster', '?0')
return res.render(runnerPath, {
base64Config,
projectName: config.projectName,
namespace: config.namespace,
})
}
import { getPathToDist } from '@packages/resolve-dist'
export const runner = {
serve (req, res, runnerPkg: RunnerPkg, options: ServeOptions) {
if (req.proxiedUrl.startsWith('/')) {
debug('request was not proxied via Cypress, erroring %o', _.pick(req, 'proxiedUrl'))
return _serveNonProxiedError(res)
}
let { config, remoteStates, getCurrentBrowser, getSpec, exit } = options
config = _.clone(config)
// at any given point, rather than just arbitrarily modifying it.
// @ts-ignore
config.testingType = options.testingType
// TODO #1: bug. Passing `remote.domainName` breaks CT for unknown reasons.
// If you pass a remote object with a domainName key, we get cross-origin
// iframe access errors.
// repro:
// {
// "domainName": "localhost"
// }
// TODO: Find out what the problem.
if (options.testingType === 'e2e') {
config.remote = remoteStates.getPrimary()
}
const spec = getSpec()
config.version = pkg.version
config.platform = os.platform() as PlatformName
config.arch = os.arch()
config.spec = spec ? { ...spec, name: spec.baseName } : null
// coerce type to allow string to be cast to BrowserFamily
config.browser = getCurrentBrowser() as Cypress.Browser
config.exit = exit ?? true
debug('serving runner index.html with config %o',
_.pick(config, 'version', 'platform', 'arch', 'projectName'))
// log the env object's keys without values to avoid leaking sensitive info
debug('env object has the following keys: %s', _.keys(config.env).join(', '))
return serveRunner(runnerPkg, config, res)
},
handle (testingType, req: Request, res: Response) {
handle (req: Request, res: Response) {
const pathToFile = getPathToDist('runner', req.params[0])
return send(req, pathToFile)
.pipe(res)
return send(req, pathToFile).pipe(res)
},
}

View File

@@ -4,7 +4,6 @@ import { ErrorRequestHandler, Request, Router } from 'express'
import send from 'send'
import { getPathToDist } from '@packages/resolve-dist'
import type { Browser } from './browsers/types'
import type { NetworkProxy } from '@packages/proxy'
import type { Cfg } from './project-base'
import xhrs from './controllers/xhrs'
@@ -20,13 +19,11 @@ const debug = Debug('cypress:server:routes')
export interface InitializeRoutes {
config: Cfg
getSpec: () => FoundSpec | null
getCurrentBrowser: () => Browser
nodeProxy: httpProxy
networkProxy: NetworkProxy
remoteStates: RemoteStates
onError: (...args: unknown[]) => any
testingType: Cypress.TestingType
exit?: boolean
}
export const createCommonRoutes = ({
@@ -34,10 +31,8 @@ export const createCommonRoutes = ({
networkProxy,
testingType,
getSpec,
getCurrentBrowser,
remoteStates,
nodeProxy,
exit,
}: InitializeRoutes) => {
const router = Router()
const { clientRoute, namespace } = config
@@ -61,7 +56,7 @@ export const createCommonRoutes = ({
router.use(`/${namespace}/graphql/*`, graphQLHTTP)
router.get(`/${namespace}/runner/*`, (req, res) => {
runner.handle(testingType, req, res)
runner.handle(req, res)
})
router.all(`/${namespace}/xhrs/*`, (req, res, next) => {

View File

@@ -241,9 +241,7 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
networkProxy: this._networkProxy!,
onError,
getSpec,
getCurrentBrowser,
testingType,
exit,
}
this.getCurrentBrowser = getCurrentBrowser

View File

@@ -1,19 +0,0 @@
require('../spec_helper')
const { serveRunner } = require('../../lib/controllers/runner')
describe('controllers/runner', () => {
describe('serveRunner', () => {
it('sets Origin-Agent-Cluster response header to false', () => {
const mockRes = {
setHeader: sinon.stub(),
render: sinon.stub(),
}
serveRunner('runner', {}, mockRes)
expect(mockRes.setHeader).to.have.been.calledWith('Origin-Agent-Cluster', '?0')
expect(mockRes.render).to.have.been.called
})
})
})