Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0f8f552

Browse filesBrowse files
TrottBridgeAR
authored andcommitted
test: refactor test-fs-stat.js
General code cleanup. PR-URL: #28929 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 4b91e4d commit 0f8f552
Copy full SHA for 0f8f552

File tree

Expand file treeCollapse file tree

1 file changed

+18
-36
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-36
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-stat.js
+18-36Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@ const fs = require('fs');
2828
fs.stat('.', common.mustCall(function(err, stats) {
2929
assert.ifError(err);
3030
assert.ok(stats.mtime instanceof Date);
31+
assert.ok(stats.hasOwnProperty('blksize'));
32+
assert.ok(stats.hasOwnProperty('blocks'));
3133
// Confirm that we are not running in the context of the internal binding
3234
// layer.
3335
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
3436
assert.strictEqual(this, undefined);
3537
}));
3638

37-
fs.stat('.', common.mustCall(function(err, stats) {
38-
assert.ok(stats.hasOwnProperty('blksize'));
39-
assert.ok(stats.hasOwnProperty('blocks'));
40-
}));
41-
4239
fs.lstat('.', common.mustCall(function(err, stats) {
4340
assert.ifError(err);
4441
assert.ok(stats.mtime instanceof Date);
@@ -71,16 +68,9 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
7168

7269
// fstatSync
7370
fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
74-
let stats;
75-
try {
76-
stats = fs.fstatSync(fd);
77-
} catch (err) {
78-
assert.fail(err);
79-
}
80-
if (stats) {
81-
assert.ok(stats.mtime instanceof Date);
82-
}
83-
fs.close(fd, assert.ifError);
71+
const stats = fs.fstatSync(fd);
72+
assert.ok(stats.mtime instanceof Date);
73+
fs.close(fd, common.mustCall(assert.ifError));
8474
}));
8575

8676
fs.stat(__filename, common.mustCall(function(err, s) {
@@ -92,38 +82,30 @@ fs.stat(__filename, common.mustCall(function(err, s) {
9282
assert.strictEqual(s.isCharacterDevice(), false);
9383
assert.strictEqual(s.isFIFO(), false);
9484
assert.strictEqual(s.isSymbolicLink(), false);
95-
const keys = [
85+
86+
const jsonString = JSON.stringify(s);
87+
const parsed = JSON.parse(jsonString);
88+
[
9689
'dev', 'mode', 'nlink', 'uid',
9790
'gid', 'rdev', 'blksize', 'ino', 'size', 'blocks',
9891
'atime', 'mtime', 'ctime', 'birthtime',
99-
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs'
100-
];
101-
const numberFields = [
102-
'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size',
103-
'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs'
104-
];
105-
const dateFields = ['atime', 'mtime', 'ctime', 'birthtime'];
106-
keys.forEach(function(k) {
92+
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs',
93+
].forEach(function(k) {
10794
assert.ok(k in s, `${k} should be in Stats`);
10895
assert.notStrictEqual(s[k], undefined, `${k} should not be undefined`);
10996
assert.notStrictEqual(s[k], null, `${k} should not be null`);
110-
});
111-
numberFields.forEach((k) => {
112-
assert.strictEqual(typeof s[k], 'number', `${k} should be a number`);
113-
});
114-
dateFields.forEach((k) => {
115-
assert.ok(s[k] instanceof Date, `${k} should be a Date`);
116-
});
117-
const jsonString = JSON.stringify(s);
118-
const parsed = JSON.parse(jsonString);
119-
keys.forEach(function(k) {
12097
assert.notStrictEqual(parsed[k], undefined, `${k} should not be undefined`);
12198
assert.notStrictEqual(parsed[k], null, `${k} should not be null`);
12299
});
123-
numberFields.forEach((k) => {
100+
[
101+
'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size',
102+
'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs',
103+
].forEach((k) => {
104+
assert.strictEqual(typeof s[k], 'number', `${k} should be a number`);
124105
assert.strictEqual(typeof parsed[k], 'number', `${k} should be a number`);
125106
});
126-
dateFields.forEach((k) => {
107+
['atime', 'mtime', 'ctime', 'birthtime'].forEach((k) => {
108+
assert.ok(s[k] instanceof Date, `${k} should be a Date`);
127109
assert.strictEqual(typeof parsed[k], 'string', `${k} should be a string`);
128110
});
129111
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.