summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-importmap.html
blob: 214b9bb59c3a736122215075013bfd07eb1c057b (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
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<!--
  More extensive tests of import maps and import.meta.resolve() will be
  located in the import maps test suite. This contains some basic tests plus
  tests some tricky parts of the import.meta.resolve() algorithm around string
  conversion which are only testable with import maps.
-->

<script type="importmap">
{
  "imports": {
    "bare": "https://example.com/",
    "https://example.com/rewrite": "https://example.com/rewritten",

    "1": "https://example.com/PASS-1",
    "null": "https://example.com/PASS-null",
    "undefined": "https://example.com/PASS-undefined",
    "[object Object]": "https://example.com/PASS-object",

    "./start": "./resources/export-1.mjs",
    "./resources/export-1.mjs": "./resources/export-2.mjs"
  }
}
</script>

<script type="module">
test(() => {
  assert_equals(import.meta.resolve("bare"), "https://example.com/");
}, "import.meta.resolve() given an import mapped bare specifier");

test(() => {
  assert_equals(import.meta.resolve("https://example.com/rewrite"), "https://example.com/rewritten");
}, "import.meta.resolve() given an import mapped  URL-like specifier");

test(() => {
  assert_equals(import.meta.resolve(), "https://example.com/PASS-undefined", "no-arg case");

  assert_equals(import.meta.resolve(1), "https://example.com/PASS-1");
  assert_equals(import.meta.resolve(null), "https://example.com/PASS-null");
  assert_equals(import.meta.resolve(undefined), "https://example.com/PASS-undefined");

  // Only toString() methods are consulted by ToString, not valueOf() ones.
  // So this becomes "[object Object]".
  assert_equals(import.meta.resolve({ valueOf() { return "./x"; } }), "https://example.com/PASS-object");
}, "Testing the ToString() step of import.meta.resolve() via import maps");

promise_test(async () => {
  const one = (await import("./start")).default;
  assert_equals(one, 1);

  const two = (await import(import.meta.resolve("./start"))).default;
  assert_equals(two, 2);
}, "import(import.meta.resolve(x)) can be different from import(x)");
</script>