Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 3 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /import-maps/not-overridden/failed-resolution.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/import-maps/resources/test-helper.js"></script>
</head>
<body>
<script type="module">
const log = [];
// Import specifiers that were not yet mapped.
try {
await import("../resources/importer.sub.js?name=a")
} catch (error) {
// Import failed because "a" is not yet defined as a specifier.
}
try {
await import("../resources/importer.sub.js?name=foo/bar")
} catch (error) {
// Import failed because "foo/bar" is not yet defined as a specifier.
}
// Try to define the previous failed-to-resolve specifiers.
const importMapScript = document.createElement('script');
importMapScript.type = 'importmap';
importMapScript.textContent =
`{
"imports": {
"a": "../resources/log.sub.js?name=B",
"foo/bar": "../resources/log.sub.js?name=OtherFoobar",
"foo/": "../resources/log.sub.js?name=OtherFoo/",
"foo": "../resources/log.sub.js?name=foo"
}
}`;
document.head.appendChild(importMapScript);
// Testing that the resolution is correct using `resolve`, as you can't import
// the same module twice.
test(() => {
assert_true(import.meta.resolve("a").endsWith("/resources/log.sub.js?name=B"));
}, "Resolution after import map should not be redefined");
test(() => {
assert_true(import.meta.resolve("foo/bar").endsWith("/resources/log.sub.js?name=OtherFoobar"));
}, "Resolution after import map should not be redefined for bare prefixes or exact matches");
test(() => {
assert_true(import.meta.resolve("foo").endsWith("/resources/log.sub.js?name=foo"));
}, "Resolution after import map should be redefined for non-prefixes");
test_loaded(
"../resources/log.sub.js?name=a",
["log:a"],
"Rules for failed resolution are not dropped"
);
</script>
</body>
</html>