diff --git a/.changeset/electron-launch-failures.md b/.changeset/electron-launch-failures.md new file mode 100644 index 0000000000..eae45d22bd --- /dev/null +++ b/.changeset/electron-launch-failures.md @@ -0,0 +1,5 @@ +--- +'@e2e-dev/electron': patch +--- + +A failed `app.open()` says why it failed instead of `TEST_TIMEOUT`: the launch keeps a moment of the operation's time to ask the app and end it. A launch whose window loaded just as the wait ran out still sets the app up. On macOS the engine starts the app with `-ApplePersistenceIgnoreState YES`, so an app the engine killed in an earlier test no longer stalls its next launch behind a "reopen windows?" alert. A launch failure quotes a stderr line over 500 characters by its length only, a dialog handler from one attempt never answers the next one's dialogs, and an attempt ends cleanly when its user-data directory cannot be removed. diff --git a/docs/reference/electron.mdx b/docs/reference/electron.mdx index 4768325d94..cbdba07bef 100644 --- a/docs/reference/electron.mdx +++ b/docs/reference/electron.mdx @@ -183,14 +183,15 @@ export default { | --- | --- | | `INVALID_CONFIG` | At config load: an `app.url`, an `app.bundleId`, or `app.permissions`; neither `app.appPath` nor `executablePath`; or an `app.launchArguments` entry the engine owns (see [Launch arguments](#launch-arguments)). | | `INVALID_CONFIG` | When the worker starts: `app.appPath` does not name an app the binary can run. The message says what is wrong with the path. | -| `APP_NOT_OPEN` | The app quit before it opened a window, or right after it opened its first one. The message quotes the last lines the app wrote to stderr. | +| `APP_NOT_OPEN` | The app quit before it opened a window, or right after it opened its first one. The message quotes the last lines the app wrote to stderr; a line over 500 characters shows only its length. | +| `APP_NOT_OPEN` | No window loaded a page in the launch's time: the app opened none, its windows loaded nothing, or Electron never became ready. The message says which, and on macOS suggests `--use-mock-keychain` for an app that waits on a keychain prompt. | | `ENGINE_FAILURE` | The operating system refused to start the binary. | #### Launch arguments The engine starts every app with switches of its own, before the target's `app.launchArguments` and a test's -[`launch({ launchArguments })`](#launch). An app with a strict argument parser must allow +[`launch({ launchArguments })`](#launch), and on macOS one after them. An app with a strict argument parser must allow them. | Switch | Why | @@ -202,6 +203,7 @@ them. | `--disable-features=CalculateNativeWinOcclusion` | The same. Left out when your arguments set `--disable-features`. | | `--no-sandbox` | On Linux only. | | `--user-data-dir=` | The test's own [user-data directory](#userdatadir). | +| `-ApplePersistenceIgnoreState YES` | On macOS only, after your arguments: an app the engine killed is not asked, in a modal alert, whether to reopen its windows. macOS reads the setting only as two arguments, so the app's `process.argv` ends with both, `-ApplePersistenceIgnoreState` and then `YES`, which is no switch. An app that opens its leftover arguments as files or URLs must skip both. | `app.launchArguments` and `launch({ launchArguments })` must not set `--user-data-dir`, `--inspect`, `--inspect-brk`, `--remote-debugging-port`, or diff --git a/packages/electron/src/app-process.ts b/packages/electron/src/app-process.ts index e0f5d57430..90aed6a32b 100644 --- a/packages/electron/src/app-process.ts +++ b/packages/electron/src/app-process.ts @@ -54,6 +54,16 @@ const ANSWER_MS = 500; /** How long a killed app gets to exit, and let go of its files, before its data is deleted. */ const EXIT_WAIT_MS = 2_000; +/** How long a failed launch waits for each answer it asks the app for, to say why it failed. */ +const FAILURE_ANSWER_MS = 250; + +/** + * What a failed launch keeps of its time to say why and end the app: the main + * process and its ready state asked, then the app killed and its exit waited + * for as long again. + */ +const FAILURE_REPORT_MS = 3 * FAILURE_ANSWER_MS; + /** How long setting the downloads directory may take of a launch's budget. */ const DOWNLOADS_SETUP_MS = 2_000; @@ -73,6 +83,9 @@ const INSPECTOR_GRACE_MS = 500; /** How many of the app's last stderr lines a failed launch quotes. */ const QUOTED_STDERR_LINES = 10; +/** The longest stderr line a launch failure quotes, in characters. */ +const QUOTED_LINE_CHARS = 500; + /** One launched app. */ interface RunningApp { readonly process: ElectronProcess; @@ -101,6 +114,8 @@ export interface AppDownload { export class AppProcess { private app: RunningApp | undefined; private exit: string | undefined; + /** The exit of an app a failed launch killed, which the next quit waits for. */ + private exiting: Promise | undefined; private directory: string | undefined; private queue: Promise = Promise.resolve(); @@ -138,14 +153,20 @@ export class AppProcess { } /** Quits the running app, if any: a graceful quit within `graceMs` and the budget, then its process tree killed. */ - async quit(budget: { readonly timeoutMs: number }, graceMs: number): Promise { + async quit(budget: { readonly timeoutMs: number }, graceMs: number, exitWaitMs = EXIT_WAIT_MS): Promise { + // A failed launch waited only briefly for the app it killed: its files in the user-data directory, removed after + // this quit, are let go of first. + const exiting = this.exiting; + this.exiting = undefined; + if (exiting !== undefined) await answerWithin(exiting, EXIT_WAIT_MS); const app = this.app; this.app = undefined; this.exit = undefined; this.directory = undefined; this.windows.clear(); if (app === undefined) return; - await stop(app, Math.min(budget.timeoutMs, graceMs)); + await stop(app, Math.min(budget.timeoutMs, graceMs), exitWaitMs); + if (app.process.ended === undefined && exitWaitMs < EXIT_WAIT_MS) this.exiting = app.process.exited; } /** @@ -158,9 +179,11 @@ export class AppProcess { // rather than the operation timing out; each phase gets what the ones before it left. // An operation cancelled, or out of time after the quit before it, starts no app. budget.check(); - const timeout = Math.max(1, budget.waits.remaining()); + // A failed launch then asks the app why and quits it: that is left out of the launch's own time, up to half of it. + // With under 1.5 s left, half is less than the report can take, so a very short launch can still end in TEST_TIMEOUT. + const available = budget.waits.remaining(); + const timeout = Math.max(1, available - Math.min(FAILURE_REPORT_MS, available / 2)); const deadline = new Deadline(timeout); - const left = (): number => Math.max(1, deadline.remaining()); let app: RunningApp; let opened = false; try { @@ -181,7 +204,10 @@ export class AppProcess { const window = (): Promise => raceAbort(() => Promise.race([loaded(open, deadline, operation.signal), quitEarly]), operation.signal, 'waiting for the first window to load'); let first = await window(); opened = true; - // Still inside the launch: an app that quits here, or a caller that stopped waiting, fails it. + // Still inside the launch: an app that quits here, or a caller that stopped waiting, fails it. A window that loaded + // as the wait for one ran out still gets the operation's time to connect its main process and place its downloads: + // with none left, an app with an inspector would be taken for one with none, and save downloads where it likes. + const left = (): number => Math.max(1, budget.waits.remaining()); const reported = await raceAbort(() => Promise.race([this.setUp(app, setup, left), quitEarly]), operation.signal, 'setting up the app'); // A splash screen can close while the app is set up: the launch ends on a window that is there. while (first.isClosed()) first = await window(); @@ -193,11 +219,13 @@ export class AppProcess { } catch (cause) { // Read before the engine's own quit, which ends the process too. const exited = app.process.ended; - const main = exited === undefined ? await answerWithin(app.main, ANSWER_MS) : undefined; + const main = exited === undefined ? await answerWithin(app.main, FAILURE_ANSWER_MS) : undefined; // Electron can stall before its ready event on a loaded machine; say so rather than blame the app's window. - const ready = main === undefined ? undefined : await answerWithin(main.evaluate(({ app: electronApp }) => electronApp.isReady(), undefined), ANSWER_MS); + const ready = main === undefined ? undefined : await answerWithin(main.evaluate(({ app: electronApp }) => electronApp.isReady(), undefined), FAILURE_ANSWER_MS); const stuck = [...app.pages.values()].filter((page) => !this.windows.has(page)).length; - await this.quit({ timeoutMs: DISCARD_CLOSE_MS }, DISCARD_CLOSE_MS); + // Killed, with no graceful quit and only a moment's wait for its exit: an app that failed to launch has nothing to + // save, and the time is the report's. The next quit waits for the rest. + await this.quit({ timeoutMs: 0 }, 0, FAILURE_ANSWER_MS); if (cause instanceof EngineError) throw cause; throw launchError(setup, app.process, { exited, ready, stuck, timeout, opened }, cause); } @@ -444,13 +472,32 @@ export class AppProcess { } } +/** + * A stderr line as a failed launch quotes it: whole up to `QUOTED_LINE_CHARS` + * characters, and only its length past that. Any cut, at white space too, + * could keep the start of a secret, which the run's redaction, matching whole + * values only, would let through. + */ +function quotedLine(line: string): string { + return line.length <= QUOTED_LINE_CHARS ? line : `(a line of ${line.length} characters)`; +} + const NO_INSPECTOR = 'the app\'s main process opened no inspector, so electron.evaluate cannot run in it and windows are known by their document titles only: a packaged app built with the EnableNodeCliInspectArguments fuse off ignores --inspect'; /** Ends an app: a graceful quit within `graceMs`, then its process tree killed and waited for. */ -async function stop(app: RunningApp, graceMs: number): Promise { +async function stop(app: RunningApp, graceMs: number, exitWaitMs: number): Promise { const { process } = app; if (process.ended !== undefined) return; + if (graceMs > 0 && (await quitGracefully(app, graceMs))) return; + process.killNow(); + // Its files in the user-data directory are deleted next: wait, briefly, until it has let go of them. + await answerWithin(process.exited, exitWaitMs); +} + +/** Asks the app to quit, and whether it exited within `graceMs`. */ +async function quitGracefully(app: RunningApp, graceMs: number): Promise { + const { process } = app; const main = await answerWithin(app.main, ANSWER_MS); if (main === undefined) { void process.browser.root.send('Browser.close').catch(() => undefined); @@ -465,10 +512,7 @@ async function stop(app: RunningApp, graceMs: number): Promise { ); void main.evaluate(({ app: electronApp }) => electronApp.quit(), undefined).catch(() => undefined); } - if ((await answerWithin(process.exited, graceMs)) !== undefined) return; - process.killNow(); - // Its files in the user-data directory are deleted next: wait, briefly, until it has let go of them. - await answerWithin(process.exited, EXIT_WAIT_MS); + return (await answerWithin(process.exited, graceMs)) !== undefined; } /** The first of the app's open windows, in the order they opened, to have a parsed document: a window is read from then on. */ @@ -532,7 +576,8 @@ function launchError( /** What the app wrote to stderr, for a failure's message; empty when it wrote nothing. */ function stderrQuote(process: ElectronProcess): string { - const lines = process.stderrTail(QUOTED_STDERR_LINES); + // A longer line is left out: a minified stack or a data: URL in one would fill the report. + const lines = process.stderrTail(QUOTED_STDERR_LINES).map(quotedLine); return lines.length === 0 ? '' : `. The app wrote to stderr:\n${lines.join('\n')}`; } diff --git a/packages/electron/src/dialogs.ts b/packages/electron/src/dialogs.ts index e0c66af769..4c3503de50 100644 --- a/packages/electron/src/dialogs.ts +++ b/packages/electron/src/dialogs.ts @@ -34,7 +34,9 @@ function classified(cause: unknown): cause is Error { export class DialogRouter { private registrations: { readonly handler: DialogHandler }[] = []; private pending: Error | undefined; - private readonly running = new Set>(); + private running = new Set>(); + /** Bumped by `reset`: a handler of an earlier attempt that is still running reports into none of the next one's state. */ + private generation = 0; /** Registers a handler, the newest winning, and returns what removes it. */ add(handler: DialogHandler): () => void { @@ -49,6 +51,8 @@ export class DialogRouter { reset(): void { this.registrations = []; this.pending = undefined; + this.running = new Set(); + this.generation += 1; } /** The failure a dialog left for the next step, once. */ @@ -66,16 +70,18 @@ export class DialogRouter { /** Answers one dialog through the newest handler. */ dispatch(dialog: OpenDialog): void { const work = this.route(dialog).catch(() => undefined); - this.running.add(work); - void work.then(() => this.running.delete(work)); + const { running } = this; + running.add(work); + void work.then(() => running.delete(work)); } private async route(dialog: OpenDialog): Promise { const handler = this.registrations.at(-1)?.handler; const { type, message } = dialog; + const { generation } = this; // The first failure is the one to report: the app's later dialogs follow from it. const fail = (error: Error): void => { - this.pending ??= error; + if (this.generation === generation) this.pending ??= error; }; if (handler === undefined) { fail(new EngineError('INVALID_STATE', `unhandled ${type} dialog: ${message}; answer it with electron.onDialog('accept'), 'dismiss', or a handler`, { retryable: false })); diff --git a/packages/electron/src/launcher.ts b/packages/electron/src/launcher.ts index ff05cbe660..fb503cb75d 100644 --- a/packages/electron/src/launcher.ts +++ b/packages/electron/src/launcher.ts @@ -36,8 +36,21 @@ export interface ProcessExit { readonly signal: NodeJS.Signals | null; } +/** The command line an app starts with: the engine's switches, the caller's own (the app path first), then the engine's for the OS. */ +export function processArguments(args: readonly string[], platform: NodeJS.Platform = process.platform): string[] { + return [ + ...engineArguments(args, platform), + ...args, + // macOS asks, in a modal alert before the app is ready, whether to reopen the windows of an app that quit uncleanly, + // as the engine's kills leave it: the launch would wait out its timeout. After the app's own arguments, since Electron + // takes the first one that is no switch as the app's path. Two arguments, both left in the app's argv, the YES no switch: macOS + // reads no one-argument form (`-ApplePersistenceIgnoreState=YES` sets nothing on Electron 45). + ...(platform === 'darwin' ? ['-ApplePersistenceIgnoreState', 'YES'] : []), + ]; +} + /** The switches the engine starts every app with, before the caller's own. */ -export function engineArguments(args: readonly string[], platform: NodeJS.Platform = process.platform): string[] { +function engineArguments(args: readonly string[], platform: NodeJS.Platform): string[] { return [ // The main process's inspector, on a port of its own choosing, for electron.evaluate. '--inspect=0', @@ -86,7 +99,7 @@ export class ElectronProcess { constructor(command: LaunchCommand) { killAtExit(); - this.child = spawn(command.executable, [...engineArguments(command.args), ...command.args], { + this.child = spawn(command.executable, processArguments(command.args), { cwd: command.cwd, env: command.env, // fd 3 carries the engine's commands and fd 4 the browser's answers. stdout is not read: an unread pipe would stall the app. diff --git a/packages/electron/src/surface.ts b/packages/electron/src/surface.ts index a4c46454a9..77961258a5 100644 --- a/packages/electron/src/surface.ts +++ b/packages/electron/src/surface.ts @@ -136,14 +136,19 @@ export class ElectronSurface { this.recorder = undefined; await uncollected?.abandon().catch(() => undefined); await this.app.serialized(() => this.app.quit(context, DISCARD_CLOSE_MS)); - // Retried: Chromium's helper processes can still be closing their files in it. - if (this.userDataDir !== undefined) rmSync(this.userDataDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); + const { userDataDir, uploadsDir } = this; this.userDataDir = undefined; - if (this.uploadsDir !== undefined) rmSync(this.uploadsDir, { recursive: true, force: true }); this.uploadsDir = undefined; this.attempt = undefined; // settleAttempt reported what the attempt's dialogs left; its handlers go with it. this.dialogs.reset(); + try { + // Retried: Chromium's helper processes can still be closing their files in it. + if (userDataDir !== undefined) rmSync(userDataDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); + } finally { + // Removed even when the user-data directory could not be, so the next attempt never finds this one's files. + if (uploadsDir !== undefined) rmSync(uploadsDir, { recursive: true, force: true }); + } } /** A dialog the test's last step opened has no next step to fail: the attempt fails with it, as a step would. */ diff --git a/packages/electron/tests/integration/launch.test.ts b/packages/electron/tests/integration/launch.test.ts index 88f397ee2e..7934d42267 100644 --- a/packages/electron/tests/integration/launch.test.ts +++ b/packages/electron/tests/integration/launch.test.ts @@ -160,6 +160,14 @@ describe('launch', () => { expect(String(await launch().then(() => undefined, (error: unknown) => error))).toMatch(/license failure/); }); + it('quotes no part of a long stderr line, which could cut a secret that holds white space', async () => { + const { launch } = appWith(`process.stderr.write('short line\\n' + 'x'.repeat(498) + ' secret value ' + 'y'.repeat(5000) + '\\n'); process.exit(3);`); + const message = String(await launch().then(() => undefined, (error: unknown) => error)); + expect(message).toContain('short line\n(a line of 5512 characters)'); + expect(message).not.toMatch(/x{2}|secret/); + expect(message.length).toBeLessThan(2000); + }); + it('says how the app ended, with what it wrote to stderr, when it quits before a window', async () => { const { directory, launch } = appWith(`console.error('license check failed'); process.exit(3);`); const failure = await launch().then(() => undefined, (error: unknown) => error); @@ -183,6 +191,22 @@ describe('launch', () => { expect(String(failure)).toMatch(/1 window has loaded nothing yet/); }); + it('reports why a launch failed within the operation\'s time, for an app whose main process is stuck', async () => { + const { directory, launch } = appWith(`app.whenReady().then(() => { new BrowserWindow({ show: false }); const until = Date.now() + 60_000; while (Date.now() < until); });`); + const started = Date.now(); + const failure = await launch(8000, AbortSignal.timeout(8000)).then(() => undefined, (error: unknown) => error); + // Its reasons and its quit fit in what the launch left, so the caller's own timeout never takes the failure's place. + expect(Date.now() - started).toBeLessThan(8000); + expect(String(failure)).toMatch(/the app opened no window within \d+ms/); + expect(await gone(directory)).toBe(true); + }); + + it('gives the first window nearly all of the launch\'s time, keeping only a moment to say why it failed', async () => { + const { windows, launch } = appWith(`app.whenReady().then(() => setTimeout(() => { ${LOADED}; }, 2500));`); + await launch(4000); + expect(windows.open()).toHaveLength(1); + }); + it('starts no app when the operation spent all its time before the launch', async () => { const { directory, launch } = appWith(`require('node:fs').writeFileSync(require('node:path').join(__dirname, 'started'), '1'); app.whenReady().then(() => { ${LOADED}; });`); const failure = await launch(500, AbortSignal.timeout(5000), 700).then(() => undefined, (error: unknown) => error); diff --git a/packages/electron/tests/integration/test-window.ts b/packages/electron/tests/integration/test-window.ts index e4f2fe0191..e440517eb5 100644 --- a/packages/electron/tests/integration/test-window.ts +++ b/packages/electron/tests/integration/test-window.ts @@ -17,6 +17,9 @@ app.whenReady().then(() => new BrowserWindow({ show: false, width: 800, height: app.on('window-all-closed', () => app.quit()); `; +/** How long the window gets to open: under vitest's 30 s hook timeout. */ +const STARTUP_MS = 20_000; + export interface TestWindow { readonly page: PageTarget; /** Replaces the window's document with `html`. */ @@ -38,7 +41,15 @@ export async function openTestWindow(): Promise { const app = new ElectronProcess({ executable: electronBinary(), args: [`--user-data-dir=${path.join(directory, 'data')}`, directory], cwd: directory, env: launchEnvironment() }); const { root } = app.browser; - const page = await new Promise((resolve, reject) => { + const stop = async (): Promise => { + app.killNow(); + await app.exited; + rmSync(directory, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); + }; + + const opened = new Promise((resolve, reject) => { + // Under the test's hook timeout, so a window that never opens fails the test here rather than leaving Electron running. + setTimeout(() => reject(new Error(`Electron opened no window within ${STARTUP_MS}ms:\n${app.stderrTail(10).join('\n')}`)), STARTUP_MS).unref(); void app.exited.then(() => reject(new Error(`Electron exited before it opened a window:\n${app.stderrTail(10).join('\n')}`))); root.on('Target.targetCreated', ({ targetInfo }) => { if (targetInfo.type !== 'page') return; @@ -52,6 +63,10 @@ export async function openTestWindow(): Promise { }); root.send('Target.setDiscoverTargets', { discover: true }).catch(reject); }); + const page = await opened.catch(async (cause: unknown) => { + await stop(); + throw cause; + }); const { session } = page; const inPage = async (fn: (arg: A) => R | Promise, arg?: A): Promise => { @@ -80,10 +95,6 @@ export async function openTestWindow(): Promise { return { x, y, width, height }; }, selector), inputValue: (selector) => inPage((query: string) => (document.querySelector(query) as HTMLInputElement).value, selector), - async close() { - app.killNow(); - await app.exited; - rmSync(directory, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); - }, + close: stop, }; } diff --git a/packages/electron/tests/unit/dialogs.test.ts b/packages/electron/tests/unit/dialogs.test.ts new file mode 100644 index 0000000000..c8566643bc --- /dev/null +++ b/packages/electron/tests/unit/dialogs.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from 'vitest'; +import { DialogRouter } from '../../src/dialogs.ts'; + +describe('DialogRouter', () => { + it('keeps a handler that outlives its attempt from failing the next one', async () => { + const router = new DialogRouter(); + let release: () => void = () => undefined; + const blocked = new Promise((resolve) => { + release = resolve; + }); + router.add(async () => { + await blocked; + throw new Error('failed in the earlier attempt'); + }); + router.dispatch({ type: 'confirm', message: 'Delete?', answer: () => Promise.resolve() }); + const earlier = router.settled(); + // The attempt ended while its handler still ran. + router.reset(); + await router.settled(); + release(); + await earlier; + expect(router.take()).toBeUndefined(); + }); +}); diff --git a/packages/electron/tests/unit/launch.test.ts b/packages/electron/tests/unit/launch.test.ts index 428e948632..3a374c5b3f 100644 --- a/packages/electron/tests/unit/launch.test.ts +++ b/packages/electron/tests/unit/launch.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest'; import { keyChord } from '../../src/actions.ts'; import { launchEnv } from '../../src/app-process.ts'; -import { engineArguments } from '../../src/launcher.ts'; +import { processArguments } from '../../src/launcher.ts'; describe('launchEnv', () => { it('gives the app what a process needs to start and draw, never the rest of the run\'s environment', () => { @@ -23,17 +23,22 @@ describe('launchEnv', () => { }); }); -describe('engineArguments', () => { - it('opens the main process\'s inspector and the DevTools pipe, and no port', () => { +describe('processArguments', () => { + it('opens the main process\'s inspector and the DevTools pipe, and no port, before the caller\'s arguments', () => { const drawing = ['--disable-backgrounding-occluded-windows', '--disable-renderer-backgrounding', '--disable-background-timer-throttling']; - expect(engineArguments([], 'darwin')).toEqual(['--inspect=0', '--remote-debugging-pipe', '--force-color-profile=srgb', ...drawing, '--disable-features=CalculateNativeWinOcclusion']); - expect(engineArguments(['--force-color-profile=display-p3-d65', '--disable-features=Other'], 'darwin')).toEqual(['--inspect=0', '--remote-debugging-pipe', ...drawing]); + expect(processArguments(['/app'], 'win32')).toEqual(['--inspect=0', '--remote-debugging-pipe', '--force-color-profile=srgb', ...drawing, '--disable-features=CalculateNativeWinOcclusion', '/app']); + expect(processArguments(['--force-color-profile=display-p3-d65', '--disable-features=Other'], 'win32')).toEqual(['--inspect=0', '--remote-debugging-pipe', ...drawing, '--force-color-profile=display-p3-d65', '--disable-features=Other']); }); it('turns Chromium\'s sandbox off on Linux, once', () => { - expect(engineArguments([], 'linux')).toContain('--no-sandbox'); - expect(engineArguments(['--no-sandbox'], 'linux')).not.toContain('--no-sandbox'); - expect(engineArguments([], 'win32')).not.toContain('--no-sandbox'); + expect(processArguments([], 'linux')).toContain('--no-sandbox'); + expect(processArguments(['--no-sandbox'], 'linux').filter((argument) => argument === '--no-sandbox')).toHaveLength(1); + expect(processArguments([], 'win32')).not.toContain('--no-sandbox'); + }); + + it('keeps macOS from asking to reopen the windows of an app that quit uncleanly, after the app\'s path and arguments', () => { + expect(processArguments(['/app', '--greeting=hi'], 'darwin').slice(-4)).toEqual(['/app', '--greeting=hi', '-ApplePersistenceIgnoreState', 'YES']); + expect(processArguments(['/app'], 'linux')).not.toContain('-ApplePersistenceIgnoreState'); }); });