From 41ed624d15c812a95cb51f071e8f766d2fd8ca3b Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 12:05:14 +0100 Subject: [PATCH 01/11] fix: skip crawlable audit when running onSuccess against deploy url --- src/lib/get-settings/get-settings.test.js | 5 +++++ src/lib/get-settings/index.js | 8 +++++++- src/lib/run-event/index.js | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/get-settings/get-settings.test.js b/src/lib/get-settings/get-settings.test.js index c0ea6c97..cf3248f1 100644 --- a/src/lib/get-settings/get-settings.test.js +++ b/src/lib/get-settings/get-settings.test.js @@ -34,6 +34,11 @@ describe('replacements', () => { expect(derivedSettings.settings.locale).toEqual('es'); }); + it('should add skipAudits if using a deployUrl', () => { + const derivedSettings = getSettings({ preset: 'desktop' }, true); + expect(derivedSettings.settings.skipAudits).toEqual(['seo/is-crawlable']); + }); + it('should error with incorrect syntax for process.env.SETTINGS', () => { process.env.SETTINGS = 'not json'; expect(getSettings).toThrow(/Invalid JSON/); diff --git a/src/lib/get-settings/index.js b/src/lib/get-settings/index.js index b9d48ecc..1fe9f36b 100644 --- a/src/lib/get-settings/index.js +++ b/src/lib/get-settings/index.js @@ -20,7 +20,7 @@ const mergeSettingsSources = (inputSettings = {}) => { return Object.assign({}, envSettings, inputSettings); }; -const getSettings = (inputSettings) => { +const getSettings = (inputSettings, isUsingDeployUrl) => { const settings = mergeSettingsSources(inputSettings); if (Object.keys(settings).length === 0) return; @@ -35,6 +35,12 @@ const getSettings = (inputSettings) => { derivedSettings.settings.locale = settings.locale; } + // If we are running against the Netlify deploy URL, the injected x-robots-tag will always cause the audit to fail, + // likely producing a false positive, so we skip in this case + if (isUsingDeployUrl) { + derivedSettings.settings.skipAudits = ['seo/is-crawlable']; + } + return derivedSettings; }; diff --git a/src/lib/run-event/index.js b/src/lib/run-event/index.js index 348f910d..0409e403 100644 --- a/src/lib/run-event/index.js +++ b/src/lib/run-event/index.js @@ -47,7 +47,7 @@ const runEvent = async ({ let errorMetadata = []; try { - const settings = getSettings(inputs?.settings); + const settings = getSettings(inputs?.settings, isOnSuccess); const allErrors = []; const data = []; From 0cdcdf6f35cd7d9e9e802ddbb72354461d9dd417 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 12:19:40 +0100 Subject: [PATCH 02/11] fix audit name --- src/lib/get-settings/get-settings.test.js | 2 +- src/lib/get-settings/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/get-settings/get-settings.test.js b/src/lib/get-settings/get-settings.test.js index cf3248f1..f1231b90 100644 --- a/src/lib/get-settings/get-settings.test.js +++ b/src/lib/get-settings/get-settings.test.js @@ -36,7 +36,7 @@ describe('replacements', () => { it('should add skipAudits if using a deployUrl', () => { const derivedSettings = getSettings({ preset: 'desktop' }, true); - expect(derivedSettings.settings.skipAudits).toEqual(['seo/is-crawlable']); + expect(derivedSettings.settings.skipAudits).toEqual(['is-crawlable']); }); it('should error with incorrect syntax for process.env.SETTINGS', () => { diff --git a/src/lib/get-settings/index.js b/src/lib/get-settings/index.js index 1fe9f36b..1d6649a9 100644 --- a/src/lib/get-settings/index.js +++ b/src/lib/get-settings/index.js @@ -38,7 +38,7 @@ const getSettings = (inputSettings, isUsingDeployUrl) => { // If we are running against the Netlify deploy URL, the injected x-robots-tag will always cause the audit to fail, // likely producing a false positive, so we skip in this case if (isUsingDeployUrl) { - derivedSettings.settings.skipAudits = ['seo/is-crawlable']; + derivedSettings.settings.skipAudits = ['is-crawlable']; } return derivedSettings; From f42d1389bc89b757f60ad17b38e54f60b08b65de Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 12:28:51 +0100 Subject: [PATCH 03/11] log the settings for debugging --- src/lib/run-event/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/run-event/index.js b/src/lib/run-event/index.js index 0409e403..e92d55c0 100644 --- a/src/lib/run-event/index.js +++ b/src/lib/run-event/index.js @@ -49,6 +49,8 @@ const runEvent = async ({ try { const settings = getSettings(inputs?.settings, isOnSuccess); + console.log('Configured settings:', settings); + const allErrors = []; const data = []; From b403d03176b121d366c269acfadcdbbf82ad47e9 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 12:33:34 +0100 Subject: [PATCH 04/11] always include the skip audit setting --- src/lib/get-settings/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/get-settings/index.js b/src/lib/get-settings/index.js index 1d6649a9..27bed533 100644 --- a/src/lib/get-settings/index.js +++ b/src/lib/get-settings/index.js @@ -22,7 +22,11 @@ const mergeSettingsSources = (inputSettings = {}) => { const getSettings = (inputSettings, isUsingDeployUrl) => { const settings = mergeSettingsSources(inputSettings); - if (Object.keys(settings).length === 0) return; + if (Object.keys(settings).length === 0) { + return isUsingDeployUrl + ? undefined + : { settings: { skipAudits: ['is-crawlable'] } }; + } // Set a base-level config based on the preset input value // (desktop is currently the only supported option) From 34b477066f3bd0a1df502453a9ecfe8f2866ef43 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 13:44:34 +0100 Subject: [PATCH 05/11] try directly adding to runauditwithurl --- src/lib/get-settings/index.js | 6 +----- src/lib/run-audit-with-url/index.js | 9 ++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/get-settings/index.js b/src/lib/get-settings/index.js index 27bed533..1d6649a9 100644 --- a/src/lib/get-settings/index.js +++ b/src/lib/get-settings/index.js @@ -22,11 +22,7 @@ const mergeSettingsSources = (inputSettings = {}) => { const getSettings = (inputSettings, isUsingDeployUrl) => { const settings = mergeSettingsSources(inputSettings); - if (Object.keys(settings).length === 0) { - return isUsingDeployUrl - ? undefined - : { settings: { skipAudits: ['is-crawlable'] } }; - } + if (Object.keys(settings).length === 0) return; // Set a base-level config based on the preset input value // (desktop is currently the only supported option) diff --git a/src/lib/run-audit-with-url/index.js b/src/lib/run-audit-with-url/index.js index fde0e3b4..a5831013 100644 --- a/src/lib/run-audit-with-url/index.js +++ b/src/lib/run-audit-with-url/index.js @@ -7,7 +7,14 @@ const runAuditWithUrl = async ({ path = '', url, thresholds, settings }) => { const getResults = async () => { const fullPath = path ? `${url}/${path}` : url; - const results = await runLighthouse(browserPath, fullPath, settings); + console.log('Running lighthouse with settings', { + ...settings, + skipAudits: ['is-crawlable'], + }); + const results = await runLighthouse(browserPath, fullPath, { + ...settings, + skipAudits: ['is-crawlable'], + }); try { return { results }; From 1b291492aaebef8d00f70bc05a853580259f7bd7 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 13:44:49 +0100 Subject: [PATCH 06/11] remove outdated test --- src/lib/get-settings/get-settings.test.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/lib/get-settings/get-settings.test.js b/src/lib/get-settings/get-settings.test.js index f1231b90..c0ea6c97 100644 --- a/src/lib/get-settings/get-settings.test.js +++ b/src/lib/get-settings/get-settings.test.js @@ -34,11 +34,6 @@ describe('replacements', () => { expect(derivedSettings.settings.locale).toEqual('es'); }); - it('should add skipAudits if using a deployUrl', () => { - const derivedSettings = getSettings({ preset: 'desktop' }, true); - expect(derivedSettings.settings.skipAudits).toEqual(['is-crawlable']); - }); - it('should error with incorrect syntax for process.env.SETTINGS', () => { process.env.SETTINGS = 'not json'; expect(getSettings).toThrow(/Invalid JSON/); From 15ab9b0fd76d887f7472b84ca438041332d9e051 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 13:51:36 +0100 Subject: [PATCH 07/11] empty object --- src/lib/run-audit-with-url/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/run-audit-with-url/index.js b/src/lib/run-audit-with-url/index.js index a5831013..fc248910 100644 --- a/src/lib/run-audit-with-url/index.js +++ b/src/lib/run-audit-with-url/index.js @@ -1,7 +1,12 @@ import { formatResults } from '../../format.js'; import { runLighthouse, getBrowserPath } from '../../run-lighthouse.js'; -const runAuditWithUrl = async ({ path = '', url, thresholds, settings }) => { +const runAuditWithUrl = async ({ + path = '', + url, + thresholds, + settings = {}, +}) => { try { const browserPath = await getBrowserPath(); From 79fc335774e8e2e8b801c9295d6e7121daa3d592 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 13:57:32 +0100 Subject: [PATCH 08/11] default to fullconfig, adding crawlable setting --- src/lib/get-settings/index.js | 2 +- src/lib/run-audit-with-url/index.js | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/lib/get-settings/index.js b/src/lib/get-settings/index.js index 1d6649a9..c382441e 100644 --- a/src/lib/get-settings/index.js +++ b/src/lib/get-settings/index.js @@ -22,7 +22,7 @@ const mergeSettingsSources = (inputSettings = {}) => { const getSettings = (inputSettings, isUsingDeployUrl) => { const settings = mergeSettingsSources(inputSettings); - if (Object.keys(settings).length === 0) return; + // if (Object.keys(settings).length === 0) return; // Set a base-level config based on the preset input value // (desktop is currently the only supported option) diff --git a/src/lib/run-audit-with-url/index.js b/src/lib/run-audit-with-url/index.js index fc248910..a6debc05 100644 --- a/src/lib/run-audit-with-url/index.js +++ b/src/lib/run-audit-with-url/index.js @@ -12,14 +12,8 @@ const runAuditWithUrl = async ({ const getResults = async () => { const fullPath = path ? `${url}/${path}` : url; - console.log('Running lighthouse with settings', { - ...settings, - skipAudits: ['is-crawlable'], - }); - const results = await runLighthouse(browserPath, fullPath, { - ...settings, - skipAudits: ['is-crawlable'], - }); + console.log('Running lighthouse with settings', settings); + const results = await runLighthouse(browserPath, fullPath, settings); try { return { results }; From 160be4a07e5f7236b0c7a0ab009f7af462ed5329 Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 14:09:04 +0100 Subject: [PATCH 09/11] tidy up log messages --- src/lib/get-settings/index.js | 1 - src/lib/run-audit-with-url/index.js | 8 +------- src/lib/run-event/index.js | 2 -- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/lib/get-settings/index.js b/src/lib/get-settings/index.js index c382441e..8c7fcc9a 100644 --- a/src/lib/get-settings/index.js +++ b/src/lib/get-settings/index.js @@ -22,7 +22,6 @@ const mergeSettingsSources = (inputSettings = {}) => { const getSettings = (inputSettings, isUsingDeployUrl) => { const settings = mergeSettingsSources(inputSettings); - // if (Object.keys(settings).length === 0) return; // Set a base-level config based on the preset input value // (desktop is currently the only supported option) diff --git a/src/lib/run-audit-with-url/index.js b/src/lib/run-audit-with-url/index.js index a6debc05..fde0e3b4 100644 --- a/src/lib/run-audit-with-url/index.js +++ b/src/lib/run-audit-with-url/index.js @@ -1,18 +1,12 @@ import { formatResults } from '../../format.js'; import { runLighthouse, getBrowserPath } from '../../run-lighthouse.js'; -const runAuditWithUrl = async ({ - path = '', - url, - thresholds, - settings = {}, -}) => { +const runAuditWithUrl = async ({ path = '', url, thresholds, settings }) => { try { const browserPath = await getBrowserPath(); const getResults = async () => { const fullPath = path ? `${url}/${path}` : url; - console.log('Running lighthouse with settings', settings); const results = await runLighthouse(browserPath, fullPath, settings); try { diff --git a/src/lib/run-event/index.js b/src/lib/run-event/index.js index e92d55c0..0409e403 100644 --- a/src/lib/run-event/index.js +++ b/src/lib/run-event/index.js @@ -49,8 +49,6 @@ const runEvent = async ({ try { const settings = getSettings(inputs?.settings, isOnSuccess); - console.log('Configured settings:', settings); - const allErrors = []; const data = []; From 9227f13e80c44c6c310b5cad52f36214f30c182f Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 14:22:09 +0100 Subject: [PATCH 10/11] fix spec --- src/lib/get-settings/get-settings.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/get-settings/get-settings.test.js b/src/lib/get-settings/get-settings.test.js index c0ea6c97..33af4fe5 100644 --- a/src/lib/get-settings/get-settings.test.js +++ b/src/lib/get-settings/get-settings.test.js @@ -1,8 +1,10 @@ import getSettings from './index.js'; describe('replacements', () => { - it('should return nothing with no settings set', () => { - expect(getSettings()).toEqual(undefined); + it('should return the default config with no settings set', () => { + const derivedSettings = getSettings(); + expect(derivedSettings.extends).toEqual('lighthouse:default'); + expect(derivedSettings.settings).toEqual({}); }); it('should return a template config with preset set to desktop', () => { From a218e36e3b8b20605ff2b3a1812f9d943967314a Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Mon, 21 Oct 2024 14:22:43 +0100 Subject: [PATCH 11/11] add new spec --- src/lib/get-settings/get-settings.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/get-settings/get-settings.test.js b/src/lib/get-settings/get-settings.test.js index 33af4fe5..4a80931f 100644 --- a/src/lib/get-settings/get-settings.test.js +++ b/src/lib/get-settings/get-settings.test.js @@ -36,6 +36,11 @@ describe('replacements', () => { expect(derivedSettings.settings.locale).toEqual('es'); }); + it('should skip is-crawlable audit when using deployUrl', () => { + const derivedSettings = getSettings({}, true); + expect(derivedSettings.settings.skipAudits).toEqual(['is-crawlable']); + }); + it('should error with incorrect syntax for process.env.SETTINGS', () => { process.env.SETTINGS = 'not json'; expect(getSettings).toThrow(/Invalid JSON/);