Skip to content

Commit

Permalink
chore: remove dead code -- lives in data-context/src/sources/HtmlData…
Browse files Browse the repository at this point in the history
…Source.ts now (#23542)
  • Loading branch information
emilyrohrbough authored Aug 29, 2022
1 parent f6eaad4 commit b08bc27
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 120 deletions.
96 changes: 3 additions & 93 deletions packages/server/lib/controllers/runner.ts
Original file line number Diff line number Diff line change
@@ -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)
},
}
7 changes: 1 addition & 6 deletions packages/server/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -20,24 +19,20 @@ 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 = ({
config,
networkProxy,
testingType,
getSpec,
getCurrentBrowser,
remoteStates,
nodeProxy,
exit,
}: InitializeRoutes) => {
const router = Router()
const { clientRoute, namespace } = config
Expand All @@ -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) => {
Expand Down
2 changes: 0 additions & 2 deletions packages/server/lib/server-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
networkProxy: this._networkProxy!,
onError,
getSpec,
getCurrentBrowser,
testingType,
exit,
}

this.getCurrentBrowser = getCurrentBrowser
Expand Down
19 changes: 0 additions & 19 deletions packages/server/test/unit/runner_spec.js

This file was deleted.

5 comments on commit b08bc27

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b08bc27 Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.7.0/linux-x64/develop-b08bc270e90db72e7bdafc4eb80cc38c8463ccb1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b08bc27 Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.7.0/linux-arm64/develop-b08bc270e90db72e7bdafc4eb80cc38c8463ccb1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b08bc27 Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.7.0/darwin-arm64/develop-b08bc270e90db72e7bdafc4eb80cc38c8463ccb1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b08bc27 Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.7.0/darwin-x64/develop-b08bc270e90db72e7bdafc4eb80cc38c8463ccb1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b08bc27 Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.7.0/win32-x64/develop-b08bc270e90db72e7bdafc4eb80cc38c8463ccb1/cypress.tgz

Please sign in to comment.