Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/command/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ function parsePlaywrightBrowsers(output) {
return versions.join(', ')
}

// Bun has its own package runner and a Bun-only install has no `npx` on PATH at all, so the
// runner has to follow the runtime that is actually executing rather than what PATH happens to hold.
function getPackageRunner() {
if (process.versions.bun) return 'bunx'
return 'npx'
}

async function getPlaywrightBrowsers() {
try {
const info = execSync('npx playwright install --dry-run').toString().trim()
const info = execSync(`${getPackageRunner()} playwright install --dry-run`).toString().trim()
return parsePlaywrightBrowsers(info)
} catch (err) {
return 'Playwright not installed'
Expand Down Expand Up @@ -85,7 +92,7 @@ export default async function (path) {
output.print('***************************************')
}

export { parsePlaywrightBrowsers, getRuntimeInfo }
export { parsePlaywrightBrowsers, getRuntimeInfo, getPackageRunner }

export const getMachineInfo = async () => {
const info = {
Expand Down
28 changes: 27 additions & 1 deletion test/unit/command/info_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai'
import { parsePlaywrightBrowsers, getRuntimeInfo } from '../../../lib/command/info.js'
import { parsePlaywrightBrowsers, getRuntimeInfo, getPackageRunner } from '../../../lib/command/info.js'

describe('info command', () => {
describe('getRuntimeInfo', () => {
Expand Down Expand Up @@ -42,6 +42,32 @@ describe('info command', () => {
})
})

describe('getPackageRunner', () => {
let originalBunVersion

beforeEach(() => {
originalBunVersion = process.versions.bun
})

afterEach(() => {
if (originalBunVersion === undefined) {
delete process.versions.bun
} else {
process.versions.bun = originalBunVersion
}
})

it('should use bunx when running under Bun', () => {
process.versions.bun = '1.4.2'
expect(getPackageRunner()).to.equal('bunx')
})

it('should use npx when not running under Bun', () => {
delete process.versions.bun
expect(getPackageRunner()).to.equal('npx')
})
})

describe('parsePlaywrightBrowsers', () => {
describe('old format (Playwright < 1.58)', () => {
const oldFormatOutput = `browser: chromium version 140.0.7339.186
Expand Down
Loading