Skip to content

Commit 6ec6ff0

Browse files
committed
chore: manually create/delete node.exe in shim test
1 parent 0d9821c commit 6ec6ff0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

test/bin/windows-shims.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
const t = require('tap')
22
const { spawnSync } = require('child_process')
33
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')
55
const Diff = require('diff')
66
const { sync: which } = require('which')
77
const { version } = require('../../package.json')
88

99
const ROOT = resolve(__dirname, '../..')
1010
const BIN = join(ROOT, 'bin')
11-
const NODE = readFileSync(process.execPath)
1211
const 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 => {
6766
t.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

Comments
 (0)