|
1 |
| -import _ from 'lodash' |
2 | 1 | import type { Request, Response } from 'express'
|
3 | 2 | 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' |
48 | 4 |
|
49 | 5 | 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) { |
96 | 7 | const pathToFile = getPathToDist('runner', req.params[0])
|
97 | 8 |
|
98 |
| - return send(req, pathToFile) |
99 |
| - .pipe(res) |
| 9 | + return send(req, pathToFile).pipe(res) |
100 | 10 | },
|
101 | 11 | }
|
0 commit comments