node/test/parallel/test-tojson-perf_hooks.js
Yash Ladha 93f0b4d35b
perf_hooks: add toJSON to performance class
Added toJSON method to the InternalPerformance class as per the
convention followed in other performance classes and per the spec:
https://www.w3.org/TR/hr-time/#tojson-method

Fixes: https://github.com/nodejs/node/issues/37623

PR-URL: https://github.com/nodejs/node/pull/37771
Fixes: https://github.com/nodejs/node/issues/37623
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-04-30 13:28:27 -07:00

15 lines
447 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { performance } = require('perf_hooks');
// Test toJSON for performance object
{
assert.strictEqual(typeof performance.toJSON, 'function');
const jsonObject = performance.toJSON();
assert.strictEqual(typeof jsonObject, 'object');
assert.strictEqual(jsonObject.timeOrigin, performance.timeOrigin);
assert.strictEqual(typeof jsonObject.nodeTiming, 'object');
}