Skip to content

Commit

Permalink
chore: increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Nov 2, 2024
1 parent 964445f commit b28a48b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cp from 'node:child_process'
import cp, { type ChildProcess } from 'node:child_process'
import logger from '@wdio/logger'

import { download as downloadDriver } from './install.js'
Expand All @@ -8,7 +8,7 @@ import type { GeckodriverParameters } from './types.js'

const log = logger('geckodriver')

export async function start (params: GeckodriverParameters) {
export async function start (params: GeckodriverParameters): Promise<ChildProcess> {
const { cacheDir, customGeckoDriverPath, spawnOpts, ...startArgs } = params
let geckoDriverPath = (
customGeckoDriverPath ||
Expand Down
28 changes: 25 additions & 3 deletions tests/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import os from 'node:os'
import { vi, test, expect } from 'vitest'
import { vi, test, expect, afterEach } from 'vitest'
import fetch from 'node-fetch'

import { getDownloadUrl, parseParams, retryFetch } from '../src/utils.js'

vi.mock('node:os', () => ({
default: {
arch: vi.fn(),
platform: vi.fn()
platform: vi.fn(),
tmpdir: vi.fn(() => '/tmp')
}
}))

vi.mock('node-fetch', () => ({
default: vi.fn()
default: vi.fn().mockResolvedValue({
status: 400,
text: () => Promise.resolve('foobar'),
json: () => Promise.resolve({ foo: 'bar' })
})
}))

afterEach(() => {
vi.mocked(fetch).mockReset()
})

test('getDownloadUrl', () => {
vi.mocked(os.arch).mockReturnValue('arm')
vi.mocked(os.platform).mockReturnValue('linux')
Expand All @@ -36,6 +45,19 @@ test('getDownloadUrl', () => {
expect(getDownloadUrl('0.33.0')).toMatchSnapshot()
})

test('download with proxy support', async () => {
vi.resetModules()
process.env.HTTPS_PROXY = 'https://proxy.com'
const { download } = await import('../src/install.js')
await download('stable').catch(() => {})
expect(fetch).toBeCalledWith(
expect.any(String),
expect.objectContaining({
agent: expect.any(Object)
})
)
})

test('parseParams', () => {
expect(parseParams({ marionetteHost: 'foobar', allowOrigins: ['123', '321'] }))
.toMatchSnapshot()
Expand Down

0 comments on commit b28a48b

Please sign in to comment.