Bug 1245916: Import more head files for xpcshell tests. r=pbrosset

xpcshell tests used to use head_*.js files so this adds those for global
discovery.

MozReview-Commit-ID: BOsoGIpwdgu

--HG--
extra : rebase_source : ef36531641cbd353625019f8deba333cfd352891
extra : source : 70eca07367f40a9b4fe8c6e23ec0aef73bf2a962
This commit is contained in:
Dave Townsend 2016-02-05 13:23:40 -08:00
Родитель 0a913f73ee
Коммит d450ff9b15
2 изменённых файлов: 41 добавлений и 6 удалений

Просмотреть файл

@ -308,7 +308,7 @@ module.exports = {
*
* @param {RuleContext} scope
* You should pass this from within a rule
* e.g. helpers.getIsBrowserMochitest(this)
* e.g. helpers.getIsHeadFile(this)
*
* @return {Boolean}
* True or false
@ -319,6 +319,22 @@ module.exports = {
return /.*[\\/]head(_.+)?\.js$/.test(pathAndFilename);
},
/**
* Check whether we might be in an xpcshell test.
*
* @param {RuleContext} scope
* You should pass this from within a rule
* e.g. helpers.getIsXpcshellTest(this)
*
* @return {Boolean}
* True or false
*/
getIsXpcshellTest: function(scope) {
var pathAndFilename = scope.getFilename();
return /.*[\\/]test_.+\.js$/.test(pathAndFilename);
},
/**
* Check whether we are in a browser mochitest.
*
@ -348,7 +364,7 @@ module.exports = {
getIsTest: function(scope) {
var pathAndFilename = scope.getFilename();
if (/.*[\\/]test_.+\.js$/.test(pathAndFilename)) {
if (this.getIsXpcshellTest(scope)) {
return true;
}

Просмотреть файл

@ -20,6 +20,20 @@ var globals = require("../globals");
module.exports = function(context) {
function importHead(path, node) {
try {
let stats = fs.statSync(path);
if (!stats.isFile()) {
return;
}
} catch (e) {
return;
}
let newGlobals = globals.getGlobalsForFile(path);
helpers.addGlobals(newGlobals, context.getScope());
}
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
@ -32,13 +46,18 @@ module.exports = function(context) {
var currentFilePath = helpers.getAbsoluteFilePath(context);
var dirName = path.dirname(currentFilePath);
var fullHeadjsPath = path.resolve(dirName, "head.js");
if (!fs.existsSync(fullHeadjsPath)) {
importHead(path.resolve(dirName, "head.js"), node);
if (!helpers.getIsXpcshellTest(this)) {
return;
}
let newGlobals = globals.getGlobalsForFile(fullHeadjsPath);
helpers.addGlobals(newGlobals, context.getScope());
let names = fs.readdirSync(dirName);
for (let name of names) {
if (name.startsWith("head_") && name.endsWith(".js")) {
importHead(path.resolve(dirName, name), node);
}
}
}
};
};