mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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>
25 lines
701 B
JavaScript
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, '');
|