зеркало из https://github.com/mozilla/gecko-dev.git
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 : 0071e0fa7361e67e6c84bca2f4a0c5b1a3c634db
This commit is contained in:
Родитель
6b99474c7c
Коммит
bc1ac20b7c
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче