Skip to content

Commit

Permalink
chore(server): share client route (#18215)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 authored and mjhenkes committed Jul 28, 2022
1 parent bf4f8ec commit 98c3a28
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
19 changes: 0 additions & 19 deletions packages/server/lib/routes-ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Debug from 'debug'
import { Request, Response, Router } from 'express'
import send from 'send'
import { getPathToDist } from '@packages/resolve-dist'
import { runner } from './controllers/runner'
import type { InitializeRoutes } from './routes'

const debug = Debug('cypress:server:routes-ct')
Expand All @@ -15,12 +14,7 @@ const serveChunk = (req: Request, res: Response, clientRoute: string) => {

export const createRoutesCT = ({
config,
specsStore,
nodeProxy,
getCurrentBrowser,
testingType,
getSpec,
getRemoteState,
}: InitializeRoutes) => {
const routesCt = Router()

Expand All @@ -44,19 +38,6 @@ export const createRoutesCT = ({
throw Error(`clientRoute is required. Received ${clientRoute}`)
}

routesCt.get(clientRoute, (req, res) => {
debug('Serving Cypress front-end by requested URL:', req.url)

runner.serve(req, res, 'runner-ct', {
config,
testingType,
getSpec,
getCurrentBrowser,
getRemoteState,
specsStore,
})
})

// enables runner-ct to make a dynamic import
routesCt.get([
`${clientRoute}ctChunk-*`,
Expand Down
23 changes: 0 additions & 23 deletions packages/server/lib/routes-e2e.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import path from 'path'
import la from 'lazy-ass'
import check from 'check-more-types'
import Debug from 'debug'
import { Router } from 'express'

import AppData from './util/app_data'
import CacheBuster from './util/cache_buster'
import specController from './controllers/spec'
import reporter from './controllers/reporter'
import { runner } from './controllers/runner'
import client from './controllers/client'
import files from './controllers/files'
import type { InitializeRoutes } from './routes'
Expand All @@ -17,13 +14,8 @@ const debug = Debug('cypress:server:routes-e2e')

export const createRoutesE2E = ({
config,
specsStore,
getRemoteState,
networkProxy,
getSpec,
getCurrentBrowser,
onError,
testingType,
}: InitializeRoutes) => {
const routesE2E = Router()

Expand Down Expand Up @@ -137,20 +129,5 @@ export const createRoutesE2E = ({
res.sendFile(file, { etag: false })
})

la(check.unemptyString(config.clientRoute), 'missing client route in config', config)

routesE2E.get(`${config.clientRoute}`, (req, res) => {
debug('Serving Cypress front-end by requested URL:', req.url)

runner.serve(req, res, 'runner', {
config,
testingType,
getSpec,
getCurrentBrowser,
getRemoteState,
specsStore,
})
})

return routesE2E
}
24 changes: 24 additions & 0 deletions packages/server/lib/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type httpProxy from 'http-proxy'
import Debug from 'debug'
import { ErrorRequestHandler, Router } from 'express'

import type { SpecsStore } from './specs-store'
Expand All @@ -9,6 +10,8 @@ import xhrs from './controllers/xhrs'
import { runner } from './controllers/runner'
import { iframesController } from './controllers/iframes'

const debug = Debug('cypress:server:routes')

export interface InitializeRoutes {
specsStore: SpecsStore
config: Cfg
Expand All @@ -26,6 +29,8 @@ export const createCommonRoutes = ({
networkProxy,
testingType,
getSpec,
getCurrentBrowser,
specsStore,
getRemoteState,
nodeProxy,
}: InitializeRoutes) => {
Expand All @@ -49,6 +54,25 @@ export const createCommonRoutes = ({
}
})

const clientRoute = config.clientRoute

if (!clientRoute) {
throw Error(`clientRoute is required. Received ${clientRoute}`)
}

router.get(clientRoute, (req, res) => {
debug('Serving Cypress front-end by requested URL:', req.url)

runner.serve(req, res, testingType === 'e2e' ? 'runner' : 'runner-ct', {
config,
testingType,
getSpec,
getCurrentBrowser,
getRemoteState,
specsStore,
})
})

router.all('*', (req, res) => {
networkProxy.handleHttpRequest(req, res)
})
Expand Down

1 comment on commit 98c3a28

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 98c3a28 Jul 28, 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/8.6.0/circle-matth/fix/hang-investigation-98c3a2813884b082f3feba83a6afc0b15dca1574/cypress.tgz

Please sign in to comment.