Files
node/test/es-module/test-esm-loader-text-format.mjs
T
Efe Karasakal 4df7d44a98 esm: only register text format when enabled
Signed-off-by: Efe Karasakal <hi@efe.dev>
PR-URL: https://github.com/nodejs/node/pull/64992
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-08-08 15:54:33 +00:00

24 lines
657 B
JavaScript

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 without the feature flag.
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, '');