forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-process-hrtime.js
More file actions
36 lines (30 loc) · 1.11 KB
/
test-process-hrtime.js
File metadata and controls
36 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'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$/);
assert.throws(() => {
process.hrtime([]);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
assert.throws(() => {
process.hrtime([1]);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
assert.throws(() => {
process.hrtime([1, 2, 3]);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
function validateTuple(tuple) {
assert(Array.isArray(tuple));
assert.strictEqual(tuple.length, 2);
assert(Number.isInteger(tuple[0]));
assert(Number.isInteger(tuple[1]));
}
const diff = process.hrtime([0, 1e9 - 1]);
assert(diff[1] >= 0); // https://github.com/nodejs/node/issues/4751