Skip to content

Commit 850c794

Browse files
TrottFishrock123
authored andcommitted
test: refactor test-fs-watchfile.js
The test no longer waits about 5 seconds between callback invocations. It now writes to the tmp directory rather than the fixtures directory. Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> PR-URL: #2393
1 parent 34f2cfa commit 850c794

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

test/parallel/test-fs-watchfile.js

+4-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const common = require('../common');
44
const fs = require('fs');
55
const path = require('path');
66
const assert = require('assert');
7-
const fixtures = path.join(__dirname, '..', 'fixtures');
87

98
// Basic usage tests.
109
assert.throws(function() {
@@ -19,7 +18,7 @@ assert.throws(function() {
1918
fs.watchFile(new Object(), function() {});
2019
}, /Path must be a string/);
2120

22-
const enoentFile = path.join(fixtures, 'non-existent-file');
21+
const enoentFile = path.join(common.tmpDir, 'non-existent-file');
2322
const expectedStatObject = new fs.Stats(
2423
0, // dev
2524
0, // mode
@@ -37,24 +36,13 @@ const expectedStatObject = new fs.Stats(
3736
Date.UTC(1970, 0, 1, 0, 0, 0) // birthtime
3837
);
3938

40-
function removeTestFile() {
41-
try {
42-
fs.unlinkSync(enoentFile);
43-
} catch (ex) {
44-
if (ex.code !== 'ENOENT') {
45-
throw ex;
46-
}
47-
}
48-
}
49-
50-
// Make sure that the file does not exist, when the test starts
51-
removeTestFile();
39+
common.refreshTmpDir();
5240

5341
// If the file initially didn't exist, and gets created at a later point of
5442
// time, the callback should be invoked again with proper values in stat object
5543
var fileExists = false;
5644

57-
fs.watchFile(enoentFile, common.mustCall(function(curr, prev) {
45+
fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) {
5846
if (!fileExists) {
5947
// If the file does not exist, all the fields should be zero and the date
6048
// fields should be UNIX EPOCH time
@@ -71,8 +59,7 @@ fs.watchFile(enoentFile, common.mustCall(function(curr, prev) {
7159
// As the file just got created, previous ino value should be lesser than
7260
// or equal to zero (non-existent file).
7361
assert(prev.ino <= 0);
74-
// Stop watching the file and delete it
62+
// Stop watching the file
7563
fs.unwatchFile(enoentFile);
76-
removeTestFile();
7764
}
7865
}, 2));

0 commit comments

Comments
 (0)