|
| 1 | +import os from 'os' |
| 2 | +import sinon from 'sinon' |
| 3 | +import mockedEnv from 'mocked-env' |
| 4 | +import { appendElectronSwitches } from '../../lib/append_electron_switches' |
| 5 | + |
| 6 | +describe('lib/append_electron_switches', () => { |
| 7 | + beforeEach(() => { |
| 8 | + sinon.stub(os, 'platform').returns('linux') |
| 9 | + }) |
| 10 | + |
| 11 | + afterEach(() => { |
| 12 | + sinon.restore() |
| 13 | + }) |
| 14 | + |
| 15 | + // @see https://github.com/electron/electron/issues/46538 |
| 16 | + // @see https://github.com/cypress-io/cypress/issues/32361 |
| 17 | + context('sets gtk-version=3 in Electron >= 36', () => { |
| 18 | + it('sets launch args', async () => { |
| 19 | + const mockApp = { |
| 20 | + commandLine: { |
| 21 | + appendSwitch: sinon.stub(), |
| 22 | + }, |
| 23 | + } as unknown as Electron.App |
| 24 | + |
| 25 | + appendElectronSwitches(mockApp) |
| 26 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--gtk-version', '3') |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + context('disables hardware acceleration on Linux', () => { |
| 31 | + it('disables hardware acceleration', async () => { |
| 32 | + const mockApp = { |
| 33 | + disableHardwareAcceleration: sinon.stub(), |
| 34 | + commandLine: { |
| 35 | + appendSwitch: sinon.stub(), |
| 36 | + }, |
| 37 | + } as unknown as Electron.App |
| 38 | + |
| 39 | + appendElectronSwitches(mockApp) |
| 40 | + expect(mockApp.disableHardwareAcceleration).to.have.been.called |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
| 44 | + context('parses ELECTRON_EXTRA_LAUNCH_ARGS', () => { |
| 45 | + let restore = null |
| 46 | + |
| 47 | + afterEach(() => { |
| 48 | + if (restore) { |
| 49 | + return restore() |
| 50 | + } |
| 51 | + }) |
| 52 | + |
| 53 | + it('sets launch args', async () => { |
| 54 | + restore = mockedEnv({ |
| 55 | + ELECTRON_EXTRA_LAUNCH_ARGS: '--foo --bar=baz --quux=true', |
| 56 | + }) |
| 57 | + |
| 58 | + const mockApp = { |
| 59 | + disableHardwareAcceleration: sinon.stub(), |
| 60 | + commandLine: { |
| 61 | + appendSwitch: sinon.stub(), |
| 62 | + }, |
| 63 | + } as unknown as Electron.App |
| 64 | + |
| 65 | + appendElectronSwitches(mockApp) |
| 66 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--foo') |
| 67 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--bar', 'baz') |
| 68 | + |
| 69 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--quux', 'true') |
| 70 | + }) |
| 71 | + |
| 72 | + it('sets launch args with zero', async () => { |
| 73 | + restore = mockedEnv({ |
| 74 | + ELECTRON_EXTRA_LAUNCH_ARGS: '--foo --bar=baz --quux=0', |
| 75 | + }) |
| 76 | + |
| 77 | + const mockApp = { |
| 78 | + disableHardwareAcceleration: sinon.stub(), |
| 79 | + commandLine: { |
| 80 | + appendSwitch: sinon.stub(), |
| 81 | + }, |
| 82 | + } as unknown as Electron.App |
| 83 | + |
| 84 | + appendElectronSwitches(mockApp) |
| 85 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--foo') |
| 86 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--bar', 'baz') |
| 87 | + |
| 88 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--quux', '0') |
| 89 | + }) |
| 90 | + |
| 91 | + it('sets launch args with false', async () => { |
| 92 | + restore = mockedEnv({ |
| 93 | + ELECTRON_EXTRA_LAUNCH_ARGS: '--foo --bar=baz --quux=false', |
| 94 | + }) |
| 95 | + |
| 96 | + const mockApp = { |
| 97 | + disableHardwareAcceleration: sinon.stub(), |
| 98 | + commandLine: { |
| 99 | + appendSwitch: sinon.stub(), |
| 100 | + }, |
| 101 | + } as Electron.App |
| 102 | + |
| 103 | + appendElectronSwitches(mockApp) |
| 104 | + |
| 105 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--foo') |
| 106 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--bar', 'baz') |
| 107 | + |
| 108 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--quux', 'false') |
| 109 | + }) |
| 110 | + |
| 111 | + it('sets launch args with multiple values inside quotes', async () => { |
| 112 | + restore = mockedEnv({ |
| 113 | + ELECTRON_EXTRA_LAUNCH_ARGS: `--foo --ipsum=0 --bar=--baz=quux --lorem='--ipsum=dolor --sit=amet'`, |
| 114 | + }) |
| 115 | + |
| 116 | + const mockApp = { |
| 117 | + disableHardwareAcceleration: sinon.stub(), |
| 118 | + commandLine: { |
| 119 | + appendSwitch: sinon.stub(), |
| 120 | + }, |
| 121 | + } as Electron.App |
| 122 | + |
| 123 | + appendElectronSwitches(mockApp) |
| 124 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--foo') |
| 125 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--ipsum', '0') |
| 126 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--bar', '--baz=quux') |
| 127 | + expect(mockApp.commandLine.appendSwitch).to.have.been.calledWith('--lorem', '--ipsum=dolor --sit=amet') |
| 128 | + }) |
| 129 | + }) |
| 130 | +}) |
0 commit comments