MCPcopy Index your code
hub / github.com/nodejs/node / verifyStats

Function verifyStats

test/parallel/test-fs-stat-bigint.js:21–94  ·  view source on GitHub ↗
(bigintStats, numStats, allowableDelta)

Source from the content-addressed store, hash-verified

19}
20
21function verifyStats(bigintStats, numStats, allowableDelta) {
22 // allowableDelta: It's possible that the file stats are updated between the
23 // two stat() calls so allow for a small difference.
24 for (const key of Object.keys(numStats)) {
25 const val = numStats[key];
26 if (isDate(val)) {
27 const time = val.getTime();
28 const time2 = bigintStats[key].getTime();
29 assert(
30 time - time2 <= allowableDelta,
31 `difference of ${key}.getTime() should <= ${allowableDelta}.\n` +
32 `Number version ${time}, BigInt version ${time2}n`);
33 } else if (key === 'mode') {
34 assert.strictEqual(bigintStats[key], BigInt(val));
35 assert.strictEqual(
36 bigintStats.isBlockDevice(),
37 numStats.isBlockDevice()
38 );
39 assert.strictEqual(
40 bigintStats.isCharacterDevice(),
41 numStats.isCharacterDevice()
42 );
43 assert.strictEqual(
44 bigintStats.isDirectory(),
45 numStats.isDirectory()
46 );
47 assert.strictEqual(
48 bigintStats.isFIFO(),
49 numStats.isFIFO()
50 );
51 assert.strictEqual(
52 bigintStats.isFile(),
53 numStats.isFile()
54 );
55 assert.strictEqual(
56 bigintStats.isSocket(),
57 numStats.isSocket()
58 );
59 assert.strictEqual(
60 bigintStats.isSymbolicLink(),
61 numStats.isSymbolicLink()
62 );
63 } else if (key.endsWith('Ms')) {
64 const nsKey = key.replace('Ms', 'Ns');
65 const msFromBigInt = bigintStats[key];
66 const nsFromBigInt = bigintStats[nsKey];
67 const msFromBigIntNs = Number(nsFromBigInt / (10n ** 6n));
68 const msFromNum = numStats[key];
69
70 assert(
71 msFromNum - Number(msFromBigInt) <= allowableDelta,
72 `Number version ${key} = ${msFromNum}, ` +
73 `BigInt version ${key} = ${msFromBigInt}n, ` +
74 `Allowable delta = ${allowableDelta}`);
75
76 assert(
77 msFromNum - Number(msFromBigIntNs) <= allowableDelta,
78 `Number version ${key} = ${msFromNum}, ` +

Callers 3

runSyncTestFunction · 0.85
runPromiseTestFunction · 0.85

Calls 10

isBlockDeviceMethod · 0.80
isCharacterDeviceMethod · 0.80
isFIFOMethod · 0.80
isSocketMethod · 0.80
inspectFunction · 0.70
keysMethod · 0.65
assertFunction · 0.50
isDirectoryMethod · 0.45
isFileMethod · 0.45
isSymbolicLinkMethod · 0.45

Tested by

no test coverage detected