mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
fbdfe9399c
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>
46 lines
1004 B
JavaScript
46 lines
1004 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const dc = require('diagnostics_channel');
|
|
|
|
const trace = dc.tracingChannel('module.require');
|
|
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.mustNotCall(track('asyncStart')),
|
|
asyncEnd: common.mustNotCall(track('asyncEnd')),
|
|
error: common.mustNotCall(track('error')),
|
|
});
|
|
|
|
const result = require('http');
|
|
|
|
// Verify order and contents of each event
|
|
assert.deepStrictEqual(events, [
|
|
{
|
|
name: 'start',
|
|
parentFilename: module.filename,
|
|
id: 'http',
|
|
},
|
|
{
|
|
name: 'end',
|
|
parentFilename: module.filename,
|
|
id: 'http',
|
|
result,
|
|
},
|
|
]);
|