Skip to content

Commit d20637f

Browse files
committed
test(install): isolate Bun bootstrap PATH fixtures
GitHub's Node setup installs Bun next to Node, so the restricted PATH still found the pinned binary and bypassed both bootstrap branches. Put a mismatched Bun command first while retaining the real PATH needed by npm lifecycle scripts.
1 parent ed3a253 commit d20637f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

scripts/test/no-yarn-dev-references.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ describe('no yarn dev references', function () {
139139
})
140140
})
141141

142-
it('bootstraps pinned Bun inside the checkout when it is absent from PATH', async () => {
142+
it('bootstraps pinned Bun when PATH does not contain the pinned version', async () => {
143143
const { bun: bunVersion } = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'))
144144
.devDependencies
145145
const bootstrapDirectory = path.join(repoRoot, 'node_modules', '.cache', `bun-${bunVersion}`)
146146
const backupDirectory = `${bootstrapDirectory}.backup-${process.pid}`
147+
const commandDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'dd-fake-bun-'))
148+
const bunCommand = process.platform === 'win32' ? 'bun.exe' : 'bun'
147149
const originalNpmExecPath = process.env.npm_execpath
148150
const originalPath = process.env.PATH
149151
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'
@@ -154,7 +156,8 @@ describe('no yarn dev references', function () {
154156
}
155157
const globalNpmRoot = execFileSync(npm, ['root', '--global'], { encoding: 'utf8' }).trim()
156158
process.env.npm_execpath = path.join(globalNpmRoot, 'npm', 'bin', 'npm-cli.js')
157-
process.env.PATH = [path.dirname(process.execPath), '/usr/bin', '/bin'].join(path.delimiter)
159+
fs.linkSync(process.execPath, path.join(commandDirectory, bunCommand))
160+
process.env.PATH = [commandDirectory, originalPath].filter(Boolean).join(path.delimiter)
158161
const bunBinary = getBunBinary()
159162

160163
assert.strictEqual(await Promise.resolve(bunBinary), path.join(
@@ -178,6 +181,7 @@ describe('no yarn dev references', function () {
178181
process.env.npm_execpath = originalNpmExecPath
179182
}
180183
process.env.PATH = originalPath
184+
fs.rmSync(commandDirectory, { recursive: true, force: true })
181185
fs.rmSync(bootstrapDirectory, { recursive: true, force: true })
182186
if (fs.existsSync(backupDirectory)) {
183187
fs.renameSync(backupDirectory, bootstrapDirectory)
@@ -190,6 +194,8 @@ describe('no yarn dev references', function () {
190194
.devDependencies
191195
const bootstrapDirectory = path.join(repoRoot, 'node_modules', '.cache', `bun-${bunVersion}`)
192196
const backupDirectory = `${bootstrapDirectory}.backup-${process.pid}`
197+
const commandDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'dd-fake-bun-'))
198+
const bunCommand = process.platform === 'win32' ? 'bun.exe' : 'bun'
193199
const fakeNpm = path.join(os.tmpdir(), `dd-fake-npm-${process.pid}.js`)
194200
const originalNpmExecPath = process.env.npm_execpath
195201
const originalPath = process.env.PATH
@@ -199,8 +205,9 @@ describe('no yarn dev references', function () {
199205
fs.renameSync(bootstrapDirectory, backupDirectory)
200206
}
201207
fs.writeFileSync(fakeNpm, '')
208+
fs.linkSync(process.execPath, path.join(commandDirectory, bunCommand))
202209
process.env.npm_execpath = fakeNpm
203-
process.env.PATH = [path.dirname(process.execPath), '/usr/bin', '/bin'].join(path.delimiter)
210+
process.env.PATH = [commandDirectory, originalPath].filter(Boolean).join(path.delimiter)
204211

205212
assert.throws(() => getBunBinary(), /Could not install Bun/)
206213
} finally {
@@ -211,6 +218,7 @@ describe('no yarn dev references', function () {
211218
}
212219
process.env.PATH = originalPath
213220
fs.rmSync(fakeNpm, { force: true })
221+
fs.rmSync(commandDirectory, { recursive: true, force: true })
214222
fs.rmSync(bootstrapDirectory, { recursive: true, force: true })
215223
if (fs.existsSync(backupDirectory)) {
216224
fs.renameSync(backupDirectory, bootstrapDirectory)

0 commit comments

Comments
 (0)