diff --git a/scripts/component_server/server.js b/scripts/component_server/server.js index 77a4ec283a..358179d337 100644 --- a/scripts/component_server/server.js +++ b/scripts/component_server/server.js @@ -8,8 +8,20 @@ const path = require('path'); 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 @@ const target = argv.target || process.env.TARGET || 'Default'; * 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 73508adc41..6a90aa07f4 100644 --- a/scripts/test/run_test_suite.js +++ b/scripts/test/run_test_suite.js @@ -35,6 +35,18 @@ const yargsObject = 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()})