diff options
author | Rich Trott <rtrott@gmail.com> | 2019-08-01 14:29:49 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-03 16:11:18 -0700 |
commit | e6c205265a8812b426d0a3c8f3d28c7bf0db224d (patch) | |
tree | ebd9e69e652da57c2f92a5b2dbd62268aea4d281 /test | |
parent | 1592d0ab737f6537bd57cfed31277715afdf609c (diff) | |
download | node-new-e6c205265a8812b426d0a3c8f3d28c7bf0db224d.tar.gz |
test: refactor test-fs-stat.js
General code cleanup.
PR-URL: https://github.com/nodejs/node/pull/28929
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-fs-stat.js | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 40a0640724..d52eb6d8fd 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -28,17 +28,14 @@ const fs = require('fs'); fs.stat('.', common.mustCall(function(err, stats) { assert.ifError(err); assert.ok(stats.mtime instanceof Date); + assert.ok(stats.hasOwnProperty('blksize')); + assert.ok(stats.hasOwnProperty('blocks')); // Confirm that we are not running in the context of the internal binding // layer. // Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1 assert.strictEqual(this, undefined); })); -fs.stat('.', common.mustCall(function(err, stats) { - assert.ok(stats.hasOwnProperty('blksize')); - assert.ok(stats.hasOwnProperty('blocks')); -})); - fs.lstat('.', common.mustCall(function(err, stats) { assert.ifError(err); assert.ok(stats.mtime instanceof Date); @@ -71,16 +68,9 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { // fstatSync fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { - let stats; - try { - stats = fs.fstatSync(fd); - } catch (err) { - assert.fail(err); - } - if (stats) { - assert.ok(stats.mtime instanceof Date); - } - fs.close(fd, assert.ifError); + const stats = fs.fstatSync(fd); + assert.ok(stats.mtime instanceof Date); + fs.close(fd, common.mustCall(assert.ifError)); })); fs.stat(__filename, common.mustCall(function(err, s) { @@ -92,38 +82,30 @@ fs.stat(__filename, common.mustCall(function(err, s) { assert.strictEqual(s.isCharacterDevice(), false); assert.strictEqual(s.isFIFO(), false); assert.strictEqual(s.isSymbolicLink(), false); - const keys = [ + + const jsonString = JSON.stringify(s); + const parsed = JSON.parse(jsonString); + [ 'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size', 'blocks', 'atime', 'mtime', 'ctime', 'birthtime', - 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' - ]; - const numberFields = [ - 'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size', - 'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' - ]; - const dateFields = ['atime', 'mtime', 'ctime', 'birthtime']; - keys.forEach(function(k) { + 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs', + ].forEach(function(k) { assert.ok(k in s, `${k} should be in Stats`); assert.notStrictEqual(s[k], undefined, `${k} should not be undefined`); assert.notStrictEqual(s[k], null, `${k} should not be null`); - }); - numberFields.forEach((k) => { - assert.strictEqual(typeof s[k], 'number', `${k} should be a number`); - }); - dateFields.forEach((k) => { - assert.ok(s[k] instanceof Date, `${k} should be a Date`); - }); - const jsonString = JSON.stringify(s); - const parsed = JSON.parse(jsonString); - keys.forEach(function(k) { assert.notStrictEqual(parsed[k], undefined, `${k} should not be undefined`); assert.notStrictEqual(parsed[k], null, `${k} should not be null`); }); - numberFields.forEach((k) => { + [ + 'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size', + 'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs', + ].forEach((k) => { + assert.strictEqual(typeof s[k], 'number', `${k} should be a number`); assert.strictEqual(typeof parsed[k], 'number', `${k} should be a number`); }); - dateFields.forEach((k) => { + ['atime', 'mtime', 'ctime', 'birthtime'].forEach((k) => { + assert.ok(s[k] instanceof Date, `${k} should be a Date`); assert.strictEqual(typeof parsed[k], 'string', `${k} should be a string`); }); })); |