mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 05:45:37 +00:00
Bug 1229224: Add an eslint plugin for importing all browser.js globals for browser-chrome tests. r=miker
--HG-- extra : commitid : 5aYt0tOvUSV extra : rebase_source : 08a1eaa364748ac9209f73e4aab4db0b53452265 extra : amend_source : 8571571251ad40a4a759b58b802b129c34b04be0
This commit is contained in:
parent
b84487234d
commit
47b0152e7a
@ -0,0 +1,12 @@
|
|||||||
|
.. _import-browserjs-globals:
|
||||||
|
|
||||||
|
========================
|
||||||
|
import-browserjs-globals
|
||||||
|
========================
|
||||||
|
|
||||||
|
Rule Details
|
||||||
|
------------
|
||||||
|
|
||||||
|
When included files from the main browser UI scripts will be loaded and any
|
||||||
|
declared globals will be defined for the current file. This is mostly useful for
|
||||||
|
browser-chrome mochitests that call browser functions.
|
@ -21,6 +21,7 @@ module.exports = {
|
|||||||
"components-imports": require("../lib/rules/components-imports"),
|
"components-imports": require("../lib/rules/components-imports"),
|
||||||
"import-globals-from": require("../lib/rules/import-globals-from"),
|
"import-globals-from": require("../lib/rules/import-globals-from"),
|
||||||
"import-headjs-globals": require("../lib/rules/import-headjs-globals"),
|
"import-headjs-globals": require("../lib/rules/import-headjs-globals"),
|
||||||
|
"import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
|
||||||
"mark-test-function-used": require("../lib/rules/mark-test-function-used"),
|
"mark-test-function-used": require("../lib/rules/mark-test-function-used"),
|
||||||
"no-aArgs": require("../lib/rules/no-aArgs"),
|
"no-aArgs": require("../lib/rules/no-aArgs"),
|
||||||
"no-cpows-in-tests": require("../lib/rules/no-cpows-in-tests"),
|
"no-cpows-in-tests": require("../lib/rules/no-cpows-in-tests"),
|
||||||
@ -31,6 +32,7 @@ module.exports = {
|
|||||||
"components-imports": 0,
|
"components-imports": 0,
|
||||||
"import-globals-from": 0,
|
"import-globals-from": 0,
|
||||||
"import-headjs-globals": 0,
|
"import-headjs-globals": 0,
|
||||||
|
"import-browserjs-globals": 0,
|
||||||
"mark-test-function-used": 0,
|
"mark-test-function-used": 0,
|
||||||
"no-aArgs": 0,
|
"no-aArgs": 0,
|
||||||
"no-cpows-in-tests": 0,
|
"no-cpows-in-tests": 0,
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* @fileoverview Import globals from browser.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";
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Rule Definition
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
|
var helpers = require("../helpers");
|
||||||
|
|
||||||
|
const SCRIPTS = [
|
||||||
|
"toolkit/components/printing/content/printUtils.js",
|
||||||
|
"toolkit/content/viewZoomOverlay.js",
|
||||||
|
"browser/components/places/content/browserPlacesViews.js",
|
||||||
|
"browser/base/content/browser.js",
|
||||||
|
"browser/components/downloads/content/downloads.js",
|
||||||
|
"browser/components/downloads/content/indicator.js",
|
||||||
|
"browser/components/customizableui/content/panelUI.js",
|
||||||
|
"toolkit/obsolete/content/inlineSpellCheckUI.js",
|
||||||
|
"toolkit/components/viewsource/content/viewSourceUtils.js",
|
||||||
|
"browser/base/content/browser-addons.js",
|
||||||
|
"browser/base/content/browser-ctrlTab.js",
|
||||||
|
"browser/base/content/browser-customization.js",
|
||||||
|
"browser/base/content/browser-devedition.js",
|
||||||
|
"browser/base/content/browser-eme.js",
|
||||||
|
"browser/base/content/browser-feeds.js",
|
||||||
|
"browser/base/content/browser-fullScreen.js",
|
||||||
|
"browser/base/content/browser-fullZoom.js",
|
||||||
|
"browser/base/content/browser-gestureSupport.js",
|
||||||
|
"browser/base/content/browser-places.js",
|
||||||
|
"browser/base/content/browser-plugins.js",
|
||||||
|
"browser/base/content/browser-safebrowsing.js",
|
||||||
|
"browser/base/content/browser-sidebar.js",
|
||||||
|
"browser/base/content/browser-social.js",
|
||||||
|
"browser/base/content/browser-syncui.js",
|
||||||
|
"browser/base/content/browser-tabsintitlebar.js",
|
||||||
|
"browser/base/content/browser-thumbnails.js",
|
||||||
|
"browser/base/content/browser-trackingprotection.js",
|
||||||
|
"browser/base/content/browser-data-submission-info-bar.js",
|
||||||
|
"browser/base/content/browser-fxaccounts.js",
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = function(context) {
|
||||||
|
return {
|
||||||
|
Program: function(node) {
|
||||||
|
if (!helpers.getIsBrowserMochitest(this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let root = helpers.getRootDir(context);
|
||||||
|
for (let script of SCRIPTS) {
|
||||||
|
let fileName = path.join(root, script);
|
||||||
|
try {
|
||||||
|
let globals = helpers.getGlobalsForFile(fileName);
|
||||||
|
helpers.addGlobals(globals, context);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
context.report(
|
||||||
|
node,
|
||||||
|
"Could not load globals from file {{filePath}}: {{error}}",
|
||||||
|
{
|
||||||
|
filePath: path.relative(root, fileName),
|
||||||
|
error: e
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user