Skip to content

Commit 20d4da9

Browse files
committed
Fix tests
1 parent d2bba65 commit 20d4da9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

lib/current-env.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@ function cpu () {
1414
}
1515

1616
let family
17-
if (os() === 'linux') {
18-
const originalExclude = process.report.excludeNetwork
19-
process.report.excludeNetwork = true
20-
const report = process.report.getReport()
21-
process.report.excludeNetwork = originalExclude
22-
if (report.header?.glibcVersionRuntime) {
23-
family = 'glibc'
24-
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
25-
family = 'musl'
26-
}
27-
}
2817
function libc (osName) {
2918
if (osName !== 'linux') {
3019
return undefined
3120
}
21+
if (family === undefined || process.report.forceCheck) {
22+
const originalExclude = process.report.excludeNetwork
23+
process.report.excludeNetwork = true
24+
const report = process.report.getReport()
25+
process.report.excludeNetwork = originalExclude
26+
if (report.header?.glibcVersionRuntime) {
27+
family = 'glibc'
28+
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
29+
family = 'musl'
30+
} else {
31+
family = null
32+
}
33+
}
3234
return family
3335
}
36+
// Cache getReport straight away because of node bug https://github.com/nodejs/node/issues/55576
37+
libc(os())
3438

3539
function devEngines (env = {}) {
3640
const osName = env.os || os()

test/check-platform.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const t = require('tap')
22
const { checkPlatform } = require('..')
3+
const process = require('node:process')
34

45
t.test('target cpu wrong', async t =>
56
t.throws(() => checkPlatform({
@@ -106,6 +107,7 @@ t.test('libc', (t) => {
106107
let REPORT = {}
107108
const _processReport = process.report.getReport
108109
process.report.getReport = () => REPORT
110+
process.report.forceCheck = true
109111

110112
t.teardown(() => {
111113
Object.defineProperty(process, 'platform', _processPlatform)

0 commit comments

Comments
 (0)