From 0dd5a264bd1a83f17340865108cbe0ee180759cf Mon Sep 17 00:00:00 2001 From: owl-from-hogvarts Date: Wed, 5 May 2021 16:30:05 +0300 Subject: [PATCH] test: fix "`fs.rmSync` is not a function" for old node.js versions add simplest polyfill for `fs.rmSync(path, {recursive: true})` --- test/rm.js | 20 ++++++++++++++++++++ test/test-find-python.js | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/rm.js diff --git a/test/rm.js b/test/rm.js new file mode 100644 index 0000000000..c32bfe0553 --- /dev/null +++ b/test/rm.js @@ -0,0 +1,20 @@ +const fs = require('fs') +const path = require('path') + +/** recursively delete files, symlinks (without following them) and dirs */ +module.exports = function rmRecSync (pth) { + pth = path.normalize(pth) + + rm(pth) + + function rm (pth) { + const pathStat = fs.statSync(pth) + // trick with lstat is used to avoid following symlinks (especially junctions on windows) + if (pathStat.isDirectory() && !fs.lstatSync(pth).isSymbolicLink()) { + fs.readdirSync(pth).forEach((nextPath) => rm(path.join(pth, nextPath))) + fs.rmdirSync(pth) + } else { + fs.unlinkSync(pth) + } + } +} diff --git a/test/test-find-python.js b/test/test-find-python.js index 928f708dee..d6cbdf83f3 100644 --- a/test/test-find-python.js +++ b/test/test-find-python.js @@ -309,6 +309,8 @@ test('find-python', { buffered: true }, (t) => { // using "junction" to avoid permission error fs.symlinkSync(paths.pythonDir, path.resolve(paths.testDir, testString), 'junction') + console.log('🚀 ~ file: test-find-python.js ~ line 312 ~ awaitt.test ~ path.resolve(paths.testDir, testString)', path.resolve(paths.testDir, testString)) + console.log('🚀 ~ file: test-find-python.js ~ line 312 ~ awaitt.test ~ paths.pythonDir', paths.pythonDir) const { pythonFinderInstance, result } = promisifyPythonFinder(path.resolve(paths.testDir, 'python')) @@ -322,7 +324,12 @@ test('find-python', { buffered: true }, (t) => { }) // remove fixture - fs.rmSync(paths.testDir, { recursive: true }) + if (fs.rmSync) { + fs.rmSync(paths.testDir, { recursive: true }) + } else { + // + require('./rm.js')(paths.testDir) + } t.end() })