Browse Source

test: refactor the code in test-fs-watch.js

* used let and const instead of var
* used assert.strictEqual instead assert.equal

PR-URL: https://github.com/nodejs/node/pull/10357
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
sivaprasanna 8 years ago
committed by James M Snell
parent
commit
5b82800241
  1. 62
      test/sequential/test-fs-watch.js

62
test/sequential/test-fs-watch.js

@ -1,25 +1,25 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
var assert = require('assert'); const assert = require('assert');
var path = require('path'); const path = require('path');
var fs = require('fs'); const fs = require('fs');
var expectFilePath = common.isWindows || const expectFilePath = common.isWindows ||
common.isLinux || common.isLinux ||
common.isOSX; common.isOSX;
var watchSeenOne = 0; let watchSeenOne = 0;
var watchSeenTwo = 0; let watchSeenTwo = 0;
var watchSeenThree = 0; let watchSeenThree = 0;
var testDir = common.tmpDir; const testDir = common.tmpDir;
var filenameOne = 'watch.txt'; const filenameOne = 'watch.txt';
var filepathOne = path.join(testDir, filenameOne); const filepathOne = path.join(testDir, filenameOne);
var filenameTwo = 'hasOwnProperty'; const filenameTwo = 'hasOwnProperty';
var filepathTwo = filenameTwo; const filepathTwo = filenameTwo;
var filepathTwoAbs = path.join(testDir, filenameTwo); const filepathTwoAbs = path.join(testDir, filenameTwo);
process.on('exit', function() { process.on('exit', function() {
assert.ok(watchSeenOne > 0); assert.ok(watchSeenOne > 0);
@ -33,12 +33,12 @@ fs.writeFileSync(filepathOne, 'hello');
assert.doesNotThrow( assert.doesNotThrow(
function() { function() {
var watcher = fs.watch(filepathOne); const watcher = fs.watch(filepathOne);
watcher.on('change', function(event, filename) { watcher.on('change', function(event, filename) {
assert.equal('change', event); assert.strictEqual('change', event);
if (expectFilePath) { if (expectFilePath) {
assert.equal('watch.txt', filename); assert.strictEqual('watch.txt', filename);
} }
watcher.close(); watcher.close();
++watchSeenOne; ++watchSeenOne;
@ -57,11 +57,11 @@ fs.writeFileSync(filepathTwoAbs, 'howdy');
assert.doesNotThrow( assert.doesNotThrow(
function() { function() {
var watcher = fs.watch(filepathTwo, function(event, filename) { const watcher = fs.watch(filepathTwo, function(event, filename) {
assert.equal('change', event); assert.strictEqual('change', event);
if (expectFilePath) { if (expectFilePath) {
assert.equal('hasOwnProperty', filename); assert.strictEqual('hasOwnProperty', filename);
} }
watcher.close(); watcher.close();
++watchSeenTwo; ++watchSeenTwo;
@ -79,13 +79,13 @@ const filepathThree = path.join(testsubdir, filenameThree);
assert.doesNotThrow( assert.doesNotThrow(
function() { function() {
var watcher = fs.watch(testsubdir, function(event, filename) { const watcher = fs.watch(testsubdir, function(event, filename) {
var renameEv = common.isSunOS ? 'change' : 'rename'; const renameEv = common.isSunOS ? 'change' : 'rename';
assert.equal(renameEv, event); assert.strictEqual(renameEv, event);
if (expectFilePath) { if (expectFilePath) {
assert.equal('newfile.txt', filename); assert.strictEqual('newfile.txt', filename);
} else { } else {
assert.equal(null, filename); assert.strictEqual(null, filename);
} }
watcher.close(); watcher.close();
++watchSeenThree; ++watchSeenThree;
@ -94,7 +94,7 @@ assert.doesNotThrow(
); );
setImmediate(function() { setImmediate(function() {
var fd = fs.openSync(filepathThree, 'w'); const fd = fs.openSync(filepathThree, 'w');
fs.closeSync(fd); fs.closeSync(fd);
}); });
@ -106,9 +106,9 @@ fs.watch(__filename, {persistent: false}, function() {
// whitebox test to ensure that wrapped FSEvent is safe // whitebox test to ensure that wrapped FSEvent is safe
// https://github.com/joyent/node/issues/6690 // https://github.com/joyent/node/issues/6690
var oldhandle; let oldhandle;
assert.throws(function() { assert.throws(function() {
var w = fs.watch(__filename, function(event, filename) { }); const w = fs.watch(__filename, function(event, filename) { });
oldhandle = w._handle; oldhandle = w._handle;
w._handle = { close: w._handle.close }; w._handle = { close: w._handle.close };
w.close(); w.close();
@ -116,7 +116,7 @@ assert.throws(function() {
oldhandle.close(); // clean up oldhandle.close(); // clean up
assert.throws(function() { assert.throws(function() {
var w = fs.watchFile(__filename, {persistent: false}, function() {}); const w = fs.watchFile(__filename, {persistent: false}, function() {});
oldhandle = w._handle; oldhandle = w._handle;
w._handle = { stop: w._handle.stop }; w._handle = { stop: w._handle.stop };
w.stop(); w.stop();

Loading…
Cancel
Save