From fa2cd97f7b13a1fe9db67e9e83b5414cb7c3f634 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 29 Jul 2022 12:57:48 +1000 Subject: [PATCH 1/2] chore: Update Chrome (beta) to 104.0.5112.65 (#22965) Co-authored-by: cypress-bot[bot] <2f0651858c6e38e0+cypress-bot[bot]@users.noreply.github.com> --- browser-versions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser-versions.json b/browser-versions.json index 51f871126625..fedcfa124fc5 100644 --- a/browser-versions.json +++ b/browser-versions.json @@ -1,4 +1,4 @@ { - "chrome:beta": "104.0.5112.57", + "chrome:beta": "104.0.5112.65", "chrome:stable": "103.0.5060.134" } From 85ee714217dd1c886ea076261d114f15f53c699d Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Fri, 29 Jul 2022 01:30:40 -0500 Subject: [PATCH 2/2] 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 --- packages/server/lib/gui/events.ts | 183 ------------------ packages/server/lib/modes/index.ts | 8 +- packages/server/lib/modes/interactive.ts | 23 +-- packages/server/lib/modes/run-ct.ts | 9 - packages/server/lib/modes/run-e2e.js | 7 - .../server/test/integration/cypress_spec.js | 20 +- .../test/unit/modes/interactive_spec.js | 14 -- packages/types/src/server.ts | 1 - 8 files changed, 14 insertions(+), 251 deletions(-) delete mode 100644 packages/server/lib/gui/events.ts delete mode 100644 packages/server/lib/modes/run-ct.ts delete mode 100644 packages/server/lib/modes/run-e2e.js diff --git a/packages/server/lib/gui/events.ts b/packages/server/lib/gui/events.ts deleted file mode 100644 index 906ca37ab7af..000000000000 --- a/packages/server/lib/gui/events.ts +++ /dev/null @@ -1,183 +0,0 @@ -/* eslint-disable no-case-declarations */ -const _ = require('lodash') -const ipc = require('electron').ipcMain -const debug = require('debug')('cypress:server:events') - -import type { LaunchArgs } from '@packages/types' -import type { EventEmitter } from 'events' - -const nullifyUnserializableValues = (obj) => { - // nullify values that cannot be cloned - // https://github.com/cypress-io/cypress/issues/6750 - return _.cloneDeepWith(obj, (val) => { - if (_.isFunction(val)) { - return null - } - - return undefined - }) -} - -const handleEvent = function (options, bus, event, id, type, arg) { - debug('got request for event: %s, %o', type, arg) - - switch (type) { - case 'launch:browser': - // TIM: Commented out for reference w/ the new implementation - // // is there a way to lint the arguments received? - // debug('launching browser for \'%s\' spec: %o', arg.specType, arg.spec) - // debug('full list of options %o', arg) - - // // the "arg" should have objects for - // // - browser - // // - spec (with fields) - // // name, absolute, relative - // // - specType: "integration" | "component" - // // - specFilter (optional): the string user searched for - // const fullSpec = _.merge({}, arg.spec, { - // specType: arg.specType, - // specFilter: arg.specFilter, - // }) - - // return openProject.launch(arg.browser, fullSpec, { - // // TODO: Tim see why this "projectRoot" is passed along - // projectRoot: options.projectRoot, - // onBrowserOpen () { - // return send({ browserOpened: true }) - // }, - // onBrowserClose () { - // return send({ browserClosed: true }) - // }, - // }) - // .catch((err) => { - // if (err.title == null) { - // err.title = 'Error launching browser' - // } - - // return sendErr(err) - // }) - return - - case 'open:project': - // debug('open:project') - - // const onSpecChanged = (spec) => { - // return bus.emit('spec:changed', spec) - // } - - // const onFocusTests = function () { - // if (_.isFunction(options.onFocusTests)) { - // options.onFocusTests() - // } - - // return bus.emit('focus:tests') - // } - - // const onError = (err) => { - // return bus.emit('project:error', errors.cloneErr(err, { html: true })) - // } - - // const onWarning = function (warning) { - // warning.message = stripAnsi(warning.message) - - // return bus.emit('project:warning', errors.cloneErr(warning, { html: true })) - // } - - // return browsers.getAllBrowsersWith(options.browser) - // .then((browsers = []) => { - // debug('setting found %s on the config', pluralize('browser', browsers.length, true)) - // options.config = _.assign(options.config, { browsers }) - // }).then(() => { - // chromePolicyCheck.run((err) => { - // return options.config.browsers.forEach((browser) => { - // if (browser.family === 'chromium') { - // browser.warning = errors.getMsgByType('BAD_POLICY_WARNING_TOOLTIP') - // } - // }) - // }) - - // return openProject.create(arg, options, { - // onFocusTests, - // onSpecChanged, - // onError, - // onWarning, - // }) - // }).call('getConfig') - // .then((config) => { - // if (config.configFile && path.isAbsolute(config.configFile)) { - // config.configFile = path.relative(arg, config.configFile) - // } - - // // those two values make no sense to display in - // // the GUI - // if (config.resolved) { - // config.resolved.configFile = undefined - // config.resolved.testingType = undefined - // } - - // return config - // }) - // .then(send) - // .catch(sendErr) - return - - case 'has:opened:cypress': - // return savedState.create() - // .then(async (state) => { - // const currentState = await state.get() - - // // we check if there is any state at all so users existing before - // // we added firstOpenedCypress are not marked as new - // const hasOpenedCypress = !!Object.keys(currentState).length - - // if (!currentState.firstOpenedCypress) { - // await state.set('firstOpenedCypress', Date.now()) - // } - - // return hasOpenedCypress - // }) - // .then(send) - return - - case 'ping:baseUrl': - // NOTE: Keeping this code around to ensure we keep this for v10 - // const baseUrl = arg - - // return ensureUrl.isListening(baseUrl) - // .then(send) - // .catch((err) => { - // const warning = errors.get('CANNOT_CONNECT_BASE_URL_WARNING', baseUrl) - - // return sendErr(warning) - // }) - return - - // TODO: setClipboardText mutation - // case 'set:clipboard:text': - // clipboard.writeText(arg) - - // return sendNull() - - default: - throw new Error(`No ipc event registered for: '${type}'`) - } -} - -interface EventsStartArgs extends LaunchArgs { - onFocusTests: () => void -} - -export = { - nullifyUnserializableValues, - - handleEvent, - - stop () { - return ipc.removeAllListeners() - }, - - start (options: EventsStartArgs, bus: EventEmitter) { - // curry left options - // ipc.on('request', _.partial(this.handleEvent, options, bus)) - }, -} diff --git a/packages/server/lib/modes/index.ts b/packages/server/lib/modes/index.ts index 5042712fbcae..942eb6b39d12 100644 --- a/packages/server/lib/modes/index.ts +++ b/packages/server/lib/modes/index.ts @@ -28,15 +28,11 @@ export = (mode, options) => { const loadingPromise = ctx.initializeMode() if (mode === 'run') { - if (options.testingType === 'component') { - return require('./run-ct').run(options, loadingPromise) - } - // run must always be deterministic - if the user doesn't specify // a testingType, we default to e2e - options.testingType = 'e2e' + options.testingType = options.testingType || 'e2e' - return require('./run-e2e').run(options, loadingPromise) + return require('./run').run(options, loadingPromise) } if (mode === 'interactive') { diff --git a/packages/server/lib/modes/interactive.ts b/packages/server/lib/modes/interactive.ts index db4cdb9260ed..5796f2023904 100644 --- a/packages/server/lib/modes/interactive.ts +++ b/packages/server/lib/modes/interactive.ts @@ -1,18 +1,19 @@ import _ from 'lodash' import os from 'os' import { app, nativeImage as image } from 'electron' -// eslint-disable-next-line no-duplicate-imports -import type { WebContents } from 'electron' + import * as cyIcons from '@packages/icons' import * as savedState from '../saved_state' import menu from '../gui/menu' import * as Windows from '../gui/windows' import { makeGraphQLServer } from '@packages/graphql/src/makeGraphQLServer' -import { DataContext, globalPubSub, getCtx, clearCtx } from '@packages/data-context' -import type { LaunchArgs, PlatformName } from '@packages/types' -import { EventEmitter } from 'events' +import { globalPubSub, getCtx, clearCtx } from '@packages/data-context' + +// eslint-disable-next-line no-duplicate-imports +import type { WebContents } from 'electron' +import type { LaunchArgs } from '@packages/types' + import debugLib from 'debug' -import Events from '../gui/events' const debug = debugLib('cypress:server:interactive') @@ -153,21 +154,13 @@ export = { return Windows.open(projectRoot, port, this.getWindowArgs(state)) .then((win) => { ctx?.actions.electron.setBrowserWindow(win) - Events.start({ - ...(options as LaunchArgs), - onFocusTests () { - // @ts-ignore - return app.focus({ steal: true }) || win.focus() - }, - os: os.platform() as PlatformName, - }, new EventEmitter()) return win }) }) }, - async run (options, ctx: DataContext) { + async run (options: LaunchArgs, _loading: Promise) { const [, port] = await Promise.all([ app.whenReady(), makeGraphQLServer(), diff --git a/packages/server/lib/modes/run-ct.ts b/packages/server/lib/modes/run-ct.ts deleted file mode 100644 index d2d3fff071fe..000000000000 --- a/packages/server/lib/modes/run-ct.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { LaunchArgs } from '@packages/types' - -export const run = (options: LaunchArgs, loadingPromise: Promise) => { - // TODO: make sure if we need to run this in electron by default to match e2e behavior? - options.browser = options.browser || 'electron' - options.runAllSpecsInSameBrowserSession = true - - return require('./run').run(options, loadingPromise) -} diff --git a/packages/server/lib/modes/run-e2e.js b/packages/server/lib/modes/run-e2e.js deleted file mode 100644 index f1a347a27ed7..000000000000 --- a/packages/server/lib/modes/run-e2e.js +++ /dev/null @@ -1,7 +0,0 @@ -const run = (options, loading) => { - return require('./run').run(options, loading) -} - -module.exports = { - run, -} diff --git a/packages/server/test/integration/cypress_spec.js b/packages/server/test/integration/cypress_spec.js index 68752f90fceb..cddb9234d061 100644 --- a/packages/server/test/integration/cypress_spec.js +++ b/packages/server/test/integration/cypress_spec.js @@ -20,7 +20,6 @@ const argsUtil = require(`../../lib/util/args`) const { fs } = require(`../../lib/util/fs`) const ciProvider = require(`../../lib/util/ci_provider`) const settings = require(`../../lib/util/settings`) -const Events = require(`../../lib/gui/events`) const Windows = require(`../../lib/gui/windows`) const interactiveMode = require(`../../lib/modes/interactive`) const runMode = require(`../../lib/modes/run`) @@ -1641,7 +1640,6 @@ describe('lib/cypress', () => { sinon.stub(electron.app, 'on').withArgs('ready').yieldsAsync() sinon.stub(Windows, 'open').resolves(this.win) sinon.stub(ServerE2E.prototype, 'startWebsockets') - sinon.spy(Events, 'start') sinon.stub(electron.ipcMain, 'on') }) @@ -1660,21 +1658,11 @@ describe('lib/cypress', () => { }) }) - it('passes options to Events.start', () => { - return cypress.start(['--port=2121', '--config=pageLoadTimeout=1000']) - .then(() => { - expect(Events.start).to.be.calledWithMatch({ - config: { - pageLoadTimeout: 1000, - port: 2121, - }, - }) - }) - }) - it('passes filtered options to Project#open and sets cli config', async function () { const open = sinon.stub(ServerE2E.prototype, 'open').resolves([]) + sinon.stub(interactiveMode, 'ready') + process.env.CYPRESS_FILE_SERVER_FOLDER = 'foo' process.env.CYPRESS_BASE_URL = 'http://localhost' process.env.CYPRESS_port = '2222' @@ -1688,7 +1676,7 @@ describe('lib/cypress', () => { return user.set({ name: 'brian', authToken: 'auth-token-123' }) .then(() => ctx.lifecycleManager.getFullInitialConfig()) .then((json) => { - // this should be overriden by the env argument + // this should be overridden by the env argument json.baseUrl = 'http://localhost:8080' const { supportFile, specPattern, excludeSpecPattern, baseUrl, experimentalSessionAndOrigin, slowTestThreshold, ...rest } = json @@ -1705,7 +1693,7 @@ describe('lib/cypress', () => { '--env=baz=baz', ]) }).then(() => { - const options = Events.start.firstCall.args[0] + const options = interactiveMode.ready.firstCall.args[0] return openProject.create(this.todosPath, { ...options, testingType: 'e2e' }, []) }).then(() => { diff --git a/packages/server/test/unit/modes/interactive_spec.js b/packages/server/test/unit/modes/interactive_spec.js index 3d081dac531e..826e5974cc8b 100644 --- a/packages/server/test/unit/modes/interactive_spec.js +++ b/packages/server/test/unit/modes/interactive_spec.js @@ -6,7 +6,6 @@ const electron = require('electron') const DataContext = require('@packages/data-context') const savedState = require(`../../../lib/saved_state`) const menu = require(`../../../lib/gui/menu`) -const Events = require(`../../../lib/gui/events`) const Windows = require(`../../../lib/gui/windows`) const interactiveMode = require(`../../../lib/modes/interactive`) @@ -128,7 +127,6 @@ describe('gui/interactive', () => { this.state = {} sinon.stub(menu, 'set') - sinon.stub(Events, 'start') sinon.stub(Windows, 'open').resolves(this.win) sinon.stub(Windows, 'trackState') @@ -137,18 +135,6 @@ describe('gui/interactive', () => { sinon.stub(state, 'get').resolves(this.state) }) - it('calls Events.start with options, adding env, onFocusTests, and os', () => { - sinon.stub(os, 'platform').returns('someOs') - const opts = {} - - return interactiveMode.ready(opts).then(() => { - expect(Events.start).to.be.called - expect(Events.start.lastCall.args[0].onFocusTests).to.be.a('function') - - expect(Events.start.lastCall.args[0].os).to.equal('someOs') - }) - }) - it('calls menu.set', () => { return interactiveMode.ready({}).then(() => { expect(menu.set).to.be.calledOnce diff --git a/packages/types/src/server.ts b/packages/types/src/server.ts index 1ecc8c7177da..53d5c960dc41 100644 --- a/packages/types/src/server.ts +++ b/packages/types/src/server.ts @@ -30,7 +30,6 @@ export interface LaunchArgs { projectRoot: string // same as above testingType: Cypress.TestingType invokedFromCli: boolean - runAllSpecsInSameBrowserSession?: boolean onError?: (error: Error) => void os: PlatformName exit?: boolean