Skip to content

Commit 62eb445

Browse files
committed
Bug 1916277 - Part 15: Add/Update Mochitest tests. r=jonco,frontend-codestyle-reviewers
Updating the tests with multiple import maps. Differential Revision: https://phabricator.services.mozilla.com/D272784
1 parent 4545802 commit 62eb445

20 files changed

Lines changed: 399 additions & 15 deletions
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
// Existing file ./bad/module_3.mjs should be mapped to ./good/module_3.mjs.
2-
//import {} from "./bad/module_3.mjs";
31
throw "Error: script_6.mjs";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// Existing file ./bad/module_7.mjs should be mapped to ./good/module_4.mjs.
1+
// Existing file ./bad/module_7.mjs should be mapped to ./good/module_7.mjs.
22
// eslint-disable-next-line import/no-unassigned-import
33
import {} from "./bad/module_7.mjs";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[DEFAULT]
2+
support-files = [
3+
"import_circular.mjs",
4+
"import_circular_1.mjs",
5+
"module_simpleExport.mjs",
6+
"module_simpleExport_2.mjs",
7+
"module_simpleImport.mjs",
8+
]
9+
10+
prefs = ["dom.multiple_import_maps.enabled=true"]
11+
12+
["test_importMap_after_module_load.html"]
13+
14+
["test_importMap_between_dynamic_imports.html"]
15+
16+
["test_importMap_between_inline_modules.html"]
17+
18+
["test_importMap_circular.html"]
19+
20+
["test_multiple_importMaps.html"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { a } from "./import_circular_1.mjs";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { a } from "./import_circular.mjs";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let x = 42;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let x = 84;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { x } from "./module_simpleExport.mjs";
2+
3+
// eslint-disable-next-line no-undef
4+
result = x;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2+
# vim: set filetype=python:
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
MOCHITEST_CHROME_MANIFESTS += ["chrome.toml"]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<meta charset=utf-8>
4+
<title>Test a top-level module load before and after an import map</title>
5+
</head>
6+
<body onload='testLoaded()'>
7+
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
8+
9+
<script>var result;</script>
10+
11+
<!--This is a module load before the import map tag-->
12+
<!--It will import "./module_simpleExport.mjs", which makes "module_simpleExport.mjs"-->
13+
<!--as a resolved module.-->
14+
<script src="./module_simpleImport.mjs" type="module">
15+
</script>
16+
17+
<script>
18+
// eslint-disable-next-line no-unused-vars
19+
let gotMsg = false;
20+
let console = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
21+
let listener = {
22+
QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]),
23+
observe(msg) {
24+
info("console message:" + msg);
25+
ok(msg.logLevel == Ci.nsIConsoleMessage.warn, "log level should be 'warn'.");
26+
console.unregisterListener(this);
27+
gotMsg = true;
28+
}
29+
};
30+
console.registerListener(listener);
31+
</script>
32+
33+
<script type="importmap" onerror='importMapError()'>
34+
{
35+
"imports": {
36+
"./module_simpleExport.mjs": "./scope1/module_simpleExport.mjs"
37+
}
38+
}
39+
</script>
40+
41+
<script>
42+
/* global gotMsg */
43+
SimpleTest.waitForExplicitFinish();
44+
45+
let hasError = false;
46+
// eslint-disable-next-line no-unused-vars
47+
function importMapError() {
48+
hasError = true;
49+
}
50+
51+
// eslint-disable-next-line no-unused-vars
52+
function testLoaded() {
53+
import("./module_simpleExport.mjs").then((ns) => {
54+
ok(ns.x == 42, 'Check simple imported value result: ' + ns.x);
55+
ok(!hasError, "onerror of the import map shouldn't be called.");
56+
ok(gotMsg, "Should have got the console warning.");
57+
}).catch((e) => {
58+
ok(false, "throws " + e);
59+
}).then(() => {
60+
SimpleTest.finish();
61+
});
62+
}
63+
</script>
64+
</body>

0 commit comments

Comments
 (0)