Skip to content

Commit

Permalink
Add test for CHROME_PATH and FIREFOX_PATH environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 26, 2024
1 parent f8a8999 commit 6df9c48
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 8 deletions.
46 changes: 46 additions & 0 deletions test/browser/finders/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,52 @@ describe('Chrome finder', () => {
})
})

describe('with CHROME_PATH environment variable', () => {
const originalEnv = { ...process.env }
const regularResolution = new Error('Starting regular resolution')

beforeEach(() => {
jest.resetModules()
jest.spyOn(utils, 'getPlatform').mockRejectedValue(regularResolution)
})

afterEach(() => {
process.env = { ...originalEnv }
})

it('return the path for executable specified in CHROME_PATH', async () => {
process.env.CHROME_PATH = executableMock('empty')

expect(await chromeFinder({})).toStrictEqual({
path: process.env.CHROME_PATH,
acceptedBrowsers: [ChromeBrowser, ChromeCdpBrowser],
})
})

it('processes regular resolution if CHROME_PATH is not executable', async () => {
process.env.CHROME_PATH = executableMock('non-executable')

await expect(chromeFinder({})).rejects.toThrow(regularResolution)
})

it('processes regular resolution if CHROME_PATH is not found', async () => {
process.env.CHROME_PATH = executableMock('not-found')

await expect(chromeFinder({})).rejects.toThrow(regularResolution)
})

it('prefers the preferred path over CHROME_PATH', async () => {
process.env.CHROME_PATH = executableMock('empty')

expect(
await chromeFinder({ preferredPath: '/test/preferred/chrome' })
).toStrictEqual({
path: '/test/preferred/chrome',
acceptedBrowsers: [ChromeBrowser, ChromeCdpBrowser],
})
})
})

describe('with Linux', () => {
beforeEach(() => {
jest.spyOn(utils, 'getPlatform').mockResolvedValue('linux')
Expand Down
4 changes: 2 additions & 2 deletions test/browser/finders/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('Edge finder', () => {
const winLocalAppData = ['C:', 'Mock', 'AppData', 'Local']

const edgePath = path.join(...winProgramFiles, ...winEdgeStable)
const originalEnv = process.env
const originalEnv = { ...process.env }

beforeEach(() => {
jest.resetModules()
Expand All @@ -155,7 +155,7 @@ describe('Edge finder', () => {
})

afterEach(() => {
process.env = originalEnv
process.env = { ...originalEnv }
})

it('finds possible executable path and returns the matched path', async () => {
Expand Down
54 changes: 50 additions & 4 deletions test/browser/finders/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,52 @@ describe('Firefox finder', () => {
})
})

describe('with FIREFOX_PATH environment variable', () => {
const originalEnv = { ...process.env }
const regularResolution = new Error('Starting regular resolution')

beforeEach(() => {
jest.resetModules()
jest.spyOn(utils, 'getPlatform').mockRejectedValue(regularResolution)
})

afterEach(() => {
process.env = { ...originalEnv }
})

it('return the path for executable specified in FIREFOX_PATH', async () => {
process.env.FIREFOX_PATH = executableMock('empty')

expect(await firefoxFinder({})).toStrictEqual({
path: process.env.FIREFOX_PATH,
acceptedBrowsers: [FirefoxBrowser],
})
})

it('processes regular resolution if FIREFOX_PATH is not executable', async () => {
process.env.FIREFOX_PATH = executableMock('non-executable')

await expect(firefoxFinder({})).rejects.toThrow(regularResolution)
})

it('processes regular resolution if FIREFOX_PATH is not found', async () => {
process.env.FIREFOX_PATH = executableMock('not-found')

await expect(firefoxFinder({})).rejects.toThrow(regularResolution)
})

it('prefers the preferred path over FIREFOX_PATH', async () => {
process.env.FIREFOX_PATH = executableMock('empty')

expect(
await firefoxFinder({ preferredPath: '/test/preferred/firefox' })
).toStrictEqual({
path: '/test/preferred/firefox',
acceptedBrowsers: [FirefoxBrowser],
})
})
})

describe('with Linux', () => {
beforeEach(() => {
jest.spyOn(utils, 'getPlatform').mockResolvedValue('linux')
Expand Down Expand Up @@ -147,7 +193,7 @@ describe('Firefox finder', () => {
'Mozilla Firefox',
'firefox.exe'
)
const originalEnv = process.env
const originalEnv = { ...process.env }

beforeEach(() => {
jest.resetModules()
Expand All @@ -166,7 +212,7 @@ describe('Firefox finder', () => {
})

afterEach(() => {
process.env = originalEnv
process.env = { ...originalEnv }
})

it('finds possible executable path and returns the matched path', async () => {
Expand Down Expand Up @@ -249,7 +295,7 @@ describe('Firefox finder', () => {
})

describe('with WSL1', () => {
const originalEnv = process.env
const originalEnv = { ...process.env }

beforeEach(() => {
jest.resetModules()
Expand All @@ -265,7 +311,7 @@ describe('Firefox finder', () => {
})

afterEach(() => {
process.env = originalEnv
process.env = { ...originalEnv }
})

it('finds possible executable path and returns the matched path', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/utils/edge-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('#findEdgeInstallation', () => {
})

it('finds out the first accessible Edge from 3 locations', async () => {
const currentEnv = process.env
const currentEnv = { ...process.env }

const programFiles = path.join('C:', 'Mock', 'Program Files')
const programFilesX86 = path.join('C:', 'Mock', 'Program Files (x86)')
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('#findEdgeInstallation', () => {
delete process.env['PROGRAMFILES(X86)']
delete process.env.LOCALAPPDATA

process.env = currentEnv
process.env = { ...currentEnv }
}
})
})
Expand Down

0 comments on commit 6df9c48

Please sign in to comment.