Skip to content

Commit

Permalink
fix(chrome-finder): win32 may provide progrem files env with differen…
Browse files Browse the repository at this point in the history
…t name
  • Loading branch information
liuyi.levi committed Aug 31, 2022
1 parent 77b065e commit 808c2ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/chrome-finder/src/__tests__/find-chrome.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { mkdirSync } from 'fs'
import { join } from 'path'

import test from 'ava'
import puppeteer from 'puppeteer-core'

import { findChrome } from '..'

test.only('should find local suitable chromium', async (t) => {
test('should find local suitable chromium', async (t) => {
const chromeInfo = await findChrome()

t.truthy(chromeInfo.browser)
Expand All @@ -18,6 +19,7 @@ test('should throw if chrome version not match', async (t) => {

test('should download if config specified', async (t) => {
const downloadPath = join(__dirname, '../', '../', 'dist', 'chrome')
mkdirSync(downloadPath, { recursive: true })
const chromeInfo = await findChrome({
min: 66,
max: 66,
Expand Down
13 changes: 9 additions & 4 deletions packages/chrome-finder/src/win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import { execSync } from 'child_process'
import { existsSync } from 'fs'
import { sep, join } from 'path'

import { canAccess } from './utils'
Expand All @@ -24,15 +25,19 @@ export function findChromeBinaryOnWin32(canary = false) {
? `${sep}Google${sep}Chrome SxS${sep}Application${sep}chrome.exe`
: `${sep}Google${sep}Chrome${sep}Application${sep}chrome.exe`

const prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']].filter(
Boolean,
)
const prefixes = [
process.env.LOCALAPPDATA,
process.env.PROGRAMFILES,
process.env['PROGRAMFILES(X86)'],
process.env.ProgramFiles,
process.env['ProgramFiles(x86)'],
].filter(Boolean)

let result: string | undefined

prefixes.forEach((prefix) => {
const chromePath = join(prefix!, suffix)
if (canAccess(chromePath)) {
if (existsSync(chromePath) && canAccess(chromePath)) {
result = chromePath
}
})
Expand Down

0 comments on commit 808c2ef

Please sign in to comment.