mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 23:17:19 +00:00

* use const instead of var * use assert.strictEqual instead of assert.equal and plain assert * use arrow functions * swap assertions arguments to match the standard * validate the error for assert.throws PR-URL: https://github.com/nodejs/node/pull/10667 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
30 lines
838 B
JavaScript
30 lines
838 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
// the default behavior, return an Array "tuple" of numbers
|
|
const tuple = process.hrtime();
|
|
|
|
// validate the default behavior
|
|
validateTuple(tuple);
|
|
|
|
// validate that passing an existing tuple returns another valid tuple
|
|
validateTuple(process.hrtime(tuple));
|
|
|
|
// test that only an Array may be passed to process.hrtime()
|
|
assert.throws(() => {
|
|
process.hrtime(1);
|
|
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
|
|
|
|
function validateTuple(tuple) {
|
|
assert(Array.isArray(tuple));
|
|
assert.strictEqual(tuple.length, 2);
|
|
tuple.forEach((v) => {
|
|
assert.strictEqual(typeof v, 'number');
|
|
assert.strictEqual(isFinite(v), true);
|
|
});
|
|
}
|
|
|
|
const diff = process.hrtime([0, 1e9 - 1]);
|
|
assert(diff[1] >= 0); // https://github.com/nodejs/node/issues/4751
|