node/test/es-module/test-require-module-tla-execution.js
Joyee Cheung 8d10bc7b09 module: improve error message from asynchronicity in require(esm)
- Improve the error message that shows up when there is a race
  from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
  parent and target file names, if available.

Drive-by: split the require(tla) tests since we are modifying
the tests already.

PR-URL: https://github.com/nodejs/node/pull/57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-02-20 17:22:08 +00:00

27 lines
760 B
JavaScript

'use strict';
// Tests that require(esm) with top-level-await throws before execution starts
// if --experimental-print-required-tla is not enabled.
const common = require('../common');
const assert = require('assert');
const { spawnSyncAndExit } = require('../common/child_process');
const fixtures = require('../common/fixtures');
{
spawnSyncAndExit(process.execPath, [
fixtures.path('es-modules/tla/require-execution.js'),
], {
signal: null,
status: 1,
stderr(output) {
assert.doesNotMatch(output, /I am executed/);
common.expectRequiredTLAError(output);
assert.match(output, /From .*require-execution\.js/);
assert.match(output, /Requiring .*execution\.mjs/);
return true;
},
stdout: ''
});
}