mirror of
https://github.com/nodejs/node.git
synced 2025-08-17 06:38:47 +02:00

This commit adds a tracing channel for module loading through `import()` and `require()`. Co-Authored-By: Stephen Belanger <admin@stephenbelanger.com> PR-URL: https://github.com/nodejs/node/pull/44340 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const dc = require('diagnostics_channel');
|
|
|
|
const trace = dc.tracingChannel('module.import');
|
|
const events = [];
|
|
let lastEvent;
|
|
|
|
function track(name) {
|
|
return (event) => {
|
|
// Verify every event after the first is the same object
|
|
if (events.length) {
|
|
assert.strictEqual(event, lastEvent);
|
|
}
|
|
lastEvent = event;
|
|
|
|
events.push({ name, ...event });
|
|
};
|
|
}
|
|
|
|
trace.subscribe({
|
|
start: common.mustCall(track('start')),
|
|
end: common.mustCall(track('end')),
|
|
asyncStart: common.mustCall(track('asyncStart')),
|
|
asyncEnd: common.mustCall(track('asyncEnd')),
|
|
error: common.mustNotCall(track('error')),
|
|
});
|
|
|
|
import('http').then(
|
|
common.mustCall((result) => {
|
|
let expectedParentURL = module.filename.replaceAll('\\', '/');
|
|
expectedParentURL = common.isWindows ?
|
|
`file:///${expectedParentURL}` :
|
|
`file://${expectedParentURL}`;
|
|
// Verify order and contents of each event
|
|
assert.deepStrictEqual(events, [
|
|
{
|
|
name: 'start',
|
|
parentURL: expectedParentURL,
|
|
url: 'http',
|
|
},
|
|
{
|
|
name: 'end',
|
|
parentURL: expectedParentURL,
|
|
url: 'http',
|
|
},
|
|
{
|
|
name: 'asyncStart',
|
|
parentURL: expectedParentURL,
|
|
url: 'http',
|
|
result,
|
|
},
|
|
{
|
|
name: 'asyncEnd',
|
|
parentURL: expectedParentURL,
|
|
url: 'http',
|
|
result,
|
|
},
|
|
]);
|
|
}),
|
|
common.mustNotCall(),
|
|
);
|