diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js index b72b294a0bd1b1..9bcf6039cd60bc 100644 --- a/test/parallel/test-fs-utimes.js +++ b/test/parallel/test-fs-utimes.js @@ -25,6 +25,8 @@ const assert = require('assert'); const util = require('util'); const fs = require('fs'); +common.refreshTmpDir(); + let tests_ok = 0; let tests_run = 0; @@ -64,9 +66,6 @@ function expect_ok(syscall, resource, err, atime, mtime) { } } -// the tests assume that __filename belongs to the user running the tests -// this should be a fairly safe assumption; testing against a temp file -// would be even better though (node doesn't have such functionality yet) function testIt(atime, mtime, callback) { let fd; @@ -74,8 +73,8 @@ function testIt(atime, mtime, callback) { // test synchronized code paths, these functions throw on failure // function syncTests() { - fs.utimesSync(__filename, atime, mtime); - expect_ok('utimesSync', __filename, undefined, atime, mtime); + fs.utimesSync(common.tmpDir, atime, mtime); + expect_ok('utimesSync', common.tmpDir, undefined, atime, mtime); tests_run++; // some systems don't have futimes @@ -110,17 +109,17 @@ function testIt(atime, mtime, callback) { // // test async code paths // - fs.utimes(__filename, atime, mtime, common.mustCall(function(err) { - expect_ok('utimes', __filename, err, atime, mtime); + fs.utimes(common.tmpDir, atime, mtime, common.mustCall(function(err) { + expect_ok('utimes', common.tmpDir, err, atime, mtime); fs.utimes('foobarbaz', atime, mtime, common.mustCall(function(err) { expect_errno('utimes', 'foobarbaz', err, 'ENOENT'); // don't close this fd if (common.isWindows) { - fd = fs.openSync(__filename, 'r+'); + fd = fs.openSync(common.tmpDir, 'r+'); } else { - fd = fs.openSync(__filename, 'r'); + fd = fs.openSync(common.tmpDir, 'r'); } fs.futimes(fd, atime, mtime, common.mustCall(function(err) { @@ -140,7 +139,7 @@ function testIt(atime, mtime, callback) { tests_run++; } -const stats = fs.statSync(__filename); +const stats = fs.statSync(common.tmpDir); // run tests const runTest = common.mustCall(testIt, 6); @@ -169,7 +168,6 @@ process.on('exit', function() { // Ref: https://github.com/nodejs/node/issues/13255 -common.refreshTmpDir(); const path = `${common.tmpDir}/test-utimes-precision`; fs.writeFileSync(path, '');