node/test/es-module/test-esm-import-attributes-errors.js
Joyee Cheung 7535aa1f72 esm: link modules synchronously when no async loader hooks are used
When no async loader hooks are registered, perform the linking as
synchronously as possible to reduce the chance of races from the
the shared module loading cache.

PR-URL: https://github.com/nodejs/node/pull/59519
Fixes: https://github.com/nodejs/node/issues/59366
Refs: https://github.com/abejfehr/node-22.18-issue-repro
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-08-20 14:31:08 +00:00

71 lines
1.8 KiB
JavaScript

'use strict';
const common = require('../common');
const { rejects } = require('assert');
const jsModuleDataUrl = 'data:text/javascript,export{}';
const jsonModuleDataUrl = 'data:application/json,""';
async function test() {
await rejects(
import('data:text/css,', { with: { type: 'css' } }),
{ code: 'ERR_UNKNOWN_MODULE_FORMAT' }
);
await rejects(
import('data:text/css,', { with: { unsupportedAttribute: 'value' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);
await rejects(
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}with{type:"json"}`),
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
);
await rejects(
import(jsModuleDataUrl, { with: { type: 'json' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
);
await rejects(
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);
await rejects(
import(jsModuleDataUrl, { with: { type: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);
await rejects(
import(jsonModuleDataUrl),
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
);
await rejects(
import(jsonModuleDataUrl, { with: {} }),
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
);
await rejects(
import(jsonModuleDataUrl, { with: { foo: 'bar' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);
await rejects(
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);
await rejects(
import(jsonModuleDataUrl, { assert: { type: 'json' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
);
await rejects(
import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`),
SyntaxError
);
}
test().then(common.mustCall());