Bug 1683392 - [puppeteer] Use "npm ci" only when tests are run on TaskCluster. r=remote-protocol-reviewers,jdescottes
authorHenrik Skupin <mail@hskupin.info>
Mon, 01 Feb 2021 10:59:38 +0000
changeset 3480202 d2f8cb04ce264f9493140d1d56ecfb20d212134e
parent 3480201 263d593f86096a9282446d1b33d88bd24ebde0ad
child 3480203 b129d712e3bc11debc9b91c582556b1941e753b3
push id648815
push userwptsync@mozilla.com
push dateMon, 01 Feb 2021 17:48:27 +0000
treeherdertry@abfb9840bad0 [default view] [failures only]
reviewersremote-protocol-reviewers, jdescottes
bugs1683392
milestone87.0a1
Bug 1683392 - [puppeteer] Use "npm ci" only when tests are run on TaskCluster. r=remote-protocol-reviewers,jdescottes This patch adds a new "--ci" argument for the "mach puppeteer-test" command. As such it can also be used locally to simulate a test job in CI. Differential Revision: https://phabricator.services.mozilla.com/D101780
remote/mach_commands.py
taskcluster/ci/source-test/remote.yml
--- a/remote/mach_commands.py
+++ b/remote/mach_commands.py
@@ -503,16 +503,21 @@ def create_parser_puppeteer():
         "--product", type=str, default="firefox", choices=["chrome", "firefox"]
     )
     p.add_argument(
         "--binary",
         type=str,
         help="Path to browser binary.  Defaults to local Firefox build.",
     )
     p.add_argument(
+        "--ci",
+        action="store_true",
+        help="Flag that indicates that tests run in a CI environment.",
+    )
+    p.add_argument(
         "--enable-fission",
         action="store_true",
         help="Enable Fission (site isolation) in Gecko.",
     )
     p.add_argument(
         "-z", "--headless", action="store_true", help="Run browser in headless mode."
     )
     p.add_argument(
@@ -566,28 +571,31 @@ class PuppeteerTest(MachCommandBase):
         "puppeteer-test",
         category="testing",
         description="Run Puppeteer unit tests.",
         parser=create_parser_puppeteer,
     )
     def puppeteer_test(
         self,
         binary=None,
+        ci=False,
         enable_fission=False,
         headless=False,
         extra_prefs=None,
         extra_options=None,
         verbosity=0,
         tests=None,
         product="firefox",
         write_results=None,
         subset=False,
         **kwargs
     ):
 
+        self.ci = ci
+
         logger = mozlog.commandline.setup_logging(
             "puppeteer-test", kwargs, {"mach": sys.stdout}
         )
 
         # moztest calls this programmatically with test objects or manifests
         if "test_objects" in kwargs and tests is not None:
             logger.error("Expected either 'test_objects' or 'tests'")
             exit(1)
@@ -664,17 +672,19 @@ class PuppeteerTest(MachCommandBase):
                 break
 
         if product != "chrome":
             env["PUPPETEER_SKIP_DOWNLOAD"] = "1"
         lib_dir = os.path.join(self.topsrcdir, puppeteer_dir, "lib")
         if changed_files and os.path.isdir(lib_dir):
             # clobber lib to force `tsc compile` step
             shutil.rmtree(lib_dir)
-        npm("ci", cwd=os.path.join(self.topsrcdir, puppeteer_dir), env=env)
+
+        command = "ci" if self.ci else "install"
+        npm(command, cwd=os.path.join(self.topsrcdir, puppeteer_dir), env=env)
 
 
 def exit(code, error=None):
     if error is not None:
         if isinstance(error, Exception):
             import traceback
 
             traceback.print_exc()
--- a/taskcluster/ci/source-test/remote.yml
+++ b/taskcluster/ci/source-test/remote.yml
@@ -40,20 +40,20 @@ puppeteer:
     run-on-projects: ["trunk"]
     treeherder:
         symbol: remote(pup)
     run:
         using: run-task
         command: >
             cd $GECKO_PATH/ &&
             $MOZ_FETCHES_DIR/firefox/firefox --screenshot http://example.org &&
-            ./mach puppeteer-test -vv --binary $MOZ_FETCHES_DIR/firefox/firefox --headless --write-results /builds/worker/results.json --log-tbpl - --log-errorsummary /builds/worker/pup_errorsummary.json --log-raw /builds/worker/pup_raw.log
+            ./mach puppeteer-test --ci -vv --binary $MOZ_FETCHES_DIR/firefox/firefox --headless --write-results /builds/worker/results.json --log-tbpl - --log-errorsummary /builds/worker/pup_errorsummary.json --log-raw /builds/worker/pup_raw.log
 
 puppeteer-fis:
     description: Puppeteer tests against Firefox CDP-based remote protocol with Fission (site isolation) turned on
     run-on-projects: []
     treeherder:
         symbol: remote(pup-fis)
     run:
         using: run-task
         command: >
             cd $GECKO_PATH/ &&
-            ./mach puppeteer-test -vv --binary $MOZ_FETCHES_DIR/firefox/firefox --headless --enable-fission --write-results /builds/worker/results.json --log-tbpl - --log-errorsummary /builds/worker/pup_errorsummary.json --log-raw /builds/worker/pup_raw.log
+            ./mach puppeteer-test --ci -vv --binary $MOZ_FETCHES_DIR/firefox/firefox --headless --enable-fission --write-results /builds/worker/results.json --log-tbpl - --log-errorsummary /builds/worker/pup_errorsummary.json --log-raw /builds/worker/pup_raw.log