mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
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>
24 lines
657 B
JavaScript
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, '');
|