Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: use resolvedConfig to name every resolved config #14600

Merged
merged 7 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions clients/test/lightrider/lightrider-entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ describe('lightrider-entry', () => {
const url = 'https://example.com';

await runLighthouseInLR(mockConnection, url, {}, {});
const config = runStub.mock.calls[0][1].config;
assert.equal(config.settings.channel, 'lr');
const resolvedConfig = runStub.mock.calls[0][1].resolvedConfig;
assert.equal(resolvedConfig.settings.channel, 'lr');

runStub.mockRestore();
});
Expand All @@ -79,8 +79,8 @@ describe('lightrider-entry', () => {

const lrDevice = 'desktop';
await runLighthouseInLR(mockConnection, url, {}, {lrDevice});
const config = runStub.mock.calls[0][1].config;
assert.equal(config.settings.formFactor, 'desktop');
const resolvedConfig = runStub.mock.calls[0][1].resolvedConfig;
assert.equal(resolvedConfig.settings.formFactor, 'desktop');

runStub.mockRestore();
});
Expand All @@ -93,8 +93,8 @@ describe('lightrider-entry', () => {

const lrDevice = 'mobile';
await runLighthouseInLR(mockConnection, url, {}, {lrDevice});
const config = runStub.mock.calls[0][1].config;
assert.equal(config.settings.formFactor, 'mobile');
const resolvedConfig = runStub.mock.calls[0][1].resolvedConfig;
assert.equal(resolvedConfig.settings.formFactor, 'mobile');

runStub.mockRestore();
});
Expand All @@ -112,9 +112,9 @@ describe('lightrider-entry', () => {
},
};
await runLighthouseInLR(mockConnection, url, {}, {configOverride});
const config = runStub.mock.calls[0][1].config;
assert.equal(config.settings.onlyAudits.length, 1);
assert.equal(config.settings.onlyAudits[0], 'network-requests');
const resolvedConfig = runStub.mock.calls[0][1].resolvedConfig;
assert.equal(resolvedConfig.settings.onlyAudits.length, 1);
assert.equal(resolvedConfig.settings.onlyAudits[0], 'network-requests');

runStub.mockRestore();
});
Expand Down
34 changes: 17 additions & 17 deletions core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function resolveFakeNavigations(artifactDefns, settings) {
* @param {LH.Gatherer.GatherMode} gatherMode
* @param {LH.Config.Json=} configJSON
* @param {LH.Flags=} flags
* @return {Promise<{config: LH.Config.FRConfig, warnings: string[]}>}
* @return {Promise<{resolvedConfig: LH.Config.FRConfig, warnings: string[]}>}
*/
async function initializeConfig(gatherMode, configJSON, flags = {}) {
const status = {msg: 'Initialize config', id: 'lh:config'};
Expand All @@ -257,7 +257,7 @@ async function initializeConfig(gatherMode, configJSON, flags = {}) {
const navigations = resolveFakeNavigations(artifacts, settings);

/** @type {LH.Config.FRConfig} */
let config = {
let resolvedConfig = {
artifacts,
navigations,
audits: await resolveAuditsToDefns(configWorkingCopy.audits, configDir),
Expand All @@ -266,43 +266,43 @@ async function initializeConfig(gatherMode, configJSON, flags = {}) {
settings,
};

const {warnings} = assertValidConfig(config);
const {warnings} = assertValidConfig(resolvedConfig);

config = filterConfigByGatherMode(config, gatherMode);
config = filterConfigByExplicitFilters(config, settings);
resolvedConfig = filterConfigByGatherMode(resolvedConfig, gatherMode);
resolvedConfig = filterConfigByExplicitFilters(resolvedConfig, settings);

log.timeEnd(status);
return {config, warnings};
return {resolvedConfig, warnings};
}

/**
* @param {LH.Config.FRConfig} config
* @param {LH.Config.FRConfig} resolvedConfig
* @return {string}
*/
function getConfigDisplayString(config) {
function getConfigDisplayString(resolvedConfig) {
/** @type {LH.Config.FRConfig} */
const jsonConfig = JSON.parse(JSON.stringify(config));
const resolvedConfigCopy = JSON.parse(JSON.stringify(resolvedConfig));

if (jsonConfig.navigations) {
for (const navigation of jsonConfig.navigations) {
if (resolvedConfigCopy.navigations) {
for (const navigation of resolvedConfigCopy.navigations) {
for (let i = 0; i < navigation.artifacts.length; ++i) {
// @ts-expect-error Breaking the Config.AnyArtifactDefn type.
navigation.artifacts[i] = navigation.artifacts[i].id;
}
}
}

if (jsonConfig.artifacts) {
for (const artifactDefn of jsonConfig.artifacts) {
if (resolvedConfigCopy.artifacts) {
for (const artifactDefn of resolvedConfigCopy.artifacts) {
// @ts-expect-error Breaking the Config.AnyArtifactDefn type.
artifactDefn.gatherer = artifactDefn.gatherer.path;
// Dependencies are not declared on Config JSON
artifactDefn.dependencies = undefined;
}
}

if (jsonConfig.audits) {
for (const auditDefn of jsonConfig.audits) {
if (resolvedConfigCopy.audits) {
for (const auditDefn of resolvedConfigCopy.audits) {
// @ts-expect-error Breaking the Config.AuditDefn type.
auditDefn.implementation = undefined;
if (Object.keys(auditDefn.options).length === 0) {
Expand All @@ -313,9 +313,9 @@ function getConfigDisplayString(config) {
}

// Printed config is more useful with localized strings.
format.replaceIcuMessages(jsonConfig, jsonConfig.settings.locale);
format.replaceIcuMessages(resolvedConfigCopy, resolvedConfigCopy.settings.locale);

return JSON.stringify(jsonConfig, null, 2);
return JSON.stringify(resolvedConfigCopy, null, 2);
}

export {
Expand Down
42 changes: 22 additions & 20 deletions core/config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ function filterCategoriesByAvailableAudits(categories, availableAudits) {
/**
* Filters a config's artifacts, audits, and categories down to the set that supports the specified gather mode.
*
* @param {LH.Config.FRConfig} config
* @param {LH.Config.FRConfig} resolvedConfig
* @param {LH.Gatherer.GatherMode} mode
* @return {LH.Config.FRConfig}
*/
function filterConfigByGatherMode(config, mode) {
const artifacts = filterArtifactsByGatherMode(config.artifacts, mode);
const supportedAudits = filterAuditsByGatherMode(config.audits, mode);
function filterConfigByGatherMode(resolvedConfig, mode) {
const artifacts = filterArtifactsByGatherMode(resolvedConfig.artifacts, mode);
const supportedAudits = filterAuditsByGatherMode(resolvedConfig.audits, mode);
const audits = filterAuditsByAvailableArtifacts(supportedAudits, artifacts || []);
const supportedCategories = filterCategoriesByGatherMode(config.categories, mode);
const supportedCategories = filterCategoriesByGatherMode(resolvedConfig.categories, mode);
const categories = filterCategoriesByAvailableAudits(supportedCategories, audits || []);

return {
...config,
...resolvedConfig,
artifacts,
audits,
categories,
Expand All @@ -280,22 +280,22 @@ function filterConfigByGatherMode(config, mode) {
* Filters a config's artifacts, audits, and categories down to the requested set.
* Skip audits overrides inclusion via `onlyAudits`/`onlyCategories`.
*
* @param {LH.Config.FRConfig} config
* @param {LH.Config.FRConfig} resolvedConfig
* @param {Pick<LH.Config.Settings, 'onlyAudits'|'onlyCategories'|'skipAudits'>} filters
* @return {LH.Config.FRConfig}
*/
function filterConfigByExplicitFilters(config, filters) {
function filterConfigByExplicitFilters(resolvedConfig, filters) {
const {onlyAudits, onlyCategories, skipAudits} = filters;

warnOnUnknownOnlyCategories(config.categories, onlyCategories);
warnOnUnknownOnlyCategories(resolvedConfig.categories, onlyCategories);

let baseAuditIds = getAuditIdsInCategories(config.categories, undefined);
let baseAuditIds = getAuditIdsInCategories(resolvedConfig.categories, undefined);
if (onlyCategories) {
baseAuditIds = getAuditIdsInCategories(config.categories, onlyCategories);
baseAuditIds = getAuditIdsInCategories(resolvedConfig.categories, onlyCategories);
} else if (onlyAudits) {
baseAuditIds = new Set();
} else if (!config.categories || !Object.keys(config.categories).length) {
baseAuditIds = new Set(config.audits?.map(audit => audit.implementation.meta.id));
} else if (!resolvedConfig.categories || !Object.keys(resolvedConfig.categories).length) {
baseAuditIds = new Set(resolvedConfig.audits?.map(audit => audit.implementation.meta.id));
}

const auditIdsToKeep = new Set(
Expand All @@ -306,17 +306,19 @@ function filterConfigByExplicitFilters(config, filters) {
].filter(auditId => !skipAudits || !skipAudits.includes(auditId))
);

const audits = auditIdsToKeep.size && config.audits ?
config.audits.filter(audit => auditIdsToKeep.has(audit.implementation.meta.id)) :
config.audits;
const audits = auditIdsToKeep.size && resolvedConfig.audits ?
resolvedConfig.audits.filter(audit => auditIdsToKeep.has(audit.implementation.meta.id)) :
resolvedConfig.audits;

const availableCategories = filterCategoriesByAvailableAudits(config.categories, audits || []);
const availableCategories =
filterCategoriesByAvailableAudits(resolvedConfig.categories, audits || []);
const categories = filterCategoriesByExplicitFilters(availableCategories, onlyCategories);
const artifacts = filterArtifactsByAvailableAudits(config.artifacts, audits);
const navigations = filterNavigationsByAvailableArtifacts(config.navigations, artifacts || []);
const artifacts = filterArtifactsByAvailableAudits(resolvedConfig.artifacts, audits);
const navigations =
filterNavigationsByAvailableArtifacts(resolvedConfig.navigations, artifacts || []);

return {
...config,
...resolvedConfig,
artifacts,
navigations,
audits,
Expand Down
14 changes: 7 additions & 7 deletions core/config/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,22 @@ function assertArtifactTopologicalOrder(navigations) {
}

/**
* @param {LH.Config.FRConfig} config
* @param {LH.Config.FRConfig} resolvedConfig
* @return {{warnings: string[]}}
*/
function assertValidConfig(config) {
const {warnings} = assertValidFRNavigations(config.navigations);
function assertValidConfig(resolvedConfig) {
const {warnings} = assertValidFRNavigations(resolvedConfig.navigations);

for (const artifactDefn of config.artifacts || []) {
for (const artifactDefn of resolvedConfig.artifacts || []) {
assertValidFRGatherer(artifactDefn.gatherer);
}

for (const auditDefn of config.audits || []) {
for (const auditDefn of resolvedConfig.audits || []) {
assertValidAudit(auditDefn);
}

assertValidCategories(config.categories, config.audits, config.groups);
assertValidSettings(config.settings);
assertValidCategories(resolvedConfig.categories, resolvedConfig.audits, resolvedConfig.groups);
assertValidSettings(resolvedConfig.settings);
return {warnings};
}

Expand Down
6 changes: 3 additions & 3 deletions core/gather/base-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
} from './driver/environment.js';

/**
* @param {LH.Config.FRConfig} config
* @param {LH.Config.FRConfig} resolvedConfig
* @param {LH.Gatherer.FRTransitionalDriver} driver
* @param {{gatherMode: LH.Gatherer.GatherMode}} context
* @return {Promise<LH.BaseArtifacts>}
*/
async function getBaseArtifacts(config, driver, context) {
async function getBaseArtifacts(resolvedConfig, driver, context) {
const BenchmarkIndex = await getBenchmarkIndex(driver.executionContext);
const {userAgent} = await getBrowserVersion(driver.defaultSession);

Expand All @@ -26,7 +26,7 @@ async function getBaseArtifacts(config, driver, context) {
fetchTime: new Date().toJSON(),
Timing: [],
LighthouseRunWarnings: [],
settings: config.settings,
settings: resolvedConfig.settings,
// Environment artifacts that can always be computed.
BenchmarkIndex,
HostUserAgent: userAgent,
Expand Down
Loading