Skip to content

Commit 12746af

Browse files
jun-okaMylesBorins
authored andcommitted
test: refactor test-fs-utimes
* favor `===` over `==` * `var` -> `const`/`let` * use `common.mustCall()` PR-URL: #9290 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e4f7f5c commit 12746af

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

‎test/parallel/test-fs-utimes.js‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ var assert = require('assert');
44
varutil=require('util');
55
varfs=require('fs');
66

7-
vartests_ok=0;
8-
vartests_run=0;
7+
lettests_ok=0;
8+
lettests_run=0;
99

1010
functionstat_resource(resource){
11-
if(typeofresource=='string'){
11+
if(typeofresource==='string'){
1212
returnfs.statSync(resource);
1313
}else{
1414
// ensure mtime has been written to disk
@@ -19,8 +19,8 @@ function stat_resource(resource) {
1919

2020
functioncheck_mtime(resource,mtime){
2121
mtime=fs._toUnixTimestamp(mtime);
22-
varstats=stat_resource(resource);
23-
varreal_mtime=fs._toUnixTimestamp(stats.mtime);
22+
conststats=stat_resource(resource);
23+
constreal_mtime=fs._toUnixTimestamp(stats.mtime);
2424
// check up to single-second precision
2525
// sub-second precision is OS and fs dependant
2626
returnmtime-real_mtime<2;
@@ -46,9 +46,9 @@ function expect_ok(syscall, resource, err, atime, mtime) {
4646
// the tests assume that __filename belongs to the user running the tests
4747
// this should be a fairly safe assumption; testing against a temp file
4848
// would be even better though (node doesn't have such functionality yet)
49-
functionrunTest(atime,mtime,callback){
49+
functiontestIt(atime,mtime,callback){
5050

51-
varfd;
51+
letfd;
5252
//
5353
// test synchronized code paths, these functions throw on failure
5454
//
@@ -67,8 +67,7 @@ function runTest(atime, mtime, callback) {
6767
expect_errno('futimesSync',fd,ex,'ENOSYS');
6868
}
6969

70-
varerr;
71-
err=undefined;
70+
leterr=undefined;
7271
try{
7372
fs.utimesSync('foobarbaz',atime,mtime);
7473
}catch(ex){
@@ -90,10 +89,10 @@ function runTest(atime, mtime, callback) {
9089
//
9190
// test async code paths
9291
//
93-
fs.utimes(__filename,atime,mtime,function(err){
92+
fs.utimes(__filename,atime,mtime,common.mustCall(function(err){
9493
expect_ok('utimes',__filename,err,atime,mtime);
9594

96-
fs.utimes('foobarbaz',atime,mtime,function(err){
95+
fs.utimes('foobarbaz',atime,mtime,common.mustCall(function(err){
9796
expect_errno('utimes','foobarbaz',err,'ENOENT');
9897

9998
// don't close this fd
@@ -103,34 +102,36 @@ function runTest(atime, mtime, callback) {
103102
fd=fs.openSync(__filename,'r');
104103
}
105104

106-
fs.futimes(fd,atime,mtime,function(err){
105+
fs.futimes(fd,atime,mtime,common.mustCall(function(err){
107106
expect_ok('futimes',fd,err,atime,mtime);
108107

109-
fs.futimes(-1,atime,mtime,function(err){
108+
fs.futimes(-1,atime,mtime,common.mustCall(function(err){
110109
expect_errno('futimes',-1,err,'EBADF');
111110
syncTests();
112111
callback();
113-
});
112+
}));
114113
tests_run++;
115-
});
114+
}));
116115
tests_run++;
117-
});
116+
}));
118117
tests_run++;
119-
});
118+
}));
120119
tests_run++;
121120
}
122121

123-
varstats=fs.statSync(__filename);
122+
conststats=fs.statSync(__filename);
124123

125124
// run tests
125+
construnTest=common.mustCall(testIt,6);
126+
126127
runTest(newDate('1982-09-10 13:37'),newDate('1982-09-10 13:37'),function(){
127128
runTest(newDate(),newDate(),function(){
128129
runTest(123456.789,123456.789,function(){
129130
runTest(stats.mtime,stats.mtime,function(){
130131
runTest(NaN,Infinity,function(){
131-
runTest('123456',-1,function(){
132+
runTest('123456',-1,common.mustCall(function(){
132133
// done
133-
});
134+
}));
134135
});
135136
});
136137
});
@@ -140,5 +141,5 @@ runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {
140141

141142
process.on('exit',function(){
142143
console.log('Tests run / ok:',tests_run,'/',tests_ok);
143-
assert.equal(tests_ok,tests_run);
144+
assert.strictEqual(tests_ok,tests_run);
144145
});

0 commit comments

Comments
 (0)