diff --git a/js/xpconnect/tests/unit/test_xpcomutils.js b/js/xpconnect/tests/unit/test_xpcomutils.js index ff11b60de70e..6aa73cb67025 100644 --- a/js/xpconnect/tests/unit/test_xpcomutils.js +++ b/js/xpconnect/tests/unit/test_xpcomutils.js @@ -156,7 +156,7 @@ add_test(function test_categoryRegistration() const XULAPPINFO_CID = Components.ID("{fc937916-656b-4fb3-a395-8c63569e27a8}"); // Create a fake app entry for our category registration apps filter. - let { newAppInfo } = ChromeUtils.import("resource://testing-common/AppInfo.jsm"); + let { newAppInfo } = ChromeUtils.importESModule("resource://testing-common/AppInfo.sys.mjs"); let XULAppInfo = newAppInfo({ name: "catRegTest", ID: "{adb42a9a-0d19-4849-bf4d-627614ca19be}", diff --git a/layout/tools/reftest/jar.mn b/layout/tools/reftest/jar.mn index a2ed6f8b226d..2d6ea891e2a5 100644 --- a/layout/tools/reftest/jar.mn +++ b/layout/tools/reftest/jar.mn @@ -53,7 +53,7 @@ reftest.jar: res/ReftestFissionChild.jsm (ReftestFissionChild.jsm) res/AsyncSpellCheckTestHelper.jsm (../../../editor/AsyncSpellCheckTestHelper.jsm) res/httpd.jsm (../../../netwerk/test/httpserver/httpd.js) - res/StructuredLog.jsm (../../../testing/modules/StructuredLog.jsm) + res/StructuredLog.sys.mjs (../../../testing/modules/StructuredLog.sys.mjs) res/PerTestCoverageUtils.jsm (../../../tools/code-coverage/PerTestCoverageUtils.jsm) res/input.css (../../../editor/reftests/xul/input.css) res/progress.css (../../../layout/reftests/forms/progress/style.css) diff --git a/layout/tools/reftest/reftest.jsm b/layout/tools/reftest/reftest.jsm index 9727a1501e43..90c49a1bacc9 100644 --- a/layout/tools/reftest/reftest.jsm +++ b/layout/tools/reftest/reftest.jsm @@ -48,8 +48,8 @@ const { HttpServer } = ChromeUtils.import("resource://reftest/httpd.jsm"); const { ReadTopManifest, CreateUrls } = ChromeUtils.import( "resource://reftest/manifest.jsm" ); -const { StructuredLogger } = ChromeUtils.import( - "resource://reftest/StructuredLog.jsm" +const { StructuredLogger } = ChromeUtils.importESModule( + "resource://reftest/StructuredLog.sys.mjs" ); const { PerTestCoverageUtils } = ChromeUtils.import( "resource://reftest/PerTestCoverageUtils.jsm" diff --git a/testing/mochitest/moz.build b/testing/mochitest/moz.build index 3251059fa0e8..edae41386eb3 100644 --- a/testing/mochitest/moz.build +++ b/testing/mochitest/moz.build @@ -45,7 +45,7 @@ FINAL_TARGET_FILES.content.static += [ FINAL_TARGET_FILES.content.tests.SimpleTest += [ "../../docshell/test/chrome/docshell_helpers.js", - "../modules/StructuredLog.jsm", + "../modules/StructuredLog.sys.mjs", "tests/SimpleTest/AccessibilityUtils.js", "tests/SimpleTest/EventUtils.js", "tests/SimpleTest/ExtensionTestUtils.js", diff --git a/testing/mochitest/server.js b/testing/mochitest/server.js index 7bcffb7e133c..e8e514d34497 100644 --- a/testing/mochitest/server.js +++ b/testing/mochitest/server.js @@ -766,10 +766,6 @@ function testListing(metadata, response) { type: "text/css", href: "/static/harness.css", }), - SCRIPT({ - type: "text/javascript", - src: "/tests/SimpleTest/StructuredLog.jsm", - }), SCRIPT({ type: "text/javascript", src: "/tests/SimpleTest/LogController.js", diff --git a/testing/mochitest/tests/SimpleTest/TestRunner.js b/testing/mochitest/tests/SimpleTest/TestRunner.js index 400698444a74..2c67b4673b7a 100644 --- a/testing/mochitest/tests/SimpleTest/TestRunner.js +++ b/testing/mochitest/tests/SimpleTest/TestRunner.js @@ -7,7 +7,6 @@ */ // This file expects the following files to be loaded. -/* import-globals-from ../../../modules/StructuredLog.jsm */ /* import-globals-from LogController.js */ /* import-globals-from MemoryStats.js */ /* import-globals-from MozillaLogger.js */ @@ -16,6 +15,13 @@ "use strict"; +const { + StructuredLogger, + StructuredFormatter, +} = SpecialPowers.ChromeUtils.importESModule( + "resource://testing-common/StructuredLog.sys.mjs" +); + function getElement(id) { return typeof id == "string" ? document.getElementById(id) : id; } @@ -337,7 +343,9 @@ TestRunner._dumpMessage = function(message) { // From https://searchfox.org/mozilla-central/source/testing/modules/StructuredLog.jsm TestRunner.structuredLogger = new StructuredLogger( "mochitest", - TestRunner._dumpMessage + TestRunner._dumpMessage, + [], + TestRunner ); TestRunner.structuredLogger.deactivateBuffering = function() { TestRunner.structuredLogger.logData("buffering_off"); diff --git a/testing/modules/StructuredLog.jsm b/testing/modules/StructuredLog.sys.mjs similarity index 92% rename from testing/modules/StructuredLog.jsm rename to testing/modules/StructuredLog.sys.mjs index e92bb0e3a675..a4524841a380 100644 --- a/testing/modules/StructuredLog.jsm +++ b/testing/modules/StructuredLog.sys.mjs @@ -2,27 +2,28 @@ * 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/. */ -"use strict"; - -var EXPORTED_SYMBOLS = ["StructuredLogger", "StructuredFormatter"]; - /** * TestLogger: Logger class generating messages compliant with the * structured logging protocol for tests exposed by mozlog * - * @param name + * @param {string} name * The name of the logger to instantiate. - * @param dumpFun + * @param {function} [dumpFun] * An underlying function to be used to log raw messages. This function * will receive the complete serialized json string to log. + * @param {object} [scope] + * The scope that the dumpFun is loaded in, so that messages are cloned + * into that scope before passing them. */ -class StructuredLogger { +export class StructuredLogger { name = null; #dumpFun = null; + #dumpScope = null; - constructor(name, dumpFun = dump) { + constructor(name, dumpFun = dump, scope = null) { this.name = name; this.#dumpFun = dumpFun; + this.#dumpScope = scope; } testStart(test) { @@ -210,7 +211,11 @@ class StructuredLogger { allData[field] = data[field]; } - this.#dumpFun(allData); + if (this.#dumpScope) { + this.#dumpFun(Cu.cloneInto(allData, this.#dumpScope)); + } else { + this.#dumpFun(allData); + } } #testId(test) { @@ -225,7 +230,7 @@ class StructuredLogger { * StructuredFormatter: Formatter class turning structured messages * into human-readable messages. */ -class StructuredFormatter { +export class StructuredFormatter { // The time at which the whole suite of tests started. #suiteStartTime = null; diff --git a/testing/modules/moz.build b/testing/modules/moz.build index 9326347a3fe5..d201d9dd524c 100644 --- a/testing/modules/moz.build +++ b/testing/modules/moz.build @@ -16,7 +16,7 @@ TESTING_JS_MODULES += [ "MockRegistrar.sys.mjs", "sinon-7.2.7.js", "Sinon.jsm", - "StructuredLog.jsm", + "StructuredLog.sys.mjs", "TestUtils.sys.mjs", "XPCShellContentUtils.sys.mjs", ] @@ -27,7 +27,7 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows": ] -TEST_HARNESS_FILES.testing.mochitest.tests.SimpleTest += ["StructuredLog.jsm"] +TEST_HARNESS_FILES.testing.mochitest.tests.SimpleTest += ["StructuredLog.sys.mjs"] with Files("**"): BUG_COMPONENT = ("Testing", "General") diff --git a/testing/modules/tests/xpcshell/test_structuredlog.js b/testing/modules/tests/xpcshell/test_structuredlog.js index f615d722080a..3802fcc0980e 100644 --- a/testing/modules/tests/xpcshell/test_structuredlog.js +++ b/testing/modules/tests/xpcshell/test_structuredlog.js @@ -2,8 +2,8 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function run_test() { - const { StructuredLogger } = ChromeUtils.import( - "resource://testing-common/StructuredLog.jsm" + const { StructuredLogger } = ChromeUtils.importESModule( + "resource://testing-common/StructuredLog.sys.mjs" ); let testBuffer = []; diff --git a/testing/xpcshell/head.js b/testing/xpcshell/head.js index b458d937876a..646c036badf1 100644 --- a/testing/xpcshell/head.js +++ b/testing/xpcshell/head.js @@ -90,8 +90,8 @@ var _dumpLog = function(raw_msg) { dump("\n" + JSON.stringify(raw_msg) + "\n"); }; -var { StructuredLogger: _LoggerClass } = ChromeUtils.import( - "resource://testing-common/StructuredLog.jsm" +var { StructuredLogger: _LoggerClass } = ChromeUtils.importESModule( + "resource://testing-common/StructuredLog.sys.mjs" ); var _testLogger = new _LoggerClass("xpcshell/head.js", _dumpLog, [_add_params]); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_startupCache.js b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_startupCache.js index acea225a31b7..4b35e9153272 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_startupCache.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_startupCache.js @@ -15,8 +15,8 @@ AddonTestUtils.createAppInfo( const { ExtensionScriptingStore } = ChromeUtils.import( "resource://gre/modules/ExtensionScriptingStore.jsm" ); -const { TestUtils } = ChromeUtils.import( - "resource://testing-common/TestUtils.jsm" +const { TestUtils } = ChromeUtils.importESModule( + "resource://testing-common/TestUtils.sys.mjs" ); const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");