• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const { rejects } = require('assert');
4
5const jsModuleDataUrl = 'data:text/javascript,export{}';
6const jsonModuleDataUrl = 'data:application/json,""';
7
8common.expectWarning(
9  'ExperimentalWarning',
10  'Import assertions are not a stable feature of the JavaScript language. ' +
11  'Avoid relying on their current behavior and syntax as those might change ' +
12  'in a future version of Node.js.'
13);
14
15async function test() {
16  await rejects(
17    import('data:text/css,', { assert: { type: 'css' } }),
18    { code: 'ERR_UNKNOWN_MODULE_FORMAT' }
19  );
20
21  await rejects(
22    import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}assert{type:"json"}`),
23    { code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
24  );
25
26  await rejects(
27    import(jsModuleDataUrl, { assert: { type: 'json' } }),
28    { code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
29  );
30
31  await rejects(
32    import(jsModuleDataUrl, { assert: { type: 'unsupported' } }),
33    { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
34  );
35
36  await rejects(
37    import(jsonModuleDataUrl),
38    { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
39  );
40
41  await rejects(
42    import(jsonModuleDataUrl, { assert: {} }),
43    { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
44  );
45
46  await rejects(
47    import(jsonModuleDataUrl, { assert: { foo: 'bar' } }),
48    { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
49  );
50
51  await rejects(
52    import(jsonModuleDataUrl, { assert: { type: 'unsupported' }}),
53    { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
54  );
55}
56
57test().then(common.mustCall());
58