failed-resolution.html (1840B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/import-maps/resources/test-helper.js"></script> 7 </head> 8 <body> 9 <script type="module"> 10 const log = []; 11 // Import specifiers that were not yet mapped. 12 try { 13 await import("../resources/importer.sub.js?name=a") 14 } catch (error) { 15 // Import failed because "a" is not yet defined as a specifier. 16 } 17 try { 18 await import("../resources/importer.sub.js?name=foo/bar") 19 } catch (error) { 20 // Import failed because "foo/bar" is not yet defined as a specifier. 21 } 22 // Try to define the previous failed-to-resolve specifiers. 23 const importMapScript = document.createElement('script'); 24 importMapScript.type = 'importmap'; 25 importMapScript.textContent = 26 `{ 27 "imports": { 28 "a": "../resources/log.sub.js?name=B", 29 "foo/bar": "../resources/log.sub.js?name=OtherFoobar", 30 "foo/": "../resources/log.sub.js?name=OtherFoo/", 31 "foo": "../resources/log.sub.js?name=foo" 32 } 33 }`; 34 document.head.appendChild(importMapScript); 35 36 // Testing that the resolution is correct using `resolve`, as you can't import 37 // the same module twice. 38 test(() => { 39 assert_true(import.meta.resolve("a").endsWith("/resources/log.sub.js?name=B")); 40 }, "Resolution after import map should not be redefined"); 41 42 test(() => { 43 assert_true(import.meta.resolve("foo/bar").endsWith("/resources/log.sub.js?name=OtherFoobar")); 44 }, "Resolution after import map should not be redefined for bare prefixes or exact matches"); 45 46 test(() => { 47 assert_true(import.meta.resolve("foo").endsWith("/resources/log.sub.js?name=foo")); 48 }, "Resolution after import map should be redefined for non-prefixes"); 49 50 test_loaded( 51 "../resources/log.sub.js?name=a", 52 ["log:a"], 53 "Rules for failed resolution are not dropped" 54 ); 55 </script> 56 </body> 57 </html>