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/62300 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
import '../common/index.mjs';
|
|
import assert from 'assert';
|
|
|
|
const jsModuleDataUrl = 'data:text/javascript,export{}';
|
|
const jsonModuleDataUrl = 'data:application/json,""';
|
|
|
|
await assert.rejects(
|
|
// This rejects because of the unsupported MIME type, not because of the
|
|
// unsupported assertion.
|
|
import('data:text/css,', { with: { type: 'css' } }),
|
|
{ code: 'ERR_UNKNOWN_MODULE_FORMAT' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}with{type:"json"}`),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsModuleDataUrl, { with: { type: 'json' } }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsModuleDataUrl, { with: { type: 'text' } }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(import.meta.url, { with: { type: 'unsupported' } }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsonModuleDataUrl),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsonModuleDataUrl, { with: {} }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsonModuleDataUrl, { with: { foo: 'bar' } }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(jsonModuleDataUrl, { assert: { type: 'json' } }),
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
|
|
);
|
|
|
|
await assert.rejects(
|
|
import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`),
|
|
SyntaxError
|
|
);
|