Files
node/test/parallel/test-diagnostics-channel-module-import-error.js
Antoine du Hamel e50cbc1abd test: enforce better never-settling-promise detection
Tests should be explicit regarding whether a promise is expected to
settle, and the test should fail when the behavior does not meet
expectations.

PR-URL: https://github.com/nodejs/node/pull/60976
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
2025-12-10 23:55:36 +00:00

66 lines
1.5 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 common.mustCall((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.mustCall(track('error')),
});
assert.rejects(import('does-not-exist'), (error) => {
const expectedParentURL = pathToFileURL(module.filename).href;
// Verify order and contents of each event
assert.deepStrictEqual(events, [
{
name: 'start',
parentURL: expectedParentURL,
url: 'does-not-exist',
},
{
name: 'end',
parentURL: expectedParentURL,
url: 'does-not-exist',
},
{
name: 'error',
parentURL: expectedParentURL,
url: 'does-not-exist',
error,
},
{
name: 'asyncStart',
parentURL: expectedParentURL,
url: 'does-not-exist',
error,
},
{
name: 'asyncEnd',
parentURL: expectedParentURL,
url: 'does-not-exist',
error,
},
]);
return true;
}).then(common.mustCall());