2024-10-28 13:21:22 +01:00
|
|
|
// 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');
|
|
|
|
|
}, {
|
2025-11-29 15:10:12 +01:00
|
|
|
code: 'ERR_REQUIRE_ASYNC_MODULE',
|
2024-10-28 13:21:22 +01:00
|
|
|
});
|
|
|
|
|
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.
|
2025-12-11 00:55:36 +01:00
|
|
|
test().then(test).then(common.mustCall());
|