Files
cypress/packages/server/lib/runner-ct.ts
T
Kukhyeon Heo 2d119ad46a chore: Intregrate runner packages. (#23028)
* chore: Intregrate runner packages.

* Remove unnecessary Studio react files.

* Remove unnecessary gif

* runner-shared to runner-ct.

* fix path.

* fix package.json

* Remove scss files from runner-ct

* Remove runner-ct

* Remove runner-shared and runner-ct comments.

* Feedback

* chore: reduce parallelism for reporter-componen-tests

* chore: reduce paralelleism

Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
2022-08-11 14:07:10 +10:00

54 lines
1.5 KiB
TypeScript

import Debug from 'debug'
import _ from 'lodash'
import send from 'send'
import { getPathToIndex, getPathToDist } from '@packages/resolve-dist'
import type { Cfg } from '@packages/server/lib/project-base'
import type { Browser } from '@packages/server/lib/browsers/types'
interface ServeOptions {
config: Cfg
getCurrentBrowser: () => Browser
}
const debug = Debug('cypress:server:runner-ct')
export const handle = (req, res) => {
const pathToFile = getPathToDist('runner', req.params[0])
return send(req, pathToFile)
.pipe(res)
}
export const makeServeConfig = (options) => {
const config = {
...options.config,
browser: options.getCurrentBrowser(),
} as Cfg
// TODO: move the component file watchers in here
// and update them in memory when they change and serve
// them straight to the HTML on load
debug('serving runner index.html with config %o',
_.pick(config, 'version', 'platform', 'arch', 'projectName'))
// 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')
return {
base64Config,
projectName: config.projectName,
namespace: config.namespace,
}
}
export const serve = (req, res, options: ServeOptions) => {
const config = makeServeConfig(options)
const runnerPath = process.env.CYPRESS_INTERNAL_RUNNER_PATH || getPathToIndex('runner')
return res.render(runnerPath, config)
}