-
Notifications
You must be signed in to change notification settings - Fork 30k
/
test-esm-import-attributes-validation.js
45 lines (34 loc) · 1.47 KB
/
test-esm-import-attributes-validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 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',
});