Skip to content

Commit

Permalink
fixup! test: clean tmpdir on process exit
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocgreis committed Jul 30, 2019
1 parent 5ccb15b commit bd99911
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion test/common/tmpdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const { debuglog } = require('util');
const { isMainThread } = require('worker_threads');

const debug = debuglog('test/tmpdir');

Expand Down Expand Up @@ -110,7 +111,8 @@ function refresh(opts = {}) {
process.on('exit', () => {
try {
// Change dit to avoid possible EBUSY
process.chdir(testRoot);
if (isMainThread)
process.chdir(testRoot);
rimrafSync(tmpPath, { spawn: false });
} catch (e) {
console.error('Can\'t clean tmpdir:', tmpPath);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-truncate-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fs.truncate(fd, 5, common.mustCall((err) => {
assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello');
}));

process.on('beforeExit', () => {
process.once('beforeExit', () => {
fs.closeSync(fd);
fs.unlinkSync(filename);
console.log('ok');
Expand Down

0 comments on commit bd99911

Please sign in to comment.