Skip to content

Commit c35c28e

Browse files
authored
core: use config to name every config json (#14649)
1 parent 3055496 commit c35c28e

File tree

17 files changed

+165
-165
lines changed

17 files changed

+165
-165
lines changed

cli/bin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ async function begin() {
6464
const urlUnderTest = cliFlags._[0];
6565

6666
/** @type {LH.Config.Json|undefined} */
67-
let configJson;
67+
let config;
6868
if (cliFlags.configPath) {
6969
// Resolve the config file path relative to where cli was called.
7070
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath);
7171

7272
if (cliFlags.configPath.endsWith('.json')) {
73-
configJson = JSON.parse(fs.readFileSync(cliFlags.configPath, 'utf-8'));
73+
config = JSON.parse(fs.readFileSync(cliFlags.configPath, 'utf-8'));
7474
} else {
7575
const configModuleUrl = url.pathToFileURL(cliFlags.configPath).href;
76-
configJson = (await import(configModuleUrl)).default;
76+
config = (await import(configModuleUrl)).default;
7777
}
7878
} else if (cliFlags.preset) {
79-
configJson = (await import(`../core/config/${cliFlags.preset}-config.js`)).default;
79+
config = (await import(`../core/config/${cliFlags.preset}-config.js`)).default;
8080
}
8181

8282
if (cliFlags.budgetPath) {
@@ -132,7 +132,7 @@ async function begin() {
132132
});
133133
}
134134

135-
return runLighthouse(urlUnderTest, cliFlags, configJson);
135+
return runLighthouse(urlUnderTest, cliFlags, config);
136136
}
137137

138138
export {

cli/test/smokehouse/lighthouse-runners/bundle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import {loadArtifacts, saveArtifacts} from '../../../../core/lib/asset-saver.js'
2626
// This runs only in the worker. The rest runs on the main thread.
2727
if (!isMainThread && parentPort) {
2828
(async () => {
29-
const {url, configJson, testRunnerOptions} = workerData;
29+
const {url, config, testRunnerOptions} = workerData;
3030
try {
31-
const result = await runBundledLighthouse(url, configJson, testRunnerOptions);
31+
const result = await runBundledLighthouse(url, config, testRunnerOptions);
3232
// Save to assets directory because LighthouseError won't survive postMessage.
3333
const assetsDir = fs.mkdtempSync(os.tmpdir() + '/smoke-bundle-assets-');
3434
await saveArtifacts(result.artifacts, assetsDir);
@@ -46,11 +46,11 @@ if (!isMainThread && parentPort) {
4646

4747
/**
4848
* @param {string} url
49-
* @param {LH.Config.Json|undefined} configJson
49+
* @param {LH.Config.Json|undefined} config
5050
* @param {{isDebug?: boolean, useLegacyNavigation?: boolean}} testRunnerOptions
5151
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts}>}
5252
*/
53-
async function runBundledLighthouse(url, configJson, testRunnerOptions) {
53+
async function runBundledLighthouse(url, config, testRunnerOptions) {
5454
if (isMainThread || !parentPort) {
5555
throw new Error('must be called in worker');
5656
}
@@ -87,12 +87,12 @@ async function runBundledLighthouse(url, configJson, testRunnerOptions) {
8787
if (testRunnerOptions.useLegacyNavigation) {
8888
const connection = new CriConnection(port);
8989
runnerResult =
90-
await legacyNavigation(url, {port, logLevel}, configJson, connection);
90+
await legacyNavigation(url, {port, logLevel}, config, connection);
9191
} else {
9292
// Puppeteer is not included in the bundle, we must create the page here.
9393
const browser = await puppeteer.connect({browserURL: `http://localhost:${port}`});
9494
const page = await browser.newPage();
95-
runnerResult = await lighthouse(url, {port, logLevel}, configJson, page);
95+
runnerResult = await lighthouse(url, {port, logLevel}, config, page);
9696
}
9797
if (!runnerResult) throw new Error('No runnerResult');
9898

@@ -109,17 +109,17 @@ async function runBundledLighthouse(url, configJson, testRunnerOptions) {
109109
/**
110110
* Launch Chrome and do a full Lighthouse run via the Lighthouse DevTools bundle.
111111
* @param {string} url
112-
* @param {LH.Config.Json=} configJson
112+
* @param {LH.Config.Json=} config
113113
* @param {{isDebug?: boolean, useLegacyNavigation?: boolean}=} testRunnerOptions
114114
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>}
115115
*/
116-
async function runLighthouse(url, configJson, testRunnerOptions = {}) {
116+
async function runLighthouse(url, config, testRunnerOptions = {}) {
117117
/** @type {string[]} */
118118
const logs = [];
119119
const worker = new Worker(new URL(import.meta.url), {
120120
stdout: true,
121121
stderr: true,
122-
workerData: {url, configJson, testRunnerOptions},
122+
workerData: {url, config, testRunnerOptions},
123123
});
124124
worker.stdout.setEncoding('utf8');
125125
worker.stderr.setEncoding('utf8');

cli/test/smokehouse/lighthouse-runners/cli.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ const execFileAsync = promisify(execFile);
2727
/**
2828
* Launch Chrome and do a full Lighthouse run via the Lighthouse CLI.
2929
* @param {string} url
30-
* @param {LH.Config.Json=} configJson
30+
* @param {LH.Config.Json=} config
3131
* @param {{isDebug?: boolean, useFraggleRock?: boolean}=} testRunnerOptions
3232
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>}
3333
*/
34-
async function runLighthouse(url, configJson, testRunnerOptions = {}) {
34+
async function runLighthouse(url, config, testRunnerOptions = {}) {
3535
const {isDebug} = testRunnerOptions;
3636
const tmpDir = `${LH_ROOT}/.tmp/smokehouse`;
3737
await fs.mkdir(tmpDir, {recursive: true});
3838
const tmpPath = await fs.mkdtemp(`${tmpDir}/smokehouse-`);
39-
return internalRun(url, tmpPath, configJson, testRunnerOptions)
39+
return internalRun(url, tmpPath, config, testRunnerOptions)
4040
// Wait for internalRun() before removing scratch directory.
4141
.finally(() => !isDebug && fs.rm(tmpPath, {recursive: true, force: true}));
4242
}
@@ -45,11 +45,11 @@ async function runLighthouse(url, configJson, testRunnerOptions = {}) {
4545
* Internal runner.
4646
* @param {string} url
4747
* @param {string} tmpPath
48-
* @param {LH.Config.Json=} configJson
48+
* @param {LH.Config.Json=} config
4949
* @param {{isDebug?: boolean, useLegacyNavigation?: boolean}=} options
5050
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>}
5151
*/
52-
async function internalRun(url, tmpPath, configJson, options) {
52+
async function internalRun(url, tmpPath, config, options) {
5353
const {isDebug = false, useLegacyNavigation = false} = options || {};
5454
const localConsole = new LocalConsole();
5555

@@ -72,9 +72,9 @@ async function internalRun(url, tmpPath, configJson, options) {
7272
}
7373

7474
// Config can be optionally provided.
75-
if (configJson) {
75+
if (config) {
7676
const configPath = `${tmpPath}/config.json`;
77-
await fs.writeFile(configPath, JSON.stringify(configJson));
77+
await fs.writeFile(configPath, JSON.stringify(config));
7878
args.push(`--config-path=${configPath}`);
7979
}
8080

cli/test/smokehouse/lighthouse-runners/devtools.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ async function setup() {
4141
* unless DEVTOOLS_PATH is set.
4242
* CHROME_PATH determines which Chrome is used–otherwise the default is puppeteer's chrome binary.
4343
* @param {string} url
44-
* @param {LH.Config.Json=} configJson
44+
* @param {LH.Config.Json=} config
4545
* @param {{isDebug?: boolean, useLegacyNavigation?: boolean}=} testRunnerOptions
4646
* @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>}
4747
*/
48-
async function runLighthouse(url, configJson, testRunnerOptions = {}) {
48+
async function runLighthouse(url, config, testRunnerOptions = {}) {
4949
const chromeFlags = [
5050
`--custom-devtools-frontend=file://${devtoolsDir}/out/LighthouseIntegration/gen/front_end`,
5151
];
5252
const {lhr, artifacts, logs} = await testUrlFromDevtools(url, {
53-
config: configJson,
53+
config,
5454
chromeFlags,
5555
useLegacyNavigation: testRunnerOptions.useLegacyNavigation,
5656
});

cli/test/smokehouse/smokehouse.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ function purpleify(str) {
134134
}
135135

136136
/**
137-
* @param {LH.Config.Json=} configJson
137+
* @param {LH.Config.Json=} config
138138
* @return {LH.Config.Json|undefined}
139139
*/
140-
function convertToLegacyConfig(configJson) {
141-
if (!configJson) return configJson;
140+
function convertToLegacyConfig(config) {
141+
if (!config) return config;
142142

143143
return {
144-
...configJson,
144+
...config,
145145
passes: [{
146146
passName: 'defaultPass',
147-
pauseAfterFcpMs: configJson.settings?.pauseAfterFcpMs,
148-
pauseAfterLoadMs: configJson.settings?.pauseAfterLoadMs,
149-
networkQuietThresholdMs: configJson.settings?.networkQuietThresholdMs,
150-
cpuQuietThresholdMs: configJson.settings?.cpuQuietThresholdMs,
151-
blankPage: configJson.settings?.blankPage,
147+
pauseAfterFcpMs: config.settings?.pauseAfterFcpMs,
148+
pauseAfterLoadMs: config.settings?.pauseAfterLoadMs,
149+
networkQuietThresholdMs: config.settings?.networkQuietThresholdMs,
150+
cpuQuietThresholdMs: config.settings?.cpuQuietThresholdMs,
151+
blankPage: config.settings?.blankPage,
152152
}],
153153
};
154154
}
@@ -184,15 +184,15 @@ async function runSmokeTest(smokeTestDefn, testOptions) {
184184
bufferedConsole.log(` Retrying run (${i} out of ${retries} retries)…`);
185185
}
186186

187-
let configJson = smokeTestDefn.config;
187+
let config = smokeTestDefn.config;
188188
if (useLegacyNavigation) {
189-
configJson = convertToLegacyConfig(configJson);
189+
config = convertToLegacyConfig(config);
190190
}
191191

192192
// Run Lighthouse.
193193
try {
194194
result = {
195-
...await lighthouseRunner(requestedUrl, configJson, {isDebug, useLegacyNavigation}),
195+
...await lighthouseRunner(requestedUrl, config, {isDebug, useLegacyNavigation}),
196196
networkRequests: takeNetworkRequestUrls ? takeNetworkRequestUrls() : undefined,
197197
};
198198

core/config/config-helpers.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,18 @@ function resolveSettings(settingsJson = {}, overrides = undefined) {
364364
}
365365

366366
/**
367-
* @param {LH.Config.Json} configJSON
367+
* @param {LH.Config.Json} config
368368
* @param {string | undefined} configDir
369369
* @param {{plugins?: string[]} | undefined} flags
370370
* @return {Promise<LH.Config.Json>}
371371
*/
372-
async function mergePlugins(configJSON, configDir, flags) {
373-
const configPlugins = configJSON.plugins || [];
372+
async function mergePlugins(config, configDir, flags) {
373+
const configPlugins = config.plugins || [];
374374
const flagPlugins = flags?.plugins || [];
375375
const pluginNames = new Set([...configPlugins, ...flagPlugins]);
376376

377377
for (const pluginName of pluginNames) {
378-
validation.assertValidPluginName(configJSON, pluginName);
378+
validation.assertValidPluginName(config, pluginName);
379379

380380
// In bundled contexts, `resolveModulePath` will fail, so use the raw pluginName directly.
381381
const pluginPath = isBundledEnvironment() ?
@@ -384,10 +384,10 @@ async function mergePlugins(configJSON, configDir, flags) {
384384
const rawPluginJson = await requireWrapper(pluginPath);
385385
const pluginJson = ConfigPlugin.parsePlugin(rawPluginJson, pluginName);
386386

387-
configJSON = mergeConfigFragment(configJSON, pluginJson);
387+
config = mergeConfigFragment(config, pluginJson);
388388
}
389389

390-
return configJSON;
390+
return config;
391391
}
392392

393393

@@ -585,7 +585,7 @@ function deepClone(json) {
585585
}
586586

587587
/**
588-
* Deep clone a ConfigJson, copying over any "live" gatherer or audit that
588+
* Deep clone a config, copying over any "live" gatherer or audit that
589589
* wouldn't make the JSON round trip.
590590
* @param {LH.Config.Json} json
591591
* @return {LH.Config.Json}

core/config/config-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class ConfigPlugin {
215215
}
216216

217217
/**
218-
* Extracts and validates a ConfigJson from the provided plugin input, throwing
218+
* Extracts and validates a config from the provided plugin input, throwing
219219
* if it deviates from the expected object shape.
220220
* @param {unknown} pluginJson
221221
* @param {string} pluginName

core/config/config.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,44 @@ const defaultConfigPath = path.join(
3838
);
3939

4040
/**
41-
* @param {LH.Config.Json|undefined} configJSON
41+
* @param {LH.Config.Json|undefined} config
4242
* @param {{configPath?: string}} context
4343
* @return {{configWorkingCopy: LH.Config.Json, configDir?: string, configPath?: string}}
4444
*/
45-
function resolveWorkingCopy(configJSON, context) {
45+
function resolveWorkingCopy(config, context) {
4646
let {configPath} = context;
4747

4848
if (configPath && !path.isAbsolute(configPath)) {
4949
throw new Error('configPath must be an absolute path');
5050
}
5151

52-
if (!configJSON) {
53-
configJSON = defaultConfig;
52+
if (!config) {
53+
config = defaultConfig;
5454
configPath = defaultConfigPath;
5555
}
5656

5757
// The directory of the config path, if one was provided.
5858
const configDir = configPath ? path.dirname(configPath) : undefined;
5959

6060
return {
61-
configWorkingCopy: deepCloneConfigJson(configJSON),
61+
configWorkingCopy: deepCloneConfigJson(config),
6262
configPath,
6363
configDir,
6464
};
6565
}
6666

6767
/**
68-
* @param {LH.Config.Json} configJSON
68+
* @param {LH.Config.Json} config
6969
* @return {LH.Config.Json}
7070
*/
71-
function resolveExtensions(configJSON) {
72-
if (!configJSON.extends) return configJSON;
71+
function resolveExtensions(config) {
72+
if (!config.extends) return config;
7373

74-
if (configJSON.extends !== 'lighthouse:default') {
74+
if (config.extends !== 'lighthouse:default') {
7575
throw new Error('`lighthouse:default` is the only valid extension method.');
7676
}
7777

78-
const {artifacts, ...extensionJSON} = configJSON;
78+
const {artifacts, ...extensionJSON} = config;
7979
const defaultClone = deepCloneConfigJson(defaultConfig);
8080
const mergedConfig = mergeConfigFragment(defaultClone, extensionJSON);
8181

@@ -236,15 +236,15 @@ function resolveFakeNavigations(artifactDefns, settings) {
236236

237237
/**
238238
* @param {LH.Gatherer.GatherMode} gatherMode
239-
* @param {LH.Config.Json=} configJSON
239+
* @param {LH.Config.Json=} config
240240
* @param {LH.Flags=} flags
241241
* @return {Promise<{resolvedConfig: LH.Config.ResolvedConfig, warnings: string[]}>}
242242
*/
243-
async function initializeConfig(gatherMode, configJSON, flags = {}) {
243+
async function initializeConfig(gatherMode, config, flags = {}) {
244244
const status = {msg: 'Initialize config', id: 'lh:config'};
245245
log.time(status, 'verbose');
246246

247-
let {configWorkingCopy, configDir} = resolveWorkingCopy(configJSON, flags);
247+
let {configWorkingCopy, configDir} = resolveWorkingCopy(config, flags);
248248

249249
configWorkingCopy = resolveExtensions(configWorkingCopy);
250250
configWorkingCopy = await mergePlugins(configWorkingCopy, configDir, flags);

core/config/validation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ function isValidArtifactDependency(dependent, dependency) {
3939

4040
/**
4141
* Throws if pluginName is invalid or (somehow) collides with a category in the
42-
* configJSON being added to.
43-
* @param {LH.Config.Json} configJSON
42+
* config being added to.
43+
* @param {LH.Config.Json} config
4444
* @param {string} pluginName
4545
*/
46-
function assertValidPluginName(configJSON, pluginName) {
46+
function assertValidPluginName(config, pluginName) {
4747
if (!pluginName.startsWith('lighthouse-plugin-')) {
4848
throw new Error(`plugin name '${pluginName}' does not start with 'lighthouse-plugin-'`);
4949
}
5050

51-
if (configJSON.categories?.[pluginName]) {
51+
if (config.categories?.[pluginName]) {
5252
throw new Error(`plugin name '${pluginName}' not allowed because it is the id of a category already found in config`); // eslint-disable-line max-len
5353
}
5454
}

core/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ import {navigationGather} from './gather/navigation-runner.js';
3737
* @param {string=} url The URL to test. Optional if running in auditMode.
3838
* @param {LH.Flags=} flags Optional settings for the Lighthouse run. If present,
3939
* they will override any settings in the config.
40-
* @param {LH.Config.Json=} configJSON Configuration for the Lighthouse run. If
40+
* @param {LH.Config.Json=} config Configuration for the Lighthouse run. If
4141
* not present, the default config is used.
4242
* @param {LH.Puppeteer.Page=} page
4343
* @return {Promise<LH.RunnerResult|undefined>}
4444
*/
45-
async function lighthouse(url, flags = {}, configJSON, page) {
46-
return navigation(page, url, {config: configJSON, flags});
45+
async function lighthouse(url, flags = {}, config, page) {
46+
return navigation(page, url, {config, flags});
4747
}
4848

4949
/**
@@ -53,17 +53,17 @@ async function lighthouse(url, flags = {}, configJSON, page) {
5353
* @param {string=} url The URL to test. Optional if running in auditMode.
5454
* @param {LH.Flags=} flags Optional settings for the Lighthouse run. If present,
5555
* they will override any settings in the config.
56-
* @param {LH.Config.Json=} configJSON Configuration for the Lighthouse run. If
56+
* @param {LH.Config.Json=} config Configuration for the Lighthouse run. If
5757
* not present, the default config is used.
5858
* @param {Connection=} userConnection
5959
* @return {Promise<LH.RunnerResult|undefined>}
6060
*/
61-
async function legacyNavigation(url, flags = {}, configJSON, userConnection) {
61+
async function legacyNavigation(url, flags = {}, config, userConnection) {
6262
// set logging preferences, assume quiet
6363
flags.logLevel = flags.logLevel || 'error';
6464
log.setLevel(flags.logLevel);
6565

66-
const resolvedConfig = await LegacyResolvedConfig.fromJson(configJSON, flags);
66+
const resolvedConfig = await LegacyResolvedConfig.fromJson(config, flags);
6767
const computedCache = new Map();
6868
const options = {resolvedConfig, computedCache};
6969
const connection = userConnection || new CriConnection(flags.port, flags.hostname);

0 commit comments

Comments
 (0)