@@ -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 ( ) , / C o u l d n o t i n s t a l l B u n / )
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