3 <script src=
"/resources/testharness.js"></script>
4 <script src=
"/resources/testharnessreport.js"></script>
6 setup({allow_uncaught_exception
: true});
8 // Hacky glue code to run Jest-based tests as WPT tests.
9 // Only supports resolving.js.
10 function require(name
) {
13 'parseFromString': parseFromString
,
20 toMatchURL
: expected
=> assert_equals(v
, expected
),
21 toThrow
: expected
=> assert_throws(expected(), v
)
25 let current_message
= '';
26 function describe(message
, f
) {
27 const old
= current_message
;
28 if (current_message
!== '') {
29 current_message
+= ' / ';
31 current_message
+= message
;
33 current_message
= old
;
35 function it(message
, f
) {
36 const old
= current_message
;
37 if (current_message
!== '') {
38 current_message
+= ' / ';
40 current_message
+= message
;
41 test(t
=> t
.step_func(f
)(), current_message
);
42 current_message
= old
;
45 // Creates a new Document (via <iframe>) and add an inline import map.
46 // Currently document.write() is used to make everything synchronous, which
47 // is just needed for running the existing Jest-based tests easily.
48 function parseFromString(mapString
, mapBaseURL
) {
49 const iframe
= document
.createElement('iframe');
50 document
.body
.appendChild(iframe
);
51 iframe
.contentDocument
.write(`
52 <base href="${mapBaseURL}">
59 <script type="importmap" onerror="onError()">
63 iframe
.contentDocument
.close();
67 // URL resolution is tested using Chromium's `internals`.
68 // TODO(hiroshige): Remove the Chromium-specific dependency.
69 function resolve(specifier
, map
, baseURL
) {
70 return internals
.resolveModuleSpecifier(specifier
,
79 https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/resolving.js
81 <script type=
"module" src=
"resources/resolving.js"></script>