0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/es-module/test-esm-import-attributes-validation.js
Antoine du Hamel 37d4f08cbd
esm: rename error code related to import attributes
PR-URL: https://github.com/nodejs/node/pull/50181
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2023-10-18 14:27:55 +00:00

46 lines
1.5 KiB
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { validateAttributes } = require('internal/modules/esm/assert');
const url = 'test://';
assert.ok(validateAttributes(url, 'builtin', {}));
assert.ok(validateAttributes(url, 'commonjs', {}));
assert.ok(validateAttributes(url, 'json', { type: 'json' }));
assert.ok(validateAttributes(url, 'module', {}));
assert.ok(validateAttributes(url, 'wasm', {}));
assert.throws(() => validateAttributes(url, 'json', {}), {
code: 'ERR_IMPORT_ATTRIBUTE_MISSING',
});
assert.throws(() => validateAttributes(url, 'json', { type: 'json', unsupportedAttribute: 'value' }), {
code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
});
assert.throws(() => validateAttributes(url, 'module', { unsupportedAttribute: 'value' }), {
code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
});
assert.throws(() => validateAttributes(url, 'module', { type: 'json' }), {
code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE',
});
// The HTML spec specifically disallows this for now, while Wasm module import
// and whether it will require a type assertion is still an open question.
assert.throws(() => validateAttributes(url, 'module', { type: 'javascript' }), {
code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
});
assert.throws(() => validateAttributes(url, 'module', { type: 'css' }), {
code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
});
assert.throws(() => validateAttributes(url, 'module', { type: false }), {
code: 'ERR_INVALID_ARG_TYPE',
});