From 6477267d4f5a7d61278aed20c86549399295d98f Mon Sep 17 00:00:00 2001 From: iulian moraru Date: Sat, 10 May 2025 00:29:08 +0300 Subject: [PATCH] Revert "Bug 1957513 - for causing xpcshell failures on test_bug1312782_http1.js" This reverts commit 3e492ab9fe2d042ae64de6206b3f3fb7f476d395. --- testing/mochitest/browser-test.js | 8 - .../mochitest/tests/SimpleTest/SimpleTest.js | 8 - testing/modules/Mochia.js | 259 ------------------ testing/modules/moz.build | 1 - testing/xpcshell/head.js | 8 - .../lib/configs/browser-test.js | 4 - .../lib/configs/chrome-test.js | 4 - .../lib/configs/xpcshell-test.js | 7 - 8 files changed, 299 deletions(-) delete mode 100644 testing/modules/Mochia.js diff --git a/testing/mochitest/browser-test.js b/testing/mochitest/browser-test.js index bc43710df78e..ef29179988bb 100644 --- a/testing/mochitest/browser-test.js +++ b/testing/mochitest/browser-test.js @@ -1936,11 +1936,3 @@ testScope.prototype = { } }, }; - -/* import-globals-from ../modules/Mochia.js */ -Services.scriptloader.loadSubScript( - "resource://testing-common/Mochia.js", - this -); - -Mochia(testScope); diff --git a/testing/mochitest/tests/SimpleTest/SimpleTest.js b/testing/mochitest/tests/SimpleTest/SimpleTest.js index e02aff12a1a4..94760a888e0a 100644 --- a/testing/mochitest/tests/SimpleTest/SimpleTest.js +++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js @@ -2262,11 +2262,3 @@ addEventListener("message", async event => { SimpleTest.finish(); } }); - -/* import-globals-from ../../../modules/Mochia.js */ -SpecialPowers.Services.scriptloader.loadSubScript( - "resource://testing-common/Mochia.js", - this -); - -Mochia(this); diff --git a/testing/modules/Mochia.js b/testing/modules/Mochia.js deleted file mode 100644 index 2c3e06f5f3bf..000000000000 --- a/testing/modules/Mochia.js +++ /dev/null @@ -1,259 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/** - * Define Mochia's helpers on the given scope. - * - * @param {object} scope - * The `globalThis` of the running test, where `add_task` is defined. - */ -const Mochia = (function () { - /** - * The context of each test suite. - */ - class Context { - static #stack = []; - - static current() { - return Context.#stack.at(-1); - } - - static push(ctx) { - Context.#stack.push(ctx); - } - - static pop() { - Context.#stack.pop(); - } - - constructor() { - this.description = []; - this.beforeEach = []; - this.afterEach = []; - } - - clone() { - const newCtx = new Context(); - newCtx.description.push(...this.description); - newCtx.beforeEach.push(...this.beforeEach); - newCtx.afterEach.push(...this.afterEach); - return newCtx; - } - } - - Context.push(new Context()); - - let _testScope = null; - - /** - * @typedef {void|Promise} MaybePromise - * - * Either undefined or a Promise that resolves to undefined. - */ - - const MochiaImpl = { - /** - * Describe a new test suite, which is a scoped environment for running setup - * and teardown. - * - * @param {string} desc - * A description of the test suite. - * - * @param {function(): MaybePromise} suite - * The test suite - */ - async describe(desc, suite) { - const ctx = Context.current().clone(); - ctx.description.push(desc); - - Context.push(ctx); - - const p = suite(); - if (p?.then) { - await p; - } - - Context.pop(); - }, - - /** - * Register a setup funciton to run before each test. - * - * Multiple functions can be registered with `beforeEach` and they will be run - * in order before each test in the suite and the suites nested inside of it. - * - * @param {function(): MaybePromise} setupFn - * The setup function. If this function returns a `Promise` it will be - * awaited. - */ - beforeEach(setupFn) { - Context.current().beforeEach.push(setupFn); - }, - - /** - * Register a tear down function to run at the end of each test. - * - * Multiple functions can be registered with `afterEach` and they will run in - * reverse order after each test in the suite and the suites nested inside of it. - * - * @param {function(): MaybePromise} tearDownFn - * The tear down function. If this function returns a `Promise` it will - * be awaited. - */ - afterEach(tearDownFn) { - Context.current().afterEach.push(tearDownFn); - }, - - /** - * Register a test function. - * - * The test will be registered via `add_task`. Each setup function registered - * before this function call will be called in order before the actual test - * and each teardown function before this function will be called in reverse - * order after the actual test. - * - * @param {string} desc - * A description of the test. This is logged at the start of the test. - * - * @param {function(): MaybePromise} testFn - * The test function. If this function returns a `Promise` it will be - * awaited. - * - * @returns {any} - * The result of calling `add_task` with the wrapped function. - */ - it(desc, testFn) { - return _testScope.add_task(MochiaImpl.wrap(desc, testFn)); - }, - - /** - * Register a test that will be the only test run. - * - * @param {string} desc - * A description of the test. This is logged at the start of the test. - * - * @param {function(): MaybePromise} testFn - * The test function. If this function returns a `Promise` it will be - * awaited. - */ - only(desc, testFn) { - MochiaImpl.it(desc, testFn).only(); - }, - - /** - * Register a test that will be skipped. - * - * @param {string} desc - * A description of the test. This is logged at the start of the test. - * - * @param {function(): MaybePromise} testFn - * The test function. If this function returns a `Promise` it will be - * awaited. - */ - skip(desc, testFn) { - MochiaImpl.it(desc, testFn).skip(); - }, - - /** - * Register a test that will be skipped if the provided predicate evaluates to - * a truthy value. - * - * @param {string} desc - * A description of the test. This is logged at the start of the test. - * - * @param {function(): boolean} skipFn - * A predicate that will be called by the test harness to determine - * whether or not the test should be skipped. - * - * @param {function(): MaybePromise} testFn - * The test function. If this function returns a `Promise` it will be - * awaited. - * - * @returns {any} - * The result of calling `add_task` with the wrapped function. - */ - skipIf(desc, skipFn, testFn) { - return _testScope.add_task( - { skip_if: skipFn }, - MochiaImpl.wrap(desc, testFn) - ); - }, - - /** - * Wrap `fn` so that all the setup functions declared with `beforeEach` are - * called before it and all the teardown functions declared with `afterEach` - * are called after. - * - * @param {string} desc - * A description of the test. - * - * @param {function(): MaybePromise} fn - * The function to wrap. - * - * @returns {function(): Promise} - * The wrapped function. - */ - wrap(desc, fn) { - const ctx = Context.current().clone(); - const name = [...ctx.description, desc].join(" / "); - - // This is a hack to give the function an implicit name. - const wrapper = { - [name]: async () => { - _testScope.info(name); - - for (const before of ctx.beforeEach) { - const p = before(); - if (p?.then) { - await p; - } - } - - { - const p = fn(); - if (p?.then) { - await p; - } - } - - for (let i = ctx.afterEach.length - 1; i >= 0; i--) { - const after = ctx.afterEach[i]; - const p = after(); - if (p?.then) { - await p; - } - } - }, - }; - - return wrapper[name]; - }, - }; - - Object.defineProperties(MochiaImpl.it, { - only: { - configurable: false, - value: MochiaImpl.only, - }, - skip: { - configurable: false, - value: MochiaImpl.skip, - }, - skipIf: { - configurable: false, - get: MochiaImpl.skipIf, - }, - }); - - return function (scope) { - _testScope = scope; - - Object.assign(_testScope, { - describe: MochiaImpl.describe, - beforeEach: MochiaImpl.beforeEach, - afterEach: MochiaImpl.afterEach, - it: MochiaImpl.it, - }); - }; -})(); diff --git a/testing/modules/moz.build b/testing/modules/moz.build index 214d29664dac..f078152ce35b 100644 --- a/testing/modules/moz.build +++ b/testing/modules/moz.build @@ -13,7 +13,6 @@ TESTING_JS_MODULES += [ "Assert.sys.mjs", "CoverageUtils.sys.mjs", "FileTestUtils.sys.mjs", - "Mochia.js", "MockRegistrar.sys.mjs", "sinon-7.2.7.js", "Sinon.sys.mjs", diff --git a/testing/xpcshell/head.js b/testing/xpcshell/head.js index f47b062853a1..0276e6cee68d 100644 --- a/testing/xpcshell/head.js +++ b/testing/xpcshell/head.js @@ -1920,11 +1920,3 @@ Object.defineProperty(this, "mozinfo", { return _mozinfo; }, }); - -/* import-globals-from ../modules/Mochia.js */ -Services.scriptloader.loadSubScript( - "resource://testing-common/Mochia.js", - this -); - -Mochia(this); diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js index c8e48231793e..ed97134505a2 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js @@ -24,10 +24,7 @@ module.exports = { addLoadEvent: false, add_setup: false, add_task: false, - afterEach: false, - beforeEach: false, content: false, - describe: false, executeSoon: false, expectUncaughtException: false, export_assertions: false, @@ -43,7 +40,6 @@ module.exports = { info: false, is: false, isnot: false, - it: false, ok: false, record: false, registerCleanupFunction: false, diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js index 9d615e4aef60..e8fbbb3c0a7d 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js @@ -11,15 +11,11 @@ module.exports = { globals: { // SpecialPowers is injected into the window object via SimpleTest.js SpecialPowers: false, - afterEach: false, - beforeEach: false, - describe: false, extractJarToTmp: false, getChromeDir: false, getJar: false, getResolvedURI: false, getRootDirectory: false, - it: false, }, name: "mozilla/chrome-test", diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js index 1357ae619c89..26ea6d154dbb 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js @@ -7,13 +7,6 @@ module.exports = { "mozilla/xpcshell": true, }, - globals: { - afterEach: false, - beforeEach: false, - describe: false, - it: false, - }, - name: "mozilla/xpcshell-test", plugins: ["mozilla", "@microsoft/sdl"],