Files
cypress/packages/server/lib/modes/interactive.ts
T
Matt Henkes 6809d1103b chore: merge dev into feat protocol (#26909)
* chore: add Nx Cloud (#26712)

* chore: add empty nx.json [run ci]

* chore: add nx cloud runner [run ci]

* chore: add nx-cloud dep [run ci]

* chore: update local nx cloud accessToken to be read-only

* feat: update git related messages for runs and debug (#26758)

* feat(app): update DebugError copy

* feat: set isUsingGit project flag and consume in DebugContainer

* feat(app): update not using git icon for DebugError

* feat(app): displays alert on runs page when not using git

* feat(app): add component for when no runs for current branch

* feat(app): add warning for no runs for branch on runs container

* chore: add feat to CHANGELOG

* chore: remove logged status value

* chore: resolve import from merge conflict

* test(app): stub branch name for e2e runs spec

* chore: add line break in changelog entry

* chore: cleanup PR

* chore: fix i18n import for DebugBranchError

* chore: add utm and update Warning links to inline

* chore: capitalize Git in i18n

* ref: warning liink

* test: add i18n to tests

* test(app): change utm_source assertions

* chore: cleanup pr

* chore: remove unused prop

* test(app): remove no git warning when moving to runs page in e2e

* chore: change template logic

* chore: remove duplicate RUNS_TAB_MEDIUM const

* Changed Debug test assertion and reordered new components for Debug

---------

Co-authored-by: Stokes Player <stokes.player@gmail.com>

* chore: rename video processing events to capture/compress (#26800)

* chore: change processing nomenclature to compressing when printing the run.

* chore: rename 'capturing of' to 'capturing'

* chore: rename upload results to upload screenshots & videos (#26811)

* chore: rename upload results to upload screenshots & videos

* run ci

* chore: capture versions of relevant dependencies with `x-dependencies` header (#26814)

* chore: update changlelog script to handle revert pr ref (#26801)

* fix: Correct typescript scaffold dependency (#26815)

* fix: correct typescript scaffold dependency (#26204)

* add changelog

* Update change log for PR comment

Co-authored-by: Mike Plummer <mike-plummer@users.noreply.github.com>

---------

Co-authored-by: Mike Plummer <mike-plummer@users.noreply.github.com>
Co-authored-by: Mark Noonan <mark@cypress.io>

* chore: 12.13.0 prep (#26833)

* chore: 12.13.0 release (#26834)

* chore: 12.13.0 changelog fix

* remove pending, bump version

* fix typo

* chore: release @cypress/vite-plugin-cypress-esm-v1.0.1

[skip ci]

* chore: Implement runSpec mutation (#26782)

* chore: replace gitter badge with discord on readme (#26771)

* chore: add GraphQL mutation for sending system notifications via Electron (#26773)

* fix: upgrade typescript from 4.7.4 to 4.9.5 (#26826)

Snyk has created this PR to upgrade typescript from 4.7.4 to 4.9.5.

See this package in npm:


See this project in Snyk:
https://app.snyk.io/org/cypress-opensource/project/d5b36925-e6ee-455d-9649-6560a9aca413?utm_source=github&utm_medium=referral&page=upgrade-pr

* test: fix 2 broken tests for Windows (#26854)

* Update stale_issues_and_pr_cleanup.yml

Upped the number of operations per run.  Have been manually doing that so this job can get through all the issues in the repo with no problems.

* chore(dep): [Snyk] Upgrade vite from 2.9.13 to 2.9.15 (#26830)

Co-authored-by: Ben M <benm@cypress.io>

* Update triage_add_to_project.yml

* chore: fix minor background color styling in debug results component (#26887)

* Update stale_issues_and_pr_cleanup.yml

stalebot was incorrectly configured to run in debug mode.  I have updated the default to run in normal mode when running scheduled

* chore: Deprecate @cypress/xpath package (#26893)

* chore: add telemetry realworld app (#26896)

* chore: capture telemetry for realworld app maybe

* idk what i was doing

* setup record key and telemetry

* testing

* override project id

* some times we just need a little context.

* Adding tests

* Adding comment

* fix yarn lock

* Trying this....

* fix tests?

---------

Co-authored-by: Jordan <jordan@jpdesigning.com>
Co-authored-by: Stokes Player <stokes.player@gmail.com>
Co-authored-by: Bill Glesias <bglesias@gmail.com>
Co-authored-by: Adam Stone-Lord <adams@cypress.io>
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
Co-authored-by: Dave Kasper <dave.m.kasper@gmail.com>
Co-authored-by: Mike Plummer <mike-plummer@users.noreply.github.com>
Co-authored-by: Mark Noonan <mark@cypress.io>
Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
Co-authored-by: Ely Lucas <ely@meta-tek.net>
Co-authored-by: Snyk bot <snyk-bot@snyk.io>
Co-authored-by: Stokes Player <stokes@cypress.io>
Co-authored-by: Ben M <benm@cypress.io>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
2023-06-02 13:55:39 -05:00

214 lines
6.2 KiB
TypeScript

import _ from 'lodash'
import os from 'os'
import { app, nativeImage as image } 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 { globalPubSub, getCtx, clearCtx } from '@packages/data-context'
import { telemetry } from '@packages/telemetry'
// eslint-disable-next-line no-duplicate-imports
import type { WebContents } from 'electron'
import type { LaunchArgs, Preferences } from '@packages/types'
import debugLib from 'debug'
import { getPathToDesktopIndex } from '@packages/resolve-dist'
const debug = debugLib('cypress:server:interactive')
const isDev = () => {
return Boolean(process.env['CYPRESS_INTERNAL_ENV'] === 'development')
}
export = {
isMac () {
return os.platform() === 'darwin'
},
getWindowArgs (url: string, state: Preferences) {
// Electron Window's arguments
// These options are passed to Electron's BrowserWindow
const minWidth = Math.round(/* 13" MacBook Air */ 1792 / 3) // Thirds
const preferredWidth = 1200
const minHeight = 400
const preferredHeight = 800
const chooseDimensions = ({ preferred, previous, minimum }) => {
// If the user doesn't have a previous size that's valid or big
// enough, use the preferred size instead.
if (!previous || previous < minimum) {
return preferred
}
return previous
}
const common = {
url,
// The backgroundColor should match the value we will show in the
// launchpad frontend.
// When we use a dist'd launchpad (production), this color won't be
// as visible. However, in our local dev setup (launchpad running via
// a dev server), the backgroundColor will flash if it is a
// different color.
backgroundColor: 'white',
// Dimensions of the Electron window on initial launch.
// Because we are migrating users that may have
// a width smaller than the min dimensions, we will
// force the dimensions to be within the minimum bounds.
//
// Doing this before launch (instead of relying on minW + minH)
// prevents the window from jumping.
width: chooseDimensions({
preferred: preferredWidth,
minimum: minWidth,
previous: state.appWidth,
}),
height: chooseDimensions({
preferred: preferredHeight,
minimum: minHeight,
previous: state.appHeight,
}),
minWidth,
minHeight,
x: state.appX,
y: state.appY,
type: 'INDEX',
devTools: state.isAppDevToolsOpen,
trackState: {
width: 'appWidth',
height: 'appHeight',
x: 'appX',
y: 'appY',
devTools: 'isAppDevToolsOpen',
},
onBlur (this: {webContents: WebContents}) {
if (this.webContents.isDevToolsOpened()) {
return
}
return Windows.hideAllUnlessAnotherWindowIsFocused()
},
onFocus () {
// hide internal dev tools if in production and previously focused
// window was the electron browser
menu.set({ withInternalDevTools: isDev() })
return Windows.showAll()
},
onClose () {
app.quit()
},
}
return _.extend(common, this.platformArgs())
},
platformArgs () {
const args = {
darwin: {
show: true,
frame: true,
transparent: false,
},
linux: {
show: true,
frame: true,
transparent: false,
icon: image.createFromPath(cyIcons.getPathToIcon('icon_64x64.png')),
},
}
return args[os.platform()]
},
async ready (options: LaunchArgs, launchpadPort: number) {
const { projectRoot } = options
const ctx = getCtx()
menu.set({
withInternalDevTools: isDev(),
onLogOutClicked () {
return globalPubSub.emit('menu:item:clicked', 'log:out')
},
getGraphQLPort: () => {
return ctx?.gqlServerPort
},
})
const State = await savedState.create(projectRoot, false)
const state = await State.get()
const url = getPathToDesktopIndex(launchpadPort)
const win = await Windows.open(projectRoot, this.getWindowArgs(url, state))
ctx?.actions.electron.setBrowserWindow(win)
return win
},
async run (options: LaunchArgs, _loading: Promise<void>) {
// Need to set this for system notifications to appear as "Cypress" on Windows
if (app.setAppUserModelId) {
app.setAppUserModelId('Cypress')
}
// Note: We do not await the `_loading` promise here since initializing
// the data context can significantly delay initial render of the UI
// https://github.com/cypress-io/cypress/issues/26388#issuecomment-1492616609
const [, port] = await Promise.all([
app.whenReady(),
makeGraphQLServer(),
])
// Before the electron app quits, we interrupt and ensure the current
// DataContext is completely destroyed prior to quitting the process.
// Parts of the DataContext teardown are asynchronous, particularly the
// closing of open file watchers, and not awaiting these can cause
// the electron process to throw.
// https://github.com/cypress-io/cypress/issues/22026
app.once('will-quit', (event: Event) => {
// We must call synchronously call preventDefault on the will-quit event
// to halt the current quit lifecycle
event.preventDefault()
debug('clearing DataContext prior to quit')
// We use setImmediate to guarantee that app.quit will be called asynchronously;
// synchronously calling app.quit in the will-quit handler prevent the subsequent
// close from occurring
setImmediate(async () => {
try {
await clearCtx()
} catch (e) {
// Silently handle clearCtx errors, we still need to quit the app
debug(`DataContext cleared with error: ${e?.message}`)
}
debug('DataContext cleared, quitting app')
telemetry.getSpan('cypress')?.end()
await telemetry.shutdown()
app.quit()
})
})
telemetry.getSpan('startup:time')?.end()
return this.ready(options, port)
},
}