Skip to content

Commit b7b6f5d

Browse files
miraoJaromir Obrclaude
authored
fix: report Bun runtime in environment info (#5700)
`codecept info` and the machine-info block printed by `run --verbose`, `run-workers --verbose` and `check` hardcoded `envinfo.helpers.getNodeInfo()`, which probes PATH rather than the running process. Under Bun that is wrong in two ways: - `nodeInfo: Not Found` on a working install, either because the image has no Node at all, or because `bunx --bun` prepends a shim dir whose `node` re-execs Bun and rejects `--version`. - A real but irrelevant Node version when some Node happens to be on PATH, which is worse because it looks correct. Pick the helper by the runtime that is actually executing, via `process.versions.bun`, and report Bun through `envinfo.helpers.getbunInfo()` so both runtimes are resolved the same way. Node output is unchanged. The returned array keeps the shape of `getNodeInfo()`, so the existing `Array.isArray` printer shows the version at index 1 with no printer change. Closes #5698 Co-authored-by: Jaromir Obr <jobr@spork.tech> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent d85b22e commit b7b6f5d

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

lib/command/info.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ async function getOsBrowsers() {
4444
].join(', ')
4545
}
4646

47+
// Which runtime executes CodeceptJS can only be told from `process.versions`; envinfo probes
48+
// PATH, where under `bunx --bun` the first `node` is a Bun shim with no --version, so
49+
// getNodeInfo() returns "Not Found" on a working install.
50+
async function getRuntimeInfo() {
51+
if (process.versions.bun) return { bunInfo: await envinfo.helpers.getbunInfo() }
52+
return { nodeInfo: await envinfo.helpers.getNodeInfo() }
53+
}
54+
4755
export default async function (path) {
4856
const testsPath = getTestRoot(path)
4957
const config = await getConfig(testsPath)
@@ -53,7 +61,7 @@ export default async function (path) {
5361
output.print('\n Environment information: \n')
5462
const info = {}
5563
info.codeceptVersion = Codecept.version()
56-
info.nodeInfo = await envinfo.helpers.getNodeInfo()
64+
Object.assign(info, await getRuntimeInfo())
5765
info.osInfo = await envinfo.helpers.getOSInfo()
5866
info.cpuInfo = await envinfo.helpers.getCPUInfo()
5967
info.osBrowsers = await getOsBrowsers()
@@ -77,11 +85,11 @@ export default async function (path) {
7785
output.print('***************************************')
7886
}
7987

80-
export { parsePlaywrightBrowsers }
88+
export { parsePlaywrightBrowsers, getRuntimeInfo }
8189

8290
export const getMachineInfo = async () => {
8391
const info = {
84-
nodeInfo: await envinfo.helpers.getNodeInfo(),
92+
...(await getRuntimeInfo()),
8593
osInfo: await envinfo.helpers.getOSInfo(),
8694
cpuInfo: await envinfo.helpers.getCPUInfo(),
8795
chromeInfo: await envinfo.helpers.getChromeInfo(),

test/unit/command/info_test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
11
import { expect } from 'chai'
2-
import { parsePlaywrightBrowsers } from '../../../lib/command/info.js'
2+
import { parsePlaywrightBrowsers, getRuntimeInfo } from '../../../lib/command/info.js'
33

44
describe('info command', () => {
5+
describe('getRuntimeInfo', () => {
6+
let originalBunVersion
7+
8+
beforeEach(() => {
9+
originalBunVersion = process.versions.bun
10+
})
11+
12+
afterEach(() => {
13+
if (originalBunVersion === undefined) {
14+
delete process.versions.bun
15+
} else {
16+
process.versions.bun = originalBunVersion
17+
}
18+
})
19+
20+
it('should report bunInfo when running under Bun', async () => {
21+
process.versions.bun = '1.4.2'
22+
const info = await getRuntimeInfo()
23+
expect(info).to.have.property('bunInfo')
24+
expect(info).to.not.have.property('nodeInfo')
25+
expect(info.bunInfo[0]).to.equal('bun')
26+
})
27+
28+
it('should report nodeInfo when not running under Bun', async () => {
29+
delete process.versions.bun
30+
const info = await getRuntimeInfo()
31+
expect(info).to.have.property('nodeInfo')
32+
expect(info).to.not.have.property('bunInfo')
33+
expect(info.nodeInfo[0]).to.equal('Node')
34+
})
35+
36+
it('should return an array so the printer shows the version at index 1', async () => {
37+
delete process.versions.bun
38+
const { nodeInfo } = await getRuntimeInfo()
39+
expect(nodeInfo).to.be.an('array')
40+
expect(nodeInfo.length).to.be.at.least(2)
41+
expect(nodeInfo[1]).to.be.a('string')
42+
})
43+
})
44+
545
describe('parsePlaywrightBrowsers', () => {
646
describe('old format (Playwright < 1.58)', () => {
747
const oldFormatOutput = `browser: chromium version 140.0.7339.186

0 commit comments

Comments
 (0)