Files
node/test/es-module/test-esm-loader-text-format.mjs
Chengzhong Wu 949f252ce8 esm: unflag --experimental-import-text
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/67778
Fixes: https://github.com/nodejs/node/issues/67267
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Efe Karasakal <hi@efe.dev>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2026-11-27 16:04:43 +00:00

25 lines
701 B
JavaScript

// Flags: --no-experimental-import-text
import '../common/index.mjs';
import assert from 'node:assert';
import { registerHooks } from 'node:module';
// A user loader can use `text` with and without import attributes when the feature is disabled.
registerHooks({
load(url, context, nextLoad) {
if (url.endsWith('.txt')) {
return nextLoad(url, { ...context, format: 'text' });
}
return nextLoad(url, context);
},
});
const { default: text } = await import('../fixtures/file-to-read-without-bom.txt');
const { default: empty } = await import(
'../fixtures/empty.txt',
{ with: { type: 'text' } }
);
assert.strictEqual(text, 'abc\ndef\nghi\n');
assert.strictEqual(empty, '');