Files
node/test/es-module/test-require-module-tla-retry-import.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

26 lines
774 B
JavaScript

// This tests that after failing to require an ESM that contains TLA,
// retrying with import() still works, and produces consistent results.
'use strict';
const common = require('../common');
const assert = require('assert');
let ns;
async function test() {
assert.throws(() => {
require('../fixtures/es-modules/tla/export-async.mjs');
}, {
code: 'ERR_REQUIRE_ASYNC_MODULE',
});
const newNs = await import('../fixtures/es-modules/tla/export-async.mjs');
if (ns === undefined) {
ns = newNs;
} else {
// Check that re-evalaution is returning the same namespace.
assert.strictEqual(ns, newNs);
}
assert.strictEqual(ns.hello, 'world');
}
// Run the test twice to check consistency after caching.
test().then(test).then(common.mustCall());