[TestRunner] add base-path and shared-resources flags

This CL adds two flags to the new test runner for configuring the
components server and then updates the server to detect those values.

Note that whilst this CL adds yet-another-way to configure the
components server, this is only being done for backwards compat whilst
we roll out this change to all the various places. We will remove old
options towards the end of this work.

Bug: chromium:1186163
Change-Id: I4c9b85a5745b9fe36894e3c492952938a5b8f648
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2763875
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
diff --git a/scripts/component_server/server.js b/scripts/component_server/server.js
index 77a4ec2..358179d 100644
--- a/scripts/component_server/server.js
+++ b/scripts/component_server/server.js
@@ -8,8 +8,20 @@
 const parseURL = require('url').parse;
 const {argv} = require('yargs');
 
-const serverPort = parseInt(process.env.PORT, 10) || 8090;
+function getTestRunnerConfig() {
+  try {
+    return JSON.parse(process.env.TEST_RUNNER_JSON_CONFIG);
+  } catch {
+    // Return an empty object so any lookups return undefined
+    return {};
+  }
+}
+function getTestRunnerConfigSetting(settingKey, fallbackValue) {
+  const config = getTestRunnerConfig();
+  return config[settingKey] === undefined ? fallbackValue : config[settingKey];
+}
 
+const serverPort = parseInt(process.env.PORT, 10) || 8090;
 const target = argv.target || process.env.TARGET || 'Default';
 
 /**
@@ -17,15 +29,17 @@
  * doc example to load. By default it's /, so that we load /front_end/..., but
  * this can be configured if you have a different file structure.
  */
-const sharedResourcesBase = argv.sharedResourcesBase || '/';
+const sharedResourcesBase =
+    argv.sharedResourcesBase || getTestRunnerConfigSetting('component-server-shared-resources-path', '/');
 
 /**
  * The server assumes that examples live in
- * devtoolsRoot/out/Target/front_end/component_docs, but if you need to add a
+ * devtoolsRoot/out/Target/gen/front_end/component_docs, but if you need to add a
  * prefix you can pass this argument. Passing `foo` will redirect the server to
- * look in devtoolsRoot/out/Target/foo/front_end/component_docs.
+ * look in devtoolsRoot/out/Target/gen/foo/front_end/component_docs.
  */
-const componentDocsBaseArg = argv.componentDocsBase || process.env.COMPONENT_DOCS_BASE || '';
+const componentDocsBaseArg = argv.componentDocsBase || process.env.COMPONENT_DOCS_BASE ||
+    getTestRunnerConfigSetting('component-server-base-path', '');
 
 /**
  * When you run npm run components-server we run the script as is from scripts/,
diff --git a/scripts/test/run_test_suite.js b/scripts/test/run_test_suite.js
index 73508ad..6a90aa0 100644
--- a/scripts/test/run_test_suite.js
+++ b/scripts/test/run_test_suite.js
@@ -35,6 +35,18 @@
           type: 'string',
           desc: 'A comma separated glob (or just a file path) to select specific test files to execute.'
         })
+        .option('component-server-base-path', {
+          type: 'string',
+          desc:
+              'The component serve assumes examples live in out/TARGET/gen/front_end/component_docs, but you can set this option to add a prefix. Passing `foo` will redirect the server to look in out/TARGET/gen/foo/front_end/component_docs.',
+          default: '',
+        })
+        .option('component-server-shared-resources-path', {
+          type: 'string',
+          desc:
+              'Configures the base of the URLs that are injected into each component example. By default it is "/", so we load from "/front_end", but you can provide a different prefix if the shared resources are based elsewhere in the directory structure.',
+          default: '/',
+        })
         .option(
             'chrome-binary-path',
             {type: 'string', desc: 'Path to the Chromium binary.', default: downloadedChromeBinaryPath()})