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

clients(lr): include flag for ignoring bad page status code #15764

Merged
merged 8 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions clients/lightrider/lightrider-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ async function getPageFromConnection(connection) {
* @param {any} connection
* @param {string} url
* @param {LH.Flags} flags Lighthouse flags
* @param {{lrDevice?: 'desktop'|'mobile', categoryIDs?: Array<string>, logAssets: boolean, configOverride?: LH.Config}} lrOpts Options coming from Lightrider
* @param {{lrDevice?: 'desktop'|'mobile', categoryIDs?: Array<string>, logAssets: boolean, configOverride?: LH.Config, ignoreStatusCode?: boolean}} lrOpts Options coming from Lightrider
* @return {Promise<string>}
*/
async function runLighthouseInLR(connection, url, flags, lrOpts) {
const {lrDevice, categoryIDs, logAssets, configOverride} = lrOpts;
const {lrDevice, categoryIDs, logAssets, configOverride, ignoreStatusCode} = lrOpts;

// Certain fixes need to kick in under LR, see https://github.com/GoogleChrome/lighthouse/issues/5839
global.isLightrider = true;
Expand All @@ -96,8 +96,9 @@ async function runLighthouseInLR(connection, url, flags, lrOpts) {
config = configOverride;
} else {
config = lrDevice === 'desktop' ? LR_PRESETS.desktop : LR_PRESETS.mobile;
config.settings = config.settings || {};
config.settings.ignoreStatusCode = ignoreStatusCode;
if (categoryIDs) {
config.settings = config.settings || {};
config.settings.onlyCategories = categoryIDs;
}
}
Expand Down
13 changes: 13 additions & 0 deletions clients/test/lightrider/lightrider-entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ describe('lightrider-entry', () => {
runStub.mockRestore();
});

it('disables 404 with flag', async () => {
const runStub = jestMock.spyOn(Runner, 'gather');

const url = 'https://example.com';

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

runStub.mockRestore();
});

it('overrides the default config when one is provided', async () => {
const runStub = jestMock.spyOn(Runner, 'gather');

Expand Down
5 changes: 4 additions & 1 deletion proto/lighthouse-result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ message LighthouseResult {
map<string, CategoryGroup> category_groups = 11;

// Message containing the configuration settings for the LH run
// Next ID: 10
// Next ID: 11
message ConfigSettings {
// The possible form factors an audit can be run in.
// This enum served the emulated_form_factor field, but in v7, that field
Expand Down Expand Up @@ -203,6 +203,9 @@ message LighthouseResult {

// Screen emulation properties (width, height, dpr, mobile viewport) to apply or an object of `{disabled: true}` if Lighthouse should avoid applying screen emulation. If either emulation is applied outside of Lighthouse, or it's being run on a mobile device, it typically should be set to disabled. For desktop, we recommend applying consistent desktop screen emulation.
ScreenEmulation screen_emulation = 9;

// Indicating whether Lighthouse should ignore status codes.
bool ignore_status_code = 10;
adrianaixba marked this conversation as resolved.
Show resolved Hide resolved
}

// The settings that were used to run this audit
Expand Down
Loading