11const t = require ( 'tap' )
22const { spawnSync } = require ( 'child_process' )
33const { resolve, join, extname, basename, sep } = require ( 'path' )
4- const { readFileSync, chmodSync, readdirSync, rmSync } = require ( 'fs' )
4+ const { copyFileSync , readFileSync, chmodSync, readdirSync, rmSync } = require ( 'fs' )
55const Diff = require ( 'diff' )
66const { sync : which } = require ( 'which' )
77const { version } = require ( '../../package.json' )
88
99const ROOT = resolve ( __dirname , '../..' )
1010const BIN = join ( ROOT , 'bin' )
11- const NODE = readFileSync ( process . execPath )
1211const SHIMS = readdirSync ( BIN ) . reduce ( ( acc , shim ) => {
1312 if ( extname ( shim ) !== '.js' ) {
1413 acc [ shim ] = readFileSync ( join ( BIN , shim ) , 'utf-8' )
@@ -67,7 +66,6 @@ t.test('shim contents', t => {
6766t . test ( 'run shims' , t => {
6867 const path = t . testdir ( {
6968 ...SHIMS ,
70- 'node.exe' : NODE ,
7169 // simulate the state where one version of npm is installed
7270 // with node, but we should load the globally installed one
7371 'global-prefix' : {
@@ -94,7 +92,13 @@ t.test('run shims', t => {
9492
9593 // hacky fix to decrease flakes of this test from `NOTEMPTY: directory not empty, rmdir`
9694 // this should get better in tap@18 and we can try removing it then
97- t . teardown ( ( ) => rmSync ( path , { recursive : true , force : true } ) )
95+ copyFileSync ( process . execPath , join ( path , 'node.exe' ) )
96+ t . teardown ( async ( ) => {
97+ rmSync ( join ( path , 'node.exe' ) )
98+ await new Promise ( res => setTimeout ( res , 100 ) )
99+ // this is superstition
100+ rmSync ( join ( path , 'node.exe' ) , { force : true } )
101+ } )
98102
99103 const spawnPath = ( cmd , args , { log, stdioString = true , ...opts } = { } ) => {
100104 if ( cmd . endsWith ( 'bash.exe' ) ) {
0 commit comments