Skip to content

Commit 98c3a28

Browse files
lmiller1990mjhenkes
authored andcommitted
chore(server): share client route (#18215)
1 parent bf4f8ec commit 98c3a28

File tree

3 files changed

+24
-42
lines changed

3 files changed

+24
-42
lines changed

packages/server/lib/routes-ct.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Debug from 'debug'
22
import { Request, Response, Router } from 'express'
33
import send from 'send'
44
import { getPathToDist } from '@packages/resolve-dist'
5-
import { runner } from './controllers/runner'
65
import type { InitializeRoutes } from './routes'
76

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

1615
export const createRoutesCT = ({
1716
config,
18-
specsStore,
1917
nodeProxy,
20-
getCurrentBrowser,
21-
testingType,
22-
getSpec,
23-
getRemoteState,
2418
}: InitializeRoutes) => {
2519
const routesCt = Router()
2620

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

47-
routesCt.get(clientRoute, (req, res) => {
48-
debug('Serving Cypress front-end by requested URL:', req.url)
49-
50-
runner.serve(req, res, 'runner-ct', {
51-
config,
52-
testingType,
53-
getSpec,
54-
getCurrentBrowser,
55-
getRemoteState,
56-
specsStore,
57-
})
58-
})
59-
6041
// enables runner-ct to make a dynamic import
6142
routesCt.get([
6243
`${clientRoute}ctChunk-*`,

packages/server/lib/routes-e2e.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import path from 'path'
2-
import la from 'lazy-ass'
3-
import check from 'check-more-types'
42
import Debug from 'debug'
53
import { Router } from 'express'
64

75
import AppData from './util/app_data'
86
import CacheBuster from './util/cache_buster'
97
import specController from './controllers/spec'
108
import reporter from './controllers/reporter'
11-
import { runner } from './controllers/runner'
129
import client from './controllers/client'
1310
import files from './controllers/files'
1411
import type { InitializeRoutes } from './routes'
@@ -17,13 +14,8 @@ const debug = Debug('cypress:server:routes-e2e')
1714

1815
export const createRoutesE2E = ({
1916
config,
20-
specsStore,
21-
getRemoteState,
2217
networkProxy,
23-
getSpec,
24-
getCurrentBrowser,
2518
onError,
26-
testingType,
2719
}: InitializeRoutes) => {
2820
const routesE2E = Router()
2921

@@ -137,20 +129,5 @@ export const createRoutesE2E = ({
137129
res.sendFile(file, { etag: false })
138130
})
139131

140-
la(check.unemptyString(config.clientRoute), 'missing client route in config', config)
141-
142-
routesE2E.get(`${config.clientRoute}`, (req, res) => {
143-
debug('Serving Cypress front-end by requested URL:', req.url)
144-
145-
runner.serve(req, res, 'runner', {
146-
config,
147-
testingType,
148-
getSpec,
149-
getCurrentBrowser,
150-
getRemoteState,
151-
specsStore,
152-
})
153-
})
154-
155132
return routesE2E
156133
}

packages/server/lib/routes.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type httpProxy from 'http-proxy'
2+
import Debug from 'debug'
23
import { ErrorRequestHandler, Router } from 'express'
34

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

13+
const debug = Debug('cypress:server:routes')
14+
1215
export interface InitializeRoutes {
1316
specsStore: SpecsStore
1417
config: Cfg
@@ -26,6 +29,8 @@ export const createCommonRoutes = ({
2629
networkProxy,
2730
testingType,
2831
getSpec,
32+
getCurrentBrowser,
33+
specsStore,
2934
getRemoteState,
3035
nodeProxy,
3136
}: InitializeRoutes) => {
@@ -49,6 +54,25 @@ export const createCommonRoutes = ({
4954
}
5055
})
5156

57+
const clientRoute = config.clientRoute
58+
59+
if (!clientRoute) {
60+
throw Error(`clientRoute is required. Received ${clientRoute}`)
61+
}
62+
63+
router.get(clientRoute, (req, res) => {
64+
debug('Serving Cypress front-end by requested URL:', req.url)
65+
66+
runner.serve(req, res, testingType === 'e2e' ? 'runner' : 'runner-ct', {
67+
config,
68+
testingType,
69+
getSpec,
70+
getCurrentBrowser,
71+
getRemoteState,
72+
specsStore,
73+
})
74+
})
75+
5276
router.all('*', (req, res) => {
5377
networkProxy.handleHttpRequest(req, res)
5478
})

0 commit comments

Comments
 (0)