Bug 1799314 - Convert consumers of testing modules to import ES modules direct (testing/). r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D161908
This commit is contained in:
Mark Banner 2022-11-17 12:00:28 +00:00
parent e9d9a68cc8
commit 02375d923e
23 changed files with 80 additions and 107 deletions

View file

@ -223,7 +223,7 @@ test log.
In addition to mochitest assertions, mochitest supports the
[CommonJS standard assertions](http://wiki.commonjs.org/wiki/Unit_Testing/1.1),
like [nodejs' assert module](https://nodejs.org/api/assert.html#assert) but
implemented in `Assert.jsm`. These are auto-imported in the browser flavor, but
implemented in `Assert.sys.mjs`. These are auto-imported in the browser flavor, but
need to be imported manually in other flavors.
### Helper functions

View file

@ -80,9 +80,9 @@ xpcshell Testing API
xpcshell tests have access to the following functions. They are defined
in
`testing/xpcshell/head.js <https://searchfox.org/mozilla-central/source/testing/xpcshell/head.js>`__
:searchfox:`testing/xpcshell/head.js <testing/xpcshell/head.js>`
and
`testing/modules/Assert.jsm <https://searchfox.org/mozilla-central/source/testing/modules/Assert.jsm>`__.
:searchfox:`testing/modules/Assert.sys.mjs <testing/modules/Assert.sys.mjs>`.
Assertions
^^^^^^^^^^
@ -102,7 +102,7 @@ Assertions
These assertion methods are provided by
`Assert.jsm </en/docs/Mozilla/JavaScript_code_modules/Assert.jsm>`__.
:searchfox:`testing/modules/Assert.sys.mjs <testing/modules/Assert.sys.mjs>`.
It implements the `CommonJS Unit Testing specification version
1.1 <http://wiki.commonjs.org/wiki/Unit_Testing/1.1>`__, which
provides a basic, standardized interface for performing in-code

View file

@ -19,15 +19,16 @@ const { ComponentUtils } = ChromeUtils.import(
"resource://gre/modules/ComponentUtils.jsm"
);
const { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);
import { TestUtils } from "resource://testing-common/TestUtils.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
ContentTask: "resource://testing-common/ContentTask.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
ContentTask: "resource://testing-common/ContentTask.jsm",
});
XPCOMUtils.defineLazyServiceGetters(lazy, {
@ -501,7 +502,7 @@ export var BrowserTestUtils = {
return;
}
// See testing/mochitest/BrowserTestUtils/content/BrowserTestUtilsChild.jsm
// See testing/mochitest/BrowserTestUtils/content/BrowserTestUtilsChild.sys.mjs
// for the difference between visibleURL and internalURL.
if (!isWanted(maybeErrorPage ? visibleURL : internalURL)) {
return;
@ -1476,7 +1477,7 @@ export var BrowserTestUtils = {
/**
* This is an internal method to be invoked by
* BrowserTestUtilsParent.jsm when a content event we were listening for
* BrowserTestUtilsParent.sys.mjs when a content event we were listening for
* happens.
*
* @private

View file

@ -3,9 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { BrowserTestUtils } = ChromeUtils.import(
"resource://testing-common/BrowserTestUtils.jsm"
);
import { BrowserTestUtils } from "resource://testing-common/BrowserTestUtils.sys.mjs";
export class ContentEventListenerParent extends JSWindowActorParent {
receiveMessage(aMessage) {

View file

@ -6,11 +6,11 @@
"use strict";
let { ContentTaskUtils } = ChromeUtils.import(
"resource://testing-common/ContentTaskUtils.jsm"
let { ContentTaskUtils } = ChromeUtils.importESModule(
"resource://testing-common/ContentTaskUtils.sys.mjs"
);
const { Assert: AssertCls } = ChromeUtils.import(
"resource://testing-common/Assert.jsm"
const { Assert: AssertCls } = ChromeUtils.importESModule(
"resource://testing-common/Assert.sys.mjs"
);
const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"

View file

@ -136,7 +136,9 @@ function testInit() {
);
} else {
// In non-e10s, only run the ShutdownLeaksCollector in the parent process.
ChromeUtils.import("chrome://mochikit/content/ShutdownLeaksCollector.jsm");
ChromeUtils.importESModule(
"chrome://mochikit/content/ShutdownLeaksCollector.sys.mjs"
);
}
}
@ -203,20 +205,20 @@ function Tester(aTests, structuredLogger, aCallback) {
this.SimpleTest.harnessParameters = gConfig;
this.MemoryStats = simpleTestScope.MemoryStats;
this.ContentTask = ChromeUtils.import(
"resource://testing-common/ContentTask.jsm"
this.ContentTask = ChromeUtils.importESModule(
"resource://testing-common/ContentTask.sys.mjs"
).ContentTask;
this.BrowserTestUtils = ChromeUtils.import(
"resource://testing-common/BrowserTestUtils.jsm"
this.BrowserTestUtils = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
).BrowserTestUtils;
this.TestUtils = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
this.TestUtils = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
).TestUtils;
this.PromiseTestUtils = ChromeUtils.importESModule(
"resource://testing-common/PromiseTestUtils.sys.mjs"
).PromiseTestUtils;
this.Assert = ChromeUtils.import(
"resource://testing-common/Assert.jsm"
this.Assert = ChromeUtils.importESModule(
"resource://testing-common/Assert.sys.mjs"
).Assert;
this.PerTestCoverageUtils = ChromeUtils.import(
"resource://testing-common/PerTestCoverageUtils.jsm"
@ -320,8 +322,8 @@ Tester.prototype = {
if (gConfig.jscovDirPrefix) {
let coveragePath = gConfig.jscovDirPrefix;
let { CoverageCollector } = ChromeUtils.import(
"resource://testing-common/CoverageUtils.jsm"
let { CoverageCollector } = ChromeUtils.importESModule(
"resource://testing-common/CoverageUtils.sys.mjs"
);
this._coverageCollector = new CoverageCollector(coveragePath);
}
@ -1183,7 +1185,7 @@ Tester.prototype = {
this.ContentTask.setTestScope(currentScope);
// Allow Assert.jsm methods to be tacked to the current scope.
// Allow Assert.sys.mjs methods to be tacked to the current scope.
scope.export_assertions = function() {
for (let func in this.Assert) {
this[func] = this.Assert[func].bind(this.Assert);

View file

@ -6,4 +6,6 @@
// We run this code in a .jsm rather than here to avoid keeping the current
// compartment alive.
ChromeUtils.import("chrome://mochikit/content/ShutdownLeaksCollector.jsm");
ChromeUtils.importESModule(
"chrome://mochikit/content/ShutdownLeaksCollector.sys.mjs"
);

View file

@ -57,7 +57,7 @@ add_task(async function() {
// Test that a representative variety of assertions work as expected, and
// trigger the expected calls to the harness's reporting function.
//
// Note: Assert.jsm has its own tests, and defers all of its reporting to a
// Note: Assert.sys.mjs has its own tests, and defers all of its reporting to a
// single reporting function, so we don't need to test it comprehensively. We
// just need to make sure that the general functionality works as expected.
let tests = {

View file

@ -11,8 +11,8 @@ function ChromeTask_ChromeScript() {
"use strict";
const { Assert: AssertCls } = ChromeUtils.import(
"resource://testing-common/Assert.jsm"
const { Assert: AssertCls } = ChromeUtils.importESModule(
"resource://testing-common/Assert.sys.mjs"
);
addMessageListener("chrome-task:spawn", async function(aData) {

View file

@ -499,8 +499,8 @@ TestRunner.runTests = function(/*url...*/) {
// Initialize code coverage
if (TestRunner.jscovDirPrefix != "") {
var { CoverageCollector } = SpecialPowers.ChromeUtils.import(
"resource://testing-common/CoverageUtils.jsm"
var { CoverageCollector } = SpecialPowers.ChromeUtils.importESModule(
"resource://testing-common/CoverageUtils.sys.mjs"
);
coverageCollector = new CoverageCollector(TestRunner.jscovDirPrefix);
}

View file

@ -10,7 +10,7 @@ import { DownloadPaths } from "resource://gre/modules/DownloadPaths.sys.mjs";
import { FileUtils } from "resource://gre/modules/FileUtils.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
import { Assert } from "resource://testing-common/Assert.sys.mjs";
let gFileCounter = 1;
let gPathsToRemove = [];

View file

@ -2,9 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { MockRegistrar } = ChromeUtils.import(
"resource://testing-common/MockRegistrar.jsm"
);
import { MockRegistrar } from "resource://testing-common/MockRegistrar.sys.mjs";
export class MockRegistry {
constructor() {

View file

@ -8,9 +8,9 @@
* observer notification.
*
* More complex functions are likely to belong to a separate test-only module.
* Examples include Assert.jsm for generic assertions, FileTestUtils.jsm to work
* with local files and their contents, and BrowserTestUtils.jsm to work with
* browser windows and tabs.
* Examples include Assert.sys.mjs for generic assertions, FileTestUtils.sys.mjs
* to work with local files and their contents, and BrowserTestUtils.sys.mjs to
* work with browser windows and tabs.
*
* Individual components also offer testing functions to other components, for
* example LoginTestUtils.jsm.

View file

@ -18,11 +18,14 @@ ChromeUtils.importESModule("resource://gre/modules/ActorManagerParent.sys.mjs");
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
ContentTask: "resource://testing-common/ContentTask.sys.mjs",
TestUtils: "resource://testing-common/TestUtils.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
ContentTask: "resource://testing-common/ContentTask.jsm",
HttpServer: "resource://testing-common/httpd.js",
MessageChannel: "resource://testing-common/MessageChannel.jsm",
TestUtils: "resource://testing-common/TestUtils.jsm",
});
XPCOMUtils.defineLazyServiceGetters(lazy, {

View file

@ -5,7 +5,9 @@
// https://github.com/joyent/node/blob/6101eb184db77d0b11eb96e48744e57ecce4b73d/test/simple/test-assert.js
// MIT license: http://opensource.org/licenses/MIT
var { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
var { Assert } = ChromeUtils.importESModule(
"resource://testing-common/Assert.sys.mjs"
);
function run_test() {
let assert = new Assert();

View file

@ -1,8 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const { MockRegistrar } = ChromeUtils.import(
"resource://testing-common/MockRegistrar.jsm"
const { MockRegistrar } = ChromeUtils.importESModule(
"resource://testing-common/MockRegistrar.sys.mjs"
);
function platformInfo(injectedValue) {

View file

@ -4,11 +4,9 @@
const lazy = {};
ChromeUtils.defineModuleGetter(
lazy,
"WrapPrivileged",
"resource://specialpowers/WrapPrivileged.jsm"
);
ChromeUtils.defineESModuleGetters(lazy, {
WrapPrivileged: "resource://specialpowers/WrapPrivileged.sys.mjs",
});
const Cm = Components.manager;
@ -110,7 +108,7 @@ MockColorPickerInstance.prototype = {
}
} catch (ex) {
dump(
"TEST-UNEXPECTED-FAIL | Exception in MockColorPicker.jsm open() " +
"TEST-UNEXPECTED-FAIL | Exception in MockColorPicker.sys.mjs open() " +
"method: " +
ex +
"\n"

View file

@ -4,20 +4,15 @@
const lazy = {};
ChromeUtils.defineModuleGetter(
lazy,
"WrapPrivileged",
"resource://specialpowers/WrapPrivileged.jsm"
);
ChromeUtils.defineESModuleGetters(lazy, {
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
WrapPrivileged: "resource://specialpowers/WrapPrivileged.sys.mjs",
});
const Cm = Components.manager;
const CONTRACT_ID = "@mozilla.org/filepicker;1";
ChromeUtils.defineESModuleGetters(lazy, {
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
});
if (import.meta.url.includes("specialpowers")) {
Cu.crashIfNotInAutomation();
}

View file

@ -10,33 +10,14 @@ const { ExtensionUtils } = ChromeUtils.import(
const lazy = {};
ChromeUtils.defineModuleGetter(
lazy,
"MockFilePicker",
"resource://specialpowers/MockFilePicker.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"MockColorPicker",
"resource://specialpowers/MockColorPicker.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"MockPermissionPrompt",
"resource://specialpowers/MockPermissionPrompt.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"SpecialPowersSandbox",
"resource://specialpowers/SpecialPowersSandbox.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"WrapPrivileged",
"resource://specialpowers/WrapPrivileged.jsm"
);
ChromeUtils.defineESModuleGetters(lazy, {
ContentTaskUtils: "resource://testing-common/ContentTaskUtils.sys.mjs",
MockColorPicker: "resource://specialpowers/MockColorPicker.sys.mjs",
MockFilePicker: "resource://specialpowers/MockFilePicker.sys.mjs",
MockPermissionPrompt: "resource://specialpowers/MockPermissionPrompt.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
SpecialPowersSandbox: "resource://specialpowers/SpecialPowersSandbox.sys.mjs",
WrapPrivileged: "resource://specialpowers/WrapPrivileged.sys.mjs",
});
ChromeUtils.defineModuleGetter(
lazy,
@ -50,11 +31,6 @@ ChromeUtils.defineModuleGetter(
"PerTestCoverageUtils",
"resource://testing-common/PerTestCoverageUtils.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"ContentTaskUtils",
"resource://testing-common/ContentTaskUtils.jsm"
);
Cu.crashIfNotInAutomation();
@ -1530,7 +1506,7 @@ export class SpecialPowersChild extends JSWindowActorChild {
* value.
*
* The sandbox also has access to an Assert object, as provided by
* Assert.jsm. Any assertion methods called before the task resolves
* Assert.sys.mjs. Any assertion methods called before the task resolves
* will be relayed back to the test environment of the caller.
*
* @param {BrowsingContext or FrameLoaderOwner or WindowProxy} target

View file

@ -9,6 +9,7 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
HiddenFrame: "resource://gre/modules/HiddenFrame.sys.mjs",
SpecialPowersSandbox: "resource://specialpowers/SpecialPowersSandbox.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
@ -16,7 +17,6 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
ExtensionTestCommon: "resource://testing-common/ExtensionTestCommon.jsm",
PerTestCoverageUtils: "resource://testing-common/PerTestCoverageUtils.jsm",
ServiceWorkerCleanUp: "resource://gre/modules/ServiceWorkerCleanUp.jsm",
SpecialPowersSandbox: "resource://specialpowers/SpecialPowersSandbox.jsm",
});
class SpecialPowersError extends Error {

View file

@ -12,11 +12,9 @@
const lazy = {};
ChromeUtils.defineModuleGetter(
lazy,
"Assert",
"resource://testing-common/Assert.jsm"
);
ChromeUtils.defineESModuleGetters(lazy, {
Assert: "resource://testing-common/Assert.sys.mjs",
});
// Note: When updating the set of globals exposed to sandboxes by
// default, please also update the ESLint plugin rule defined in

View file

@ -6,7 +6,7 @@
/**
* Ensures that tests can import a module in the same folder through:
* ChromeUtils.import("resource://test/module.jsm");
* ChromeUtils.importESModule("resource://test/module.jsm");
*/
function run_test() {

View file

@ -62,9 +62,9 @@ let { XPCOMUtils: _XPCOMUtils } = ChromeUtils.importESModule(
let { OS: _OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
// Support a common assertion library, Assert.jsm.
var { Assert: AssertCls } = ChromeUtils.import(
"resource://testing-common/Assert.jsm"
// Support a common assertion library, Assert.sys.mjs.
var { Assert: AssertCls } = ChromeUtils.importESModule(
"resource://testing-common/Assert.sys.mjs"
);
// Pass a custom report function for xpcshell-test style reporting.
@ -76,7 +76,7 @@ var Assert = new AssertCls(function(err, message, stack) {
}
}, true);
// Bug 1506134 for followup. Some xpcshell tests use ContentTask.jsm, which
// Bug 1506134 for followup. Some xpcshell tests use ContentTask.sys.mjs, which
// expects browser-test.js to have set a testScope that includes record.
function record(condition, name, diag, stack) {
do_report_result(condition, name, stack);
@ -555,8 +555,8 @@ function _execute_test() {
let coverageCollector = null;
if (typeof _JSCOV_DIR === "string") {
let _CoverageCollector = ChromeUtils.import(
"resource://testing-common/CoverageUtils.jsm"
let _CoverageCollector = ChromeUtils.importESModule(
"resource://testing-common/CoverageUtils.sys.mjs"
).CoverageCollector;
coverageCollector = new _CoverageCollector(_JSCOV_DIR);
}
@ -568,7 +568,7 @@ function _execute_test() {
// _TEST_FILE is dynamically defined by <runxpcshelltests.py>.
_load_files(_TEST_FILE);
// Tack Assert.jsm methods to the current scope.
// Tack Assert.sys.mjs methods to the current scope.
this.Assert = Assert;
for (let func in Assert) {
this[func] = Assert[func].bind(Assert);