|
23 | 23 | const common = require('../common');
|
24 | 24 | const assert = require('assert');
|
25 | 25 | const fs = require('fs');
|
| 26 | +const util = require('util'); |
26 | 27 |
|
27 | 28 | fs.stat('.', common.mustCall(function(err, stats) {
|
28 | 29 | assert.ifError(err);
|
@@ -65,38 +66,56 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
|
65 | 66 | assert.fail(err);
|
66 | 67 | }
|
67 | 68 | if (stats) {
|
68 |
| - console.dir(stats); |
69 | 69 | assert.ok(stats.mtime instanceof Date);
|
70 | 70 | }
|
71 | 71 | fs.close(fd, assert.ifError);
|
72 | 72 | }));
|
73 | 73 |
|
74 |
| -console.log(`stating: ${__filename}`); |
75 | 74 | fs.stat(__filename, common.mustCall(function(err, s) {
|
76 | 75 | assert.ifError(err);
|
77 |
| - |
78 |
| - console.dir(s); |
79 |
| - |
80 |
| - console.log(`isDirectory: ${JSON.stringify(s.isDirectory())}`); |
81 | 76 | assert.strictEqual(false, s.isDirectory());
|
82 |
| - |
83 |
| - console.log(`isFile: ${JSON.stringify(s.isFile())}`); |
84 | 77 | assert.strictEqual(true, s.isFile());
|
85 |
| - |
86 |
| - console.log(`isSocket: ${JSON.stringify(s.isSocket())}`); |
87 | 78 | assert.strictEqual(false, s.isSocket());
|
88 |
| - |
89 |
| - console.log(`isBlockDevice: ${JSON.stringify(s.isBlockDevice())}`); |
90 | 79 | assert.strictEqual(false, s.isBlockDevice());
|
91 |
| - |
92 |
| - console.log(`isCharacterDevice: ${JSON.stringify(s.isCharacterDevice())}`); |
93 | 80 | assert.strictEqual(false, s.isCharacterDevice());
|
94 |
| - |
95 |
| - console.log(`isFIFO: ${JSON.stringify(s.isFIFO())}`); |
96 | 81 | assert.strictEqual(false, s.isFIFO());
|
97 |
| - |
98 |
| - console.log(`isSymbolicLink: ${JSON.stringify(s.isSymbolicLink())}`); |
99 | 82 | assert.strictEqual(false, s.isSymbolicLink());
|
100 |
| - |
101 |
| - assert.ok(s.mtime instanceof Date); |
| 83 | + const keys = [ |
| 84 | + 'dev', 'mode', 'nlink', 'uid', |
| 85 | + 'gid', 'rdev', 'ino', 'size', |
| 86 | + 'atime', 'mtime', 'ctime', 'birthtime', |
| 87 | + 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' |
| 88 | + ]; |
| 89 | + if (!common.isWindows) { |
| 90 | + keys.push('blocks', 'blksize'); |
| 91 | + } |
| 92 | + const numberFields = [ |
| 93 | + 'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'ino', 'size', |
| 94 | + 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' |
| 95 | + ]; |
| 96 | + const dateFields = ['atime', 'mtime', 'ctime', 'birthtime']; |
| 97 | + keys.forEach(function(k) { |
| 98 | + assert.ok(k in s, `${k} should be in Stats`); |
| 99 | + assert.notStrictEqual(s[k], undefined, `${k} should not be undefined`); |
| 100 | + assert.notStrictEqual(s[k], null, `${k} should not be null`); |
| 101 | + }); |
| 102 | + numberFields.forEach((k) => { |
| 103 | + assert.strictEqual(typeof s[k], 'number', `${k} should be a number`); |
| 104 | + }); |
| 105 | + dateFields.forEach((k) => { |
| 106 | + assert.ok(s[k] instanceof Date, `${k} should be a Date`); |
| 107 | + }); |
| 108 | + const jsonString = JSON.stringify(s); |
| 109 | + const parsed = JSON.parse(jsonString); |
| 110 | + keys.forEach(function(k) { |
| 111 | + assert.notStrictEqual(parsed[k], undefined, `${k} should not be undefined`); |
| 112 | + assert.notStrictEqual(parsed[k], null, `${k} should not be null`); |
| 113 | + }); |
| 114 | + numberFields.forEach((k) => { |
| 115 | + assert.strictEqual(typeof parsed[k], 'number', `${k} should be a number`); |
| 116 | + }); |
| 117 | + dateFields.forEach((k) => { |
| 118 | + assert.strictEqual(typeof parsed[k], 'string', `${k} should be a string`); |
| 119 | + }); |
| 120 | + assert.strictEqual(util.inspect(s.toJSON()), util.inspect(s)); |
102 | 121 | }));
|
0 commit comments