mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1778089 - Part 3: Add more test for ChromeUtils.importESModule. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D151713
This commit is contained in:
parent
a3e74dae81
commit
ae941f81cb
4
js/xpconnect/tests/unit/es6module_absolute.js
Normal file
4
js/xpconnect/tests/unit/es6module_absolute.js
Normal file
@ -0,0 +1,4 @@
|
||||
import { x as x1 } from "resource://test/es6module_absolute2.js";
|
||||
import { x as x2 } from "./es6module_absolute2.js";
|
||||
export const absoluteX = x1;
|
||||
export const relativeX = x2;
|
1
js/xpconnect/tests/unit/es6module_absolute2.js
Normal file
1
js/xpconnect/tests/unit/es6module_absolute2.js
Normal file
@ -0,0 +1 @@
|
||||
export const x = { value: 10 };
|
7
js/xpconnect/tests/unit/es6module_dynamic_import.js
Normal file
7
js/xpconnect/tests/unit/es6module_dynamic_import.js
Normal file
@ -0,0 +1,7 @@
|
||||
let resolve;
|
||||
|
||||
export const result = new Promise(r => { resolve = r; });
|
||||
|
||||
import("./es6module_dynamic_import2.js").then(ns => {}, e => {
|
||||
resolve(e);
|
||||
});
|
1
js/xpconnect/tests/unit/es6module_dynamic_import2.js
Normal file
1
js/xpconnect/tests/unit/es6module_dynamic_import2.js
Normal file
@ -0,0 +1 @@
|
||||
export const x = 10;
|
1
js/xpconnect/tests/unit/es6module_import_error.js
Normal file
1
js/xpconnect/tests/unit/es6module_import_error.js
Normal file
@ -0,0 +1 @@
|
||||
import { y } from "./es6module_import_error2.js";
|
1
js/xpconnect/tests/unit/es6module_import_error2.js
Normal file
1
js/xpconnect/tests/unit/es6module_import_error2.js
Normal file
@ -0,0 +1 @@
|
||||
export const x = 10;
|
@ -1,7 +1,7 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
add_task(async function() {
|
||||
// Test basic import.
|
||||
let ns = ChromeUtils.importESModule("resource://test/es6module.js");
|
||||
Assert.equal(ns.loadCount, 1);
|
||||
@ -12,6 +12,12 @@ function run_test() {
|
||||
Assert.equal(ns.loadCount, 1);
|
||||
Assert.equal(ns, ns2);
|
||||
|
||||
// Test imports with absolute and relative URIs return the same thing.
|
||||
let ns3 = ChromeUtils.importESModule("resource://test/es6module_absolute.js");
|
||||
let ns4 = ChromeUtils.importESModule("resource://test/es6module_absolute2.js");
|
||||
Assert.ok(ns3.absoluteX === ns3.relativeX);
|
||||
Assert.ok(ns3.absoluteX === ns4.x);
|
||||
|
||||
// Test load failure.
|
||||
testFailure("resource://test/es6module_not_found.js", {
|
||||
type: "Error",
|
||||
@ -50,6 +56,14 @@ function run_test() {
|
||||
columnNumber: 5,
|
||||
});
|
||||
|
||||
// Test import error.
|
||||
testFailure("resource://test/es6module_import_error.js", {
|
||||
type: "SyntaxError",
|
||||
fileName: "resource://test/es6module_import_error.js",
|
||||
lineNumber: 1,
|
||||
columnNumber: 9,
|
||||
});
|
||||
|
||||
// Test execution failure.
|
||||
let exception1 = testFailure("resource://test/es6module_throws.js", {
|
||||
type: "Error",
|
||||
@ -91,7 +105,18 @@ function run_test() {
|
||||
lineNumber: 1,
|
||||
columnNumber: 0,
|
||||
});
|
||||
}
|
||||
|
||||
// Test dynamic import is not supported.
|
||||
ns = ChromeUtils.importESModule("resource://test/es6module_dynamic_import.js");
|
||||
const e = await ns.result;
|
||||
checkException(e, {
|
||||
type: "Error",
|
||||
message: "not supported",
|
||||
fileName: "resource://test/es6module_dynamic_import.js",
|
||||
lineNumber: 5,
|
||||
columnNumber: 1,
|
||||
});
|
||||
});
|
||||
|
||||
function testFailure(url, expected) {
|
||||
let threw = false;
|
||||
@ -110,8 +135,14 @@ function testFailure(url, expected) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
Assert.ok(threw);
|
||||
Assert.ok(threw, "Error should be thrown");
|
||||
|
||||
checkException(exception, expected, importLine, importColumn);
|
||||
|
||||
return exception;
|
||||
}
|
||||
|
||||
function checkException(exception, expected, importLine, importColumn) {
|
||||
if ("type" in expected) {
|
||||
Assert.equal(exception.constructor.name, expected.type, "error type");
|
||||
}
|
||||
@ -141,6 +172,4 @@ function testFailure(url, expected) {
|
||||
}
|
||||
Assert.equal(exception.columnNumber, expectedColumn, "columnNumber");
|
||||
}
|
||||
|
||||
return exception;
|
||||
}
|
||||
|
@ -47,6 +47,12 @@ support-files =
|
||||
api_script.js
|
||||
import_stack.jsm
|
||||
import_stack.sys.mjs
|
||||
es6module_import_error.js
|
||||
es6module_import_error2.js
|
||||
es6module_dynamic_import.js
|
||||
es6module_dynamic_import2.js
|
||||
es6module_absolute.js
|
||||
es6module_absolute2.js
|
||||
|
||||
[test_allowWaivers.js]
|
||||
[test_bogus_files.js]
|
||||
|
Loading…
Reference in New Issue
Block a user