forked from mirrors/gecko-dev
Bug 1860427 - Add a new environment to ESLint for testharness.js and automatically use it for html files including the harness. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D191581
This commit is contained in:
parent
ea4d53ae9b
commit
8679d01066
4 changed files with 84 additions and 1 deletions
|
|
@ -70,6 +70,21 @@ special-powers-sandbox
|
|||
Defines the environment for scripts evaluated inside ``SpecialPowers`` sandbox
|
||||
with the default options.
|
||||
|
||||
testharness
|
||||
-----------
|
||||
|
||||
Defines the environment the globals that are injected from
|
||||
:searchfox:`dom/imptests/testharness.js <dom/imptests/testharness.js>`.
|
||||
|
||||
It is injected automatically into (x)html files which include:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<script src="/resources/testharness.js"></script>
|
||||
|
||||
It may need to be included manually in JavaScript files which are loaded into
|
||||
the same scope.
|
||||
|
||||
xpcshell
|
||||
--------
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* @fileoverview Defines the environment for testharness.js files. This
|
||||
* is automatically included in (x)html files including
|
||||
* /resources/testharness.js.
|
||||
*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
// These globals are taken from dom/imptests/testharness.js, via the expose
|
||||
// function.
|
||||
|
||||
module.exports = {
|
||||
globals: {
|
||||
EventWatcher: false,
|
||||
test: false,
|
||||
async_test: false,
|
||||
promise_test: false,
|
||||
promise_rejects: false,
|
||||
generate_tests: false,
|
||||
setup: false,
|
||||
done: false,
|
||||
on_event: false,
|
||||
step_timeout: false,
|
||||
format_value: false,
|
||||
assert_true: false,
|
||||
assert_false: false,
|
||||
assert_equals: false,
|
||||
assert_not_equals: false,
|
||||
assert_in_array: false,
|
||||
assert_object_equals: false,
|
||||
assert_array_equals: false,
|
||||
assert_approx_equals: false,
|
||||
assert_less_than: false,
|
||||
assert_greater_than: false,
|
||||
assert_between_exclusive: false,
|
||||
assert_less_than_equal: false,
|
||||
assert_greater_than_equal: false,
|
||||
assert_between_inclusive: false,
|
||||
assert_regexp_match: false,
|
||||
assert_class_string: false,
|
||||
assert_exists: false,
|
||||
assert_own_property: false,
|
||||
assert_not_exists: false,
|
||||
assert_inherits: false,
|
||||
assert_idl_attribute: false,
|
||||
assert_readonly: false,
|
||||
assert_throws: false,
|
||||
assert_unreaded: false,
|
||||
assert_any: false,
|
||||
fetch_tests_from_worker: false,
|
||||
timeout: false,
|
||||
add_start_callback: false,
|
||||
add_test_state_callback: false,
|
||||
add_result_callback: false,
|
||||
add_completion_callback: false,
|
||||
},
|
||||
};
|
||||
|
|
@ -12,6 +12,7 @@ const path = require("path");
|
|||
const fs = require("fs");
|
||||
const helpers = require("./helpers");
|
||||
const htmlparser = require("htmlparser2");
|
||||
const testharnessEnvironment = require("./environments/testharness.js");
|
||||
|
||||
const callExpressionDefinitions = [
|
||||
/^loader\.lazyGetter\((?:globalThis|this), "(\w+)"/,
|
||||
|
|
@ -323,6 +324,11 @@ function getGlobalsForScript(src, type, dir) {
|
|||
scriptName = path.join(helpers.rootDir, "testing", "mochitest", src);
|
||||
} else if (src.startsWith("/tests/")) {
|
||||
scriptName = path.join(helpers.rootDir, src.substring(7));
|
||||
} else if (src.startsWith("/resources/testharness.js")) {
|
||||
return Object.keys(testharnessEnvironment.globals).map(name => ({
|
||||
name,
|
||||
writable: true,
|
||||
}));
|
||||
} else if (dir) {
|
||||
// Fallback to hoping this is a relative path.
|
||||
scriptName = path.join(dir, src);
|
||||
|
|
|
|||
|
|
@ -27,13 +27,14 @@ module.exports = {
|
|||
"chrome-worker": require("../lib/environments/chrome-worker.js"),
|
||||
"frame-script": require("../lib/environments/frame-script.js"),
|
||||
jsm: require("../lib/environments/jsm.js"),
|
||||
privileged: require("../lib/environments/privileged.js"),
|
||||
"process-script": require("../lib/environments/process-script.js"),
|
||||
"remote-page": require("../lib/environments/remote-page.js"),
|
||||
simpletest: require("../lib/environments/simpletest.js"),
|
||||
sjs: require("../lib/environments/sjs.js"),
|
||||
"special-powers-sandbox": require("../lib/environments/special-powers-sandbox.js"),
|
||||
specific: require("../lib/environments/specific"),
|
||||
privileged: require("../lib/environments/privileged.js"),
|
||||
testharness: require("../lib/environments/testharness.js"),
|
||||
xpcshell: require("../lib/environments/xpcshell.js"),
|
||||
},
|
||||
rules: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue