1
1
const t = require ( 'tap' )
2
2
const { spawnSync } = require ( 'child_process' )
3
3
const { resolve, join, extname, basename, sep } = require ( 'path' )
4
- const { readFileSync, chmodSync, readdirSync, rmSync } = require ( 'fs' )
4
+ const { copyFileSync , readFileSync, chmodSync, readdirSync, rmSync } = require ( 'fs' )
5
5
const Diff = require ( 'diff' )
6
6
const { sync : which } = require ( 'which' )
7
7
const { version } = require ( '../../package.json' )
8
8
9
9
const ROOT = resolve ( __dirname , '../..' )
10
10
const BIN = join ( ROOT , 'bin' )
11
- const NODE = readFileSync ( process . execPath )
12
11
const SHIMS = readdirSync ( BIN ) . reduce ( ( acc , shim ) => {
13
12
if ( extname ( shim ) !== '.js' ) {
14
13
acc [ shim ] = readFileSync ( join ( BIN , shim ) , 'utf-8' )
@@ -67,7 +66,6 @@ t.test('shim contents', t => {
67
66
t . test ( 'run shims' , t => {
68
67
const path = t . testdir ( {
69
68
...SHIMS ,
70
- 'node.exe' : NODE ,
71
69
// simulate the state where one version of npm is installed
72
70
// with node, but we should load the globally installed one
73
71
'global-prefix' : {
@@ -94,7 +92,13 @@ t.test('run shims', t => {
94
92
95
93
// hacky fix to decrease flakes of this test from `NOTEMPTY: directory not empty, rmdir`
96
94
// 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
+ } )
98
102
99
103
const spawnPath = ( cmd , args , { log, stdioString = true , ...opts } = { } ) => {
100
104
if ( cmd . endsWith ( 'bash.exe' ) ) {
0 commit comments