Skip to content

Commit 85ee714

Browse files
chore(server): clean up server code (#23002)
* remove dead code * looking a little closer, runAllSpecsInSameBrowserSession is not used and default browser was already set to electron
1 parent fa2cd97 commit 85ee714

File tree

8 files changed

+14
-251
lines changed

8 files changed

+14
-251
lines changed

packages/server/lib/gui/events.ts

Lines changed: 0 additions & 183 deletions
This file was deleted.

packages/server/lib/modes/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@ export = (mode, options) => {
2828
const loadingPromise = ctx.initializeMode()
2929

3030
if (mode === 'run') {
31-
if (options.testingType === 'component') {
32-
return require('./run-ct').run(options, loadingPromise)
33-
}
34-
3531
// run must always be deterministic - if the user doesn't specify
3632
// a testingType, we default to e2e
37-
options.testingType = 'e2e'
33+
options.testingType = options.testingType || 'e2e'
3834

39-
return require('./run-e2e').run(options, loadingPromise)
35+
return require('./run').run(options, loadingPromise)
4036
}
4137

4238
if (mode === 'interactive') {

packages/server/lib/modes/interactive.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import _ from 'lodash'
22
import os from 'os'
33
import { app, nativeImage as image } from 'electron'
4-
// eslint-disable-next-line no-duplicate-imports
5-
import type { WebContents } from 'electron'
4+
65
import * as cyIcons from '@packages/icons'
76
import * as savedState from '../saved_state'
87
import menu from '../gui/menu'
98
import * as Windows from '../gui/windows'
109
import { makeGraphQLServer } from '@packages/graphql/src/makeGraphQLServer'
11-
import { DataContext, globalPubSub, getCtx, clearCtx } from '@packages/data-context'
12-
import type { LaunchArgs, PlatformName } from '@packages/types'
13-
import { EventEmitter } from 'events'
10+
import { globalPubSub, getCtx, clearCtx } from '@packages/data-context'
11+
12+
// eslint-disable-next-line no-duplicate-imports
13+
import type { WebContents } from 'electron'
14+
import type { LaunchArgs } from '@packages/types'
15+
1416
import debugLib from 'debug'
15-
import Events from '../gui/events'
1617

1718
const debug = debugLib('cypress:server:interactive')
1819

@@ -153,21 +154,13 @@ export = {
153154
return Windows.open(projectRoot, port, this.getWindowArgs(state))
154155
.then((win) => {
155156
ctx?.actions.electron.setBrowserWindow(win)
156-
Events.start({
157-
...(options as LaunchArgs),
158-
onFocusTests () {
159-
// @ts-ignore
160-
return app.focus({ steal: true }) || win.focus()
161-
},
162-
os: os.platform() as PlatformName,
163-
}, new EventEmitter())
164157

165158
return win
166159
})
167160
})
168161
},
169162

170-
async run (options, ctx: DataContext) {
163+
async run (options: LaunchArgs, _loading: Promise<void>) {
171164
const [, port] = await Promise.all([
172165
app.whenReady(),
173166
makeGraphQLServer(),

packages/server/lib/modes/run-ct.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/server/lib/modes/run-e2e.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/server/test/integration/cypress_spec.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const argsUtil = require(`../../lib/util/args`)
2020
const { fs } = require(`../../lib/util/fs`)
2121
const ciProvider = require(`../../lib/util/ci_provider`)
2222
const settings = require(`../../lib/util/settings`)
23-
const Events = require(`../../lib/gui/events`)
2423
const Windows = require(`../../lib/gui/windows`)
2524
const interactiveMode = require(`../../lib/modes/interactive`)
2625
const runMode = require(`../../lib/modes/run`)
@@ -1641,7 +1640,6 @@ describe('lib/cypress', () => {
16411640
sinon.stub(electron.app, 'on').withArgs('ready').yieldsAsync()
16421641
sinon.stub(Windows, 'open').resolves(this.win)
16431642
sinon.stub(ServerE2E.prototype, 'startWebsockets')
1644-
sinon.spy(Events, 'start')
16451643
sinon.stub(electron.ipcMain, 'on')
16461644
})
16471645

@@ -1660,21 +1658,11 @@ describe('lib/cypress', () => {
16601658
})
16611659
})
16621660

1663-
it('passes options to Events.start', () => {
1664-
return cypress.start(['--port=2121', '--config=pageLoadTimeout=1000'])
1665-
.then(() => {
1666-
expect(Events.start).to.be.calledWithMatch({
1667-
config: {
1668-
pageLoadTimeout: 1000,
1669-
port: 2121,
1670-
},
1671-
})
1672-
})
1673-
})
1674-
16751661
it('passes filtered options to Project#open and sets cli config', async function () {
16761662
const open = sinon.stub(ServerE2E.prototype, 'open').resolves([])
16771663

1664+
sinon.stub(interactiveMode, 'ready')
1665+
16781666
process.env.CYPRESS_FILE_SERVER_FOLDER = 'foo'
16791667
process.env.CYPRESS_BASE_URL = 'http://localhost'
16801668
process.env.CYPRESS_port = '2222'
@@ -1688,7 +1676,7 @@ describe('lib/cypress', () => {
16881676
return user.set({ name: 'brian', authToken: 'auth-token-123' })
16891677
.then(() => ctx.lifecycleManager.getFullInitialConfig())
16901678
.then((json) => {
1691-
// this should be overriden by the env argument
1679+
// this should be overridden by the env argument
16921680
json.baseUrl = 'http://localhost:8080'
16931681

16941682
const { supportFile, specPattern, excludeSpecPattern, baseUrl, experimentalSessionAndOrigin, slowTestThreshold, ...rest } = json
@@ -1705,7 +1693,7 @@ describe('lib/cypress', () => {
17051693
'--env=baz=baz',
17061694
])
17071695
}).then(() => {
1708-
const options = Events.start.firstCall.args[0]
1696+
const options = interactiveMode.ready.firstCall.args[0]
17091697

17101698
return openProject.create(this.todosPath, { ...options, testingType: 'e2e' }, [])
17111699
}).then(() => {

packages/server/test/unit/modes/interactive_spec.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const electron = require('electron')
66
const DataContext = require('@packages/data-context')
77
const savedState = require(`../../../lib/saved_state`)
88
const menu = require(`../../../lib/gui/menu`)
9-
const Events = require(`../../../lib/gui/events`)
109
const Windows = require(`../../../lib/gui/windows`)
1110
const interactiveMode = require(`../../../lib/modes/interactive`)
1211

@@ -128,7 +127,6 @@ describe('gui/interactive', () => {
128127
this.state = {}
129128

130129
sinon.stub(menu, 'set')
131-
sinon.stub(Events, 'start')
132130
sinon.stub(Windows, 'open').resolves(this.win)
133131
sinon.stub(Windows, 'trackState')
134132

@@ -137,18 +135,6 @@ describe('gui/interactive', () => {
137135
sinon.stub(state, 'get').resolves(this.state)
138136
})
139137

140-
it('calls Events.start with options, adding env, onFocusTests, and os', () => {
141-
sinon.stub(os, 'platform').returns('someOs')
142-
const opts = {}
143-
144-
return interactiveMode.ready(opts).then(() => {
145-
expect(Events.start).to.be.called
146-
expect(Events.start.lastCall.args[0].onFocusTests).to.be.a('function')
147-
148-
expect(Events.start.lastCall.args[0].os).to.equal('someOs')
149-
})
150-
})
151-
152138
it('calls menu.set', () => {
153139
return interactiveMode.ready({}).then(() => {
154140
expect(menu.set).to.be.calledOnce

packages/types/src/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface LaunchArgs {
3030
projectRoot: string // same as above
3131
testingType: Cypress.TestingType
3232
invokedFromCli: boolean
33-
runAllSpecsInSameBrowserSession?: boolean
3433
onError?: (error: Error) => void
3534
os: PlatformName
3635
exit?: boolean

0 commit comments

Comments
 (0)