0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-inspector-promises.js
Erick Wendel 0324529e0f
inspector: introduce inspector/promises API
PR-URL: https://github.com/nodejs/node/pull/44250
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruy Adorno <ruyadorno@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-10-13 23:12:05 +00:00

62 lines
1.7 KiB
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const inspector = require('inspector/promises');
const { basename } = require('path');
const currentFilename = basename(__filename);
{
// Ensure that inspector/promises has the same signature as inspector
assert.deepStrictEqual(Reflect.ownKeys(inspector), Reflect.ownKeys(require('inspector')));
}
(async () => {
{
// Ensure that session.post returns a valid promisified result
const session = new inspector.Session();
session.connect();
await session.post('Profiler.enable');
await session.post('Profiler.start');
const {
profile
} = await session.post('Profiler.stop');
const {
callFrame: {
url,
},
} = profile.nodes.find(({
callFrame,
}) => {
return callFrame.url.includes(currentFilename);
});
session.disconnect();
assert.deepStrictEqual(basename(url), currentFilename);
}
{
// Ensure that even if a post function is slower than another, Promise.all will get it in order
const session = new inspector.Session();
session.connect();
const sum1 = session.post('Runtime.evaluate', { expression: '2 + 2' });
const exp = 'new Promise((r) => setTimeout(() => r(6), 100))';
const sum2 = session.post('Runtime.evaluate', { expression: exp, awaitPromise: true });
const sum3 = session.post('Runtime.evaluate', { expression: '4 + 4' });
const results = (await Promise.all([
sum1,
sum2,
sum3,
])).map(({ result: { value } }) => value);
session.disconnect();
assert.deepStrictEqual(results, [ 4, 6, 8 ]);
}
})().then(common.mustCall());