Bug 1383120 - [eslint-plugin-mozilla] Fix getTestType() helper so mochitests aren't treated as xpcshell tests, r?Mossop draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 21 Jul 2017 12:41:27 -0400
changeset 615878 577911fb00cf2d5ad2ba9512e6102dc05fa91f1e
parent 615779 e8400551c2e39f24c75a009ebed496c7acd7bf47
child 615879 6ff43c48b25fa9c15426b0294f5fdc03dc64d354
push id70521
push userahalberstadt@mozilla.com
push dateWed, 26 Jul 2017 14:35:22 +0000
reviewersMossop
bugs1383120
milestone56.0a1
Bug 1383120 - [eslint-plugin-mozilla] Fix getTestType() helper so mochitests aren't treated as xpcshell tests, r?Mossop This also adds a11y as a test type. MozReview-Commit-ID: D7y3uALzVQx
devtools/server/tests/unit/test_profiler_bufferstatus.js
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
--- a/devtools/server/tests/unit/test_profiler_bufferstatus.js
+++ b/devtools/server/tests/unit/test_profiler_bufferstatus.js
@@ -8,16 +8,17 @@
  * Tests if the profiler actor returns its buffer status via getBufferInfo.
  */
 
 const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
 const INITIAL_WAIT_TIME = 100; // ms
 const MAX_WAIT_TIME = 20000; // ms
 const MAX_PROFILER_ENTRIES = 10000000;
 
+// eslint-disable-next-line no-unused-vars
 function run_test() {
   // Ensure the profiler is not running when the test starts (it could
   // happen if the MOZ_PROFILER_STARTUP environment variable is set).
   Profiler.StopProfiler();
 
   get_chrome_actors((client, form) => {
     let actor = form.profilerActor;
     check_empty_buffer(client, actor, () => {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -512,37 +512,47 @@ module.exports = {
    * @param  {RuleContext} scope
    *         You should pass this from within a rule
    *         e.g. helpers.getIsHeadFile(context)
    *
    * @return {String or null}
    *         Test type: xpcshell, browser, chrome, mochitest
    */
   getTestType(scope) {
+    let testTypes = ["browser", "xpcshell", "chrome", "mochitest", "a11y"];
     let manifest = this.getTestManifest(scope);
     if (manifest) {
       let name = path.basename(manifest);
-      for (let testType of ["browser", "xpcshell", "chrome", "mochitest"]) {
+      for (let testType of testTypes) {
         if (name.startsWith(testType)) {
           return testType;
         }
       }
     }
 
     let filepath = this.cleanUpPath(scope.getFilename());
     let filename = path.basename(filepath);
 
     if (filename.startsWith("browser_")) {
       return "browser";
     }
 
     if (filename.startsWith("test_")) {
-      return "xpcshell";
+      let parent = path.basename(path.dirname(filepath));
+      for (let testType of testTypes) {
+        if (parent.startsWith(testType)) {
+          return testType;
+        }
+      }
+
+      // It likely is a test, we're just not sure what kind.
+      return "unknown";
     }
 
+    // Likely not a test
     return null;
   },
 
   getIsWorker(filePath) {
     let filename = path.basename(this.cleanUpPath(filePath)).toLowerCase();
 
     return filename.includes("worker");
   },