Create a reusable cypress_test() macro

I want to write a couple of tests for some plotting web pages. I keep
asking other folks to validate that I didn't break anything. It's time
to automate this.

This patch creates a new macro that will make it easier for everyone
to write such tests. We're also converting the one existing Cypress
test to use the new macro.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I8ec82dc8ebdcc22a394f3b66fbc5c39e937adc6e
diff --git a/scouting/BUILD b/scouting/BUILD
index 1d6ac5d..a8072d3 100644
--- a/scouting/BUILD
+++ b/scouting/BUILD
@@ -1,5 +1,5 @@
-load("@aspect_rules_cypress//cypress:defs.bzl", "cypress_module_test")
 load("//tools/build_rules:apache.bzl", "apache_wrapper")
+load("//tools/build_rules:js.bzl", "cypress_test")
 
 sh_binary(
     name = "scouting",
@@ -16,21 +16,11 @@
     ],
 )
 
-cypress_module_test(
+cypress_test(
     name = "scouting_test",
-    args = [
-        "run",
-        "--config-file=cypress.config.js",
-        "--browser=../../chrome_linux/chrome",
-    ],
-    browsers = ["@chrome_linux//:all"],
-    copy_data_to_bin = False,
-    cypress = "//:node_modules/cypress",
     data = [
-        "cypress.config.js",
         "scouting_test.cy.js",
         "//scouting/testing:scouting_test_servers",
-        "@xvfb_amd64//:wrapped_bin/Xvfb",
     ],
     runner = "cypress_runner.js",
 )
diff --git a/scouting/cypress.config.js b/scouting/cypress.config.js
deleted file mode 100644
index 4eb1a82..0000000
--- a/scouting/cypress.config.js
+++ /dev/null
@@ -1,22 +0,0 @@
-const {defineConfig} = require('cypress');
-
-module.exports = defineConfig({
-  e2e: {
-    specPattern: ['*.cy.js'],
-    supportFile: false,
-    setupNodeEvents(on, config) {
-      on('before:browser:launch', (browser = {}, launchOptions) => {
-        launchOptions.args.push('--disable-gpu-shader-disk-cache');
-      });
-
-      // Lets users print to the console:
-      //    cy.task('log', 'message here');
-      on('task', {
-        log(message) {
-          console.log(message);
-          return null;
-        },
-      });
-    },
-  },
-});
diff --git a/scouting/cypress_runner.js b/scouting/cypress_runner.js
index 6c63adb..c8f60f8 100644
--- a/scouting/cypress_runner.js
+++ b/scouting/cypress_runner.js
@@ -57,17 +57,22 @@
 
 // Wait for the server to be ready, run the tests, then shut down the server.
 (async () => {
+  // Parse command line options.
+  let runOptions = await cypress.cli.parseRunArguments(process.argv.slice(2));
+
   await serverStartup;
-  const result = await cypress.run({
-    headless: true,
-    config: {
-      baseUrl: 'http://localhost:8000',
-      screenshotsFolder:
-        process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/screenshots',
-      video: false,
-      videosFolder: process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/videos',
-    },
-  });
+  const result = await cypress.run(
+    Object.assign(runOptions, {
+      headless: true,
+      config: {
+        baseUrl: 'http://localhost:8000',
+        screenshotsFolder:
+          process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/screenshots',
+        video: false,
+        videosFolder: process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/videos',
+      },
+    })
+  );
   await servers.kill();
   await serverShutdown;