summaryrefslogtreecommitdiffstats
path: root/dom/base/test/jsmodules/importmaps/test_dynamic_import_reject_importMap.html
blob: 96744c93172b97a1adb2b4cf01a67b0c30e98434 (plain)
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
<!DOCTYPE html>
<head>
  <meta charset=utf-8>
  <title>Test import map should be rejected.</title>
</head>
<body onload='testLoaded()'>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

<!--There is a dynamic import before the import map tag, so the import map-->
<!--cannot be accepted according to the spec.-->
<!--And because the import map is rejected, so the module specifier-->
<!--"./module_simpleExport.mjs" won't be remapped to-->
<!--"./scope1/module_simpleExport.mjs".-->

<script>
  import("./module_simpleExport.mjs");
</script>

<script type="importmap" onerror='importMapError()'>
{
  "imports": {
    "./module_simpleExport.mjs": "./scope1/module_simpleExport.mjs"
  }
}
</script>

<script>
  SimpleTest.waitForExplicitFinish();

  let hasError = false;
  function importMapError() {
    hasError = true;
  }

  function testLoaded() {
    import("./module_simpleExport.mjs").then((ns) => {
      ok(ns.x == 42, 'Check simple imported value result: ' + ns.x);
      ok(hasError, "onerror of the import map should be called.");
    }).catch((e) => {
      ok(false, "throws " + e);
    }).then(() => {
      SimpleTest.finish();
    });
  }
</script>
</body>