Skip to content

Commit 81f1824

Browse files
authored
fix: do not forward geckoDriverVersion as a CLI argument to geckodriver binary (#732)
1 parent 5eee840 commit 81f1824

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import type { GeckodriverParameters } from './types.js'
99
const log = logger('geckodriver')
1010

1111
export async function start (params: GeckodriverParameters): Promise<ChildProcess> {
12-
const { cacheDir, customGeckoDriverPath, spawnOpts, ...startArgs } = params
12+
const { cacheDir, customGeckoDriverPath, spawnOpts, geckoDriverVersion, ...startArgs } = params
1313
let geckoDriverPath = (
1414
customGeckoDriverPath ||
1515
process.env.GECKODRIVER_PATH ||
1616
// deprecated
1717
process.env.GECKODRIVER_FILEPATH
1818
)
1919
if (!geckoDriverPath) {
20-
geckoDriverPath = await downloadDriver(params.geckoDriverVersion, cacheDir)
20+
geckoDriverPath = await downloadDriver(geckoDriverVersion, cacheDir)
2121
}
2222

2323
if (!(await hasAccess(geckoDriverPath))) {

tests/start-unit.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import cp from 'node:child_process'
33
import { vi, test, expect } from 'vitest'
44
import { type GeckodriverParameters, start } from '../src/index.ts'
5+
import { download } from '../src/install.js'
56

67
test('start', async () => {
78
vi.mock('../src/install.js', () => {
@@ -38,4 +39,24 @@ test('start', async () => {
3839
MOZ_HEADLESS_WIDTH: '720'
3940
}
4041
})
42+
})
43+
44+
test('start does not forward geckoDriverVersion as a Geckodriver CLI argument', async () => {
45+
vi.mocked(cp.spawn).mockClear()
46+
vi.mocked(download).mockClear()
47+
48+
const args: GeckodriverParameters = {
49+
geckoDriverVersion: '0.36.0'
50+
}
51+
52+
await start(args)
53+
54+
// the version is used to download the correct driver binary...
55+
expect(download).toHaveBeenCalledWith('0.36.0', undefined)
56+
57+
// ...but must not be passed to the Geckodriver executable (it rejects
58+
// unknown args, e.g. "unexpected argument '--gecko-driver-version' found")
59+
const spawnArgs = vi.mocked(cp.spawn).mock.calls[0][1] as string[]
60+
expect(spawnArgs).not.toContain('--gecko-driver-version=0.36.0')
61+
expect(spawnArgs.some((arg) => arg.startsWith('--gecko-driver-version'))).toBe(false)
4162
})

0 commit comments

Comments
 (0)