Skip to content

Commit

Permalink
update teardown step in test suite to properly handle temporary direc…
Browse files Browse the repository at this point in the history
…tory (#82)
  • Loading branch information
mojavelinux authored Jul 3, 2021
1 parent 7032d8e commit 163f98f
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ function file () {
}

teardown(() => {
const rmSync = fs.rmSync || fs.rmdirSync
files.forEach((file) => {
try {
if (fs.existsSync(file)) {
fs.unlinkSync(file)
fs.statSync(file).isDirectory() ? rmSync(file, { recursive: true, maxRetries: 10 }) : fs.unlinkSync(file)
}
} catch (e) {
console.log(e)
Expand Down Expand Up @@ -294,12 +295,6 @@ function buildTests (test, sync) {
t.error(err)
t.equal(data, 'hello world\n')
stream.end()
// put file where teardown can access it
const { dir, base } = path.parse(dest)
const tmpDir = dir + '~'
fs.renameSync(dir, tmpDir)
fs.renameSync(path.join(tmpDir, base), dir)
fs.rmdirSync(tmpDir)
})
})
})
Expand Down

0 comments on commit 163f98f

Please sign in to comment.