mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
4e68b541fd
PR-URL: https://github.com/nodejs/node/pull/54509 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const dc = require('diagnostics_channel');
|
|
const { pathToFileURL } = require('url');
|
|
|
|
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) => {
|
|
const expectedParentURL = pathToFileURL(module.filename).href;
|
|
// 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(),
|
|
);
|