From 850c794882368d7e27d86bea49b0658cde6d864f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 15 Aug 2015 16:17:36 -0700 Subject: [PATCH] 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 Reviewed-By: Sakthipriyan Vairamani PR-URL: https://github.com/nodejs/node/pull/2393 --- test/parallel/test-fs-watchfile.js | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js index 35712741f773df..5e075fb056e8bc 100644 --- a/test/parallel/test-fs-watchfile.js +++ b/test/parallel/test-fs-watchfile.js @@ -4,7 +4,6 @@ const common = require('../common'); const fs = require('fs'); const path = require('path'); const assert = require('assert'); -const fixtures = path.join(__dirname, '..', 'fixtures'); // Basic usage tests. assert.throws(function() { @@ -19,7 +18,7 @@ assert.throws(function() { fs.watchFile(new Object(), function() {}); }, /Path must be a string/); -const enoentFile = path.join(fixtures, 'non-existent-file'); +const enoentFile = path.join(common.tmpDir, 'non-existent-file'); const expectedStatObject = new fs.Stats( 0, // dev 0, // mode @@ -37,24 +36,13 @@ const expectedStatObject = new fs.Stats( Date.UTC(1970, 0, 1, 0, 0, 0) // birthtime ); -function removeTestFile() { - try { - fs.unlinkSync(enoentFile); - } catch (ex) { - if (ex.code !== 'ENOENT') { - throw ex; - } - } -} - -// Make sure that the file does not exist, when the test starts -removeTestFile(); +common.refreshTmpDir(); // If the file initially didn't exist, and gets created at a later point of // time, the callback should be invoked again with proper values in stat object var fileExists = false; -fs.watchFile(enoentFile, common.mustCall(function(curr, prev) { +fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) { if (!fileExists) { // If the file does not exist, all the fields should be zero and the date // fields should be UNIX EPOCH time @@ -71,8 +59,7 @@ fs.watchFile(enoentFile, common.mustCall(function(curr, prev) { // As the file just got created, previous ino value should be lesser than // or equal to zero (non-existent file). assert(prev.ino <= 0); - // Stop watching the file and delete it + // Stop watching the file fs.unwatchFile(enoentFile); - removeTestFile(); } }, 2));