Bug 1801368 - Migrate StructuredLog.jsm to an ES module. r=ahal

Depends on D162490

Differential Revision: https://phabricator.services.mozilla.com/D162491
This commit is contained in:
Mark Banner 2022-11-24 16:17:47 +00:00
parent 55d53c8bb7
commit 4a8185fb14
11 changed files with 38 additions and 29 deletions

View File

@ -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}",

View File

@ -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)

View File

@ -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"

View File

@ -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",

View File

@ -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",

View File

@ -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");

View File

@ -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;

View File

@ -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")

View File

@ -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 = [];

View File

@ -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]);

View File

@ -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");