-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Expand file tree
/
Copy pathtest-esm-import-attributes-errors.js
More file actions
75 lines (60 loc) · 2.04 KB
/
test-esm-import-attributes-errors.js
File metadata and controls
75 lines (60 loc) · 2.04 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
const common = require('../common');
const assert = require('assert');
const jsModuleDataUrl = 'data:text/javascript,exportassert';
const jsonModuleDataUrl = 'data:application/json,""';
async function test() {
await assert.rejects(
import('data:text/css,', { with: { type: 'css' } }),
{ code: 'ERR_UNKNOWN_MODULE_FORMAT' }
);
await assert.rejects(
import('data:text/css,', { with: { unsupportedAttribute: 'value' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
);
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(jsModuleDataUrl, { 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
);
}
test().then(common.mustCall());