bug 1540655: moztest: add test path resolution for Puppeteer tests; r=ahal draft
Fri, 16 Aug 2019 13:22:24 +0000
changeset 2220731 f9f8c820826bbfefe7eb61d678d1c7aa51bd0558
parent 2220730 5de2f4622f3ce60ef9bf2ce100e35c229fc2dea0
child 2220732 0b31408d805481c20e0113e0c84c2a6462a5e323
push id406994
push userreviewbot
push dateFri, 16 Aug 2019 13:23:14 +0000
treeherdertry@5f50de08beda [default view] [failures only]
bug 1540655: moztest: add test path resolution for Puppeteer tests; r=ahal Makes it possible for mach to resolve test paths for Puppeteer, so that individual tests can be run from the command line using "./mach test", as such: % ./mach test remote/test/puppeteer/test/screenshot.spec.js As the Puppeteer test suite is imported from upstream and we cannot change this directory at will (i.e. to add test manifest files), we take the same approach as for WPT and populate the manifest by recursively walking the remote/test/puppeteer/test/**/*.spec.js file tree. Differential Revision: https://phabricator.services.mozilla.com/D37013 Differential Diff: PHID-DIFF-vnjje3k56ohnifg5m4vx
--- a/testing/mozbase/moztest/moztest/resolve.py
+++ b/testing/mozbase/moztest/moztest/resolve.py
@@ -1,16 +1,17 @@
 # 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/.
 from __future__ import absolute_import, print_function, unicode_literals
+import fnmatch
+import os
 import pickle
-import os
 import sys
 from collections import defaultdict
 import manifestparser
 import mozpack.path as mozpath
 from mozbuild.base import MozbuildObject
 from mozbuild.util import OrderedDefaultDict
 from mozbuild.frontend.reader import BuildReader, EmptyConfig
@@ -142,16 +143,21 @@ TEST_SUITES = {
         'task_regex': ['mochitest-remote($|.*(-1|[^0-9])$)',
     'mochitest-webgl1-core': WebglSuite('webgl1-core'),
     'mochitest-webgl1-ext': WebglSuite('webgl1-ext'),
     'mochitest-webgl2-core': WebglSuite('webgl2-core'),
     'mochitest-webgl2-ext': WebglSuite('webgl2-ext'),
     'mochitest-webgl2-deqp': WebglSuite('webgl2-deqp'),
+    'puppeteer': {
+        'aliases': ('remote/test/puppeteer',),
+        'mach_command': 'puppeteer-test',
+        'kwargs': {},
+    },
     'python': {
         'mach_command': 'python-test',
         'kwargs': {'tests': None},
     'telemetry-tests-client': {
         'aliases': ('ttc',),
         'mach_command': 'telemetry-tests-client',
         'kwargs': {},
@@ -229,16 +235,17 @@ for i in range(1, MOCHITEST_TOTAL_CHUNKS
     'a11y': 'mochitest-a11y',
     'browser-chrome': 'mochitest-browser-chrome',
     'chrome': 'mochitest-chrome',
     'crashtest': 'crashtest',
     'firefox-ui-functional': 'firefox-ui-functional',
     'firefox-ui-update': 'firefox-ui-update',
     'marionette': 'marionette',
     'mochitest': 'mochitest-plain',
+    'puppeteer': 'puppeteer',
     'python': 'python',
     'reftest': 'reftest',
     'steeplechase': '',
     'telemetry-tests-client': 'telemetry-tests-client',
     'web-platform-tests': 'web-platform-tests',
     'xpcshell': 'xpcshell',
@@ -420,16 +427,18 @@ class TestMetadata(object):
         paths = paths or []
         paths = [mozpath.normpath(p) for p in paths]
         if not paths:
             paths = [None]
         candidate_paths = set()
+        if flavor in (None, 'puppeteer') and any(self.is_puppeteer_path(p) for p in paths):
+            self.add_puppeteer_manifest_data()
         if flavor in (None, 'web-platform-tests') and any(self.is_wpt_path(p) for p in paths):
         for path in sorted(paths):
             if path is None:
                 candidate_paths |= set(self._tests_by_path.keys())
@@ -450,16 +459,40 @@ class TestMetadata(object):
             candidate_paths |= {p for p in self._tests_by_path if path in p}
         for p in sorted(candidate_paths):
             tests = self._tests_by_path[p]
             for test in fltr(tests):
                 yield test
+    def is_puppeteer_path(self, path):
+        if path is None:
+            return True
+        return mozpath.match(path, "remote/test/puppeteer/test/**")
+    def add_puppeteer_manifest_data(self):
+        test_path = os.path.join(self._srcdir, "remote", "test", "puppeteer", "test")
+        for root, dirs, paths in os.walk(test_path):
+            for filename in fnmatch.filter(paths, "*.spec.js"):
+                path = os.path.join(root, filename)
+                self._tests_by_path[path].append({
+                    "path": os.path.abspath(path),
+                    "flavor": "puppeteer",
+                    "here": os.path.dirname(path),
+                    "manifest": None,
+                    "name": path,
+                    "file_relpath": path,
+                    "head": "",
+                    "support-files": "",
+                    "subsuite": "puppeteer",
+                    "dir_relpath": os.path.dirname(path),
+                    "srcdir_relpath": path,
+                    })
     def is_wpt_path(self, path):
         if path is None:
             return True
         if mozpath.match(path, "testing/web-platform/tests/**"):
             return True
         if mozpath.match(path, "testing/web-platform/mozilla/tests/**"):
             return True
         return False