-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1929548 [wpt PR 49004] - Multiple import maps, a=testonly
Automatic update from web-platform-tests Multiple import maps Import maps currently have to load before any ES module and there can only be a single import map per document. That makes them fragile and potentially slow to use in real-life scenarios: Any module that loads before them breaks the entire app, and in apps with many modules the become a large blocking resource, as the entire map for all possible modules needs to load first. This implements whatwg/html#10528 to solve that. Change-Id: I54e1b9cdfe989d61c85d73a5fd384f860273ad9a Bug: 358379381 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5776262 Commit-Queue: Yoav Weiss (@Shopify) <yoavweiss@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/main@{#1378943} -- wpt-commits: 3f26764c67f20c6f5306063fc9bcda13930a51ca wpt-pr: 49004
- Loading branch information
1 parent
49aad56
commit b3328ee
Showing
27 changed files
with
637 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
testing/web-platform/tests/import-maps/multiple-import-maps/already-resolved-dropped.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/import-maps/resources/test-helper.js"></script> | ||
<script> | ||
// Simulate resolving a module before import maps are processed | ||
import("../resources/log.js?pipe=sub&name=ModuleA").catch(() => {}); | ||
</script> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"../resources/log.js?pipe=sub&name=ModuleA": "../resources/log.js?pipe=sub&name=ModuleB", | ||
"http:/": "../resources/log.js?pipe=sub&name=scheme", | ||
"https:/": "../resources/log.js?pipe=sub&name=scheme" | ||
} | ||
} | ||
</script> | ||
<script> | ||
test_loaded( | ||
"../resources/log.js?pipe=sub&name=ModuleA", | ||
["log:ModuleA"], | ||
"Rules for already resolved modules are dropped" | ||
); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
testing/web-platform/tests/import-maps/multiple-import-maps/conflict-first-persists.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"module-a": "../resources/log.js?pipe=sub&name=ModuleA", | ||
"module-b/something": "../resources/log.js?pipe=sub&name=ModuleB" | ||
} | ||
} | ||
</script> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"module-a": "../resources/log.js?pipe=sub&name=OtherModuleA", | ||
"module-b/": "../resources/log.js?pipe=sub&name=PrefixModuleB", | ||
"module-b": "../resources/log.js?pipe=sub&name=OtherModuleB" | ||
} | ||
} | ||
</script> | ||
<script> | ||
const test_loaded = (specifier, expected_log, description) => { | ||
promise_test(async t => { | ||
log = []; | ||
await import(specifier); | ||
assert_array_equals(log, expected_log); | ||
}, description); | ||
}; | ||
|
||
test_loaded( | ||
"module-a", | ||
["log:ModuleA"], | ||
"First defined rule persists in case of conflict" | ||
); | ||
|
||
test_loaded( | ||
"module-b/something", | ||
["log:ModuleB"], | ||
"First defined rule persists in case of conflict - prefixed bare specifiers" | ||
); | ||
|
||
test_loaded( | ||
"module-b", | ||
["log:OtherModuleB"], | ||
"First defined rule persists in case of conflict - non-prefix bare specifier" | ||
); | ||
</script> | ||
</html> |
45 changes: 45 additions & 0 deletions
45
.../tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
function waitForBool(boolName) { | ||
return new Promise((resolve) => { | ||
const checkVariable = setInterval(() => { | ||
if (window[boolName]) { | ||
clearInterval(checkVariable); | ||
resolve(); | ||
} | ||
}, 0); | ||
}); | ||
} | ||
|
||
step_timeout(() => { | ||
const importMapScript = document.createElement('script'); | ||
importMapScript.type = 'importmap'; | ||
importMapScript.textContent = JSON.stringify({ | ||
imports: { | ||
"../resources/log.sub.js?name=A": "../resources/log.sub.js?name=B" | ||
} | ||
}); | ||
document.head.appendChild(importMapScript); | ||
}, 100); | ||
const log = []; | ||
</script> | ||
<script type="module"> | ||
import "../resources/importer.sub.js?pipe=trickle(d0.5)&name=..%2Fresources%2Flog.sub.js%3Fname%3DA"; | ||
</script> | ||
<script type="module"> | ||
test(() => { | ||
assert_array_equals(log, ["log:B"], "Import should use the new import map"); | ||
}, "Module tree that started to download before a new import map should still take it into account"); | ||
</script> | ||
</body> | ||
</html> | ||
|
||
|
||
|
||
|
33 changes: 33 additions & 0 deletions
33
...latform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script type="module" async> | ||
step_timeout(() => { | ||
const importMapScript = document.createElement('script'); | ||
importMapScript.type = 'importmap'; | ||
importMapScript.textContent = JSON.stringify({ | ||
imports: { | ||
"../resources/log.sub.js?name=A": "../resources/log.sub.js?name=B" | ||
} | ||
}); | ||
document.head.appendChild(importMapScript); | ||
}, 100); | ||
</script> | ||
<script> | ||
const log = []; | ||
</script> | ||
<script type="module" src="../resources/importer.sub.js?pipe=trickle(d0.5)&name=..%2Fresources%2Flog.sub.js%3Fname%3DA"></script> | ||
<script type="module"> | ||
test(() => { | ||
assert_array_equals(log, ["log:B"], "Import should use the new import map"); | ||
}, "Module tree that started to download before a new import map should still take it into account"); | ||
</script> | ||
</body> | ||
</html> | ||
|
||
|
||
|
32 changes: 32 additions & 0 deletions
32
testing/web-platform/tests/import-maps/multiple-import-maps/url-resolution-conflict.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
const log = []; | ||
</script> | ||
<script type="importmap"> | ||
{ | ||
"scopes": { | ||
"/": { | ||
"../resources/../resources/app.js": "../resources/log.js?pipe=sub&name=first" | ||
} | ||
} | ||
} | ||
</script> | ||
<script type="importmap"> | ||
{ | ||
"scopes": { | ||
"/": { | ||
"../resources/app.js": "../resources/log.js?pipe=sub&name=second" | ||
} | ||
} | ||
} | ||
</script> | ||
<script type="module"> | ||
promise_test(async () => { | ||
await import("../resources/app.js"); | ||
assert_array_equals(log, ["log:first"]); | ||
}, | ||
"Second import map should not override same resolved URL"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
testing/web-platform/tests/import-maps/not-overridden/dynamic.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
const log = []; | ||
|
||
// First, use a module specifier | ||
promise_test(() => { | ||
return import("../resources/log.js?pipe=sub&name=A") | ||
.then(() => { | ||
assert_array_equals(log, ["log:A"], "First import should use original module"); | ||
}); | ||
}, "Initial import before import map"); | ||
|
||
// Now try to redefine it with multiple import map rules | ||
</script> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=B", | ||
"http:/": "../resources/log.js?pipe=sub&name=scheme", | ||
"https:/": "../resources/log.js?pipe=sub&name=scheme" | ||
} | ||
} | ||
</script> | ||
<script type="module"> | ||
// Testing that the resolution is correct using `resolve`, as you can't import | ||
// the same module twice. | ||
test(() => { | ||
assert_true(import.meta.resolve("../resources/log.js?pipe=sub&name=A") | ||
.endsWith("/resources/log.js?pipe=sub&name=A")); | ||
}, "Resolution after import map should not be redefined"); | ||
</script> | ||
</body> | ||
</html> | ||
|
Oops, something went wrong.