From 5da0ed4254de2c1db7f184033225dafe3097796d Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Thu, 3 Oct 2019 16:41:20 -0400 Subject: [PATCH 1/4] core(gather): add new InitialHtml public artifact --- lighthouse-cli/test/smokehouse/dbw-config.js | 29 ------------------- .../dobetterweb/dbw-expectations.js | 1 + .../test/smokehouse/smoke-test-dfns.js | 2 +- lighthouse-core/config/default-config.js | 1 + types/artifacts.d.ts | 2 ++ 5 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 lighthouse-cli/test/smokehouse/dbw-config.js diff --git a/lighthouse-cli/test/smokehouse/dbw-config.js b/lighthouse-cli/test/smokehouse/dbw-config.js deleted file mode 100644 index 468dfe34494a..000000000000 --- a/lighthouse-cli/test/smokehouse/dbw-config.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @license Copyright 2017 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -/** - * Config file for running PWA smokehouse audits. - */ -module.exports = { - extends: 'lighthouse:default', - settings: { - onlyCategories: [ - 'best-practices', - ], - onlyAudits: [ - 'dom-size', - 'render-blocking-resources', - 'errors-in-console', - 'efficient-animated-content', - 'apple-touch-icon', // pull in apple touch icon to test `LinkElements` - ], - }, - audits: [ - // Test the `ignoredPatterns` audit option. - {path: 'errors-in-console', options: {ignoredPatterns: ['An ignored error']}}, - ], -}; diff --git a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js index d9544efdec8d..759ac32b092f 100644 --- a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js +++ b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js @@ -20,6 +20,7 @@ const expectations = [ }, { id: 'wordpress', }], + InitialHtml: /^.*DoBetterWeb Mega Tester.*aggressive-promise-polyfill.*<\/html>\n$/s, LinkElements: [ { rel: 'stylesheet', diff --git a/lighthouse-cli/test/smokehouse/smoke-test-dfns.js b/lighthouse-cli/test/smokehouse/smoke-test-dfns.js index f5db176d9671..057cee12798c 100644 --- a/lighthouse-cli/test/smokehouse/smoke-test-dfns.js +++ b/lighthouse-cli/test/smokehouse/smoke-test-dfns.js @@ -39,7 +39,7 @@ const smokeTests = [{ }, { id: 'dbw', expectations: require('./dobetterweb/dbw-expectations.js'), - config: require('./dbw-config.js'), + config: require('../../../lighthouse-core/config/default-config.js'), batch: 'parallel-second', }, { id: 'redirects', diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index ce9800a5f9f9..ae2c7b69e7c9 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -136,6 +136,7 @@ const defaultConfig = { 'meta-elements', 'script-elements', 'iframe-elements', + 'initial-html', 'dobetterweb/appcache', 'dobetterweb/doctype', 'dobetterweb/domstats', diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index a3ff14433bff..46b817f87f0d 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -63,6 +63,8 @@ declare global { ConsoleMessages: Crdp.Log.EntryAddedEvent[]; /** All the iframe elements in the page.*/ IFrameElements: Artifacts.IFrameElement[]; + /** The contents of the initial HTML document request. */ + InitialHtml: string; /** Information on size and loading for all the images in the page. Natural size information for `picture` and CSS images is only available if the image was one of the largest 50 images. */ ImageElements: Artifacts.ImageElement[]; /** All the link elements on the page or equivalently declared in `Link` headers. @see https://html.spec.whatwg.org/multipage/links.html */ From 0f1db9658d29e93a8e338b416ba7de9095c4d384 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Thu, 3 Oct 2019 21:53:43 -0400 Subject: [PATCH 2/4] the actual gatherer, no big deal --- .../gather/gatherers/initial-html.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lighthouse-core/gather/gatherers/initial-html.js diff --git a/lighthouse-core/gather/gatherers/initial-html.js b/lighthouse-core/gather/gatherers/initial-html.js new file mode 100644 index 000000000000..fbaf0bae12da --- /dev/null +++ b/lighthouse-core/gather/gatherers/initial-html.js @@ -0,0 +1,30 @@ +/** + * @license Copyright 2019 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +const Gatherer = require('./gatherer.js'); +const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer.js'); + +/** + * Collects the content of the initially-requested html document. + */ +class InitialHtml extends Gatherer { + /** + * @param {LH.Gatherer.PassContext} passContext + * @param {LH.Gatherer.LoadData} loadData + * @return {Promise} + */ + async afterPass(passContext, loadData) { + const mainResource = NetworkAnalyzer.findMainDocument(loadData.networkRecords, passContext.url); + + const driver = passContext.driver; + const mainContent = await driver.getRequestContent(mainResource.requestId); + + return mainContent; + } +} + +module.exports = InitialHtml; From f9baa8580b5cb7d789c09af94e22eef6b631d2a5 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Mon, 7 Oct 2019 11:28:17 -0400 Subject: [PATCH 3/4] snapshots are bad and they should feel bad --- lighthouse-cli/test/cli/__snapshots__/index-test.js.snap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap index 3f92a647b8ba..0cffdc9e5acb 100644 --- a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap +++ b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap @@ -1147,6 +1147,9 @@ Object { Object { "path": "iframe-elements", }, + Object { + "path": "initial-html", + }, Object { "path": "dobetterweb/appcache", }, From a78ac3cb4513078f226dc564e6adb053a89a1007 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Tue, 15 Oct 2019 16:07:03 -0400 Subject: [PATCH 4/4] MainDocumentContent --- .../test/cli/__snapshots__/index-test.js.snap | 2 +- lighthouse-cli/test/smokehouse/dbw-config.js | 17 +++++++++++++++++ .../smokehouse/dobetterweb/dbw-expectations.js | 2 +- .../test/smokehouse/smoke-test-dfns.js | 2 +- lighthouse-core/config/default-config.js | 2 +- ...initial-html.js => main-document-content.js} | 12 +++++------- .../test/results/artifacts/artifacts.json | 5 +++-- types/artifacts.d.ts | 4 ++-- 8 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 lighthouse-cli/test/smokehouse/dbw-config.js rename lighthouse-core/gather/gatherers/{initial-html.js => main-document-content.js} (78%) diff --git a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap index 0cffdc9e5acb..f58b5096c6ee 100644 --- a/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap +++ b/lighthouse-cli/test/cli/__snapshots__/index-test.js.snap @@ -1148,7 +1148,7 @@ Object { "path": "iframe-elements", }, Object { - "path": "initial-html", + "path": "main-document-content", }, Object { "path": "dobetterweb/appcache", diff --git a/lighthouse-cli/test/smokehouse/dbw-config.js b/lighthouse-cli/test/smokehouse/dbw-config.js new file mode 100644 index 000000000000..319aa5280923 --- /dev/null +++ b/lighthouse-cli/test/smokehouse/dbw-config.js @@ -0,0 +1,17 @@ +/** + * @license Copyright 2017 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +/** + * Config file for running PWA smokehouse audits. + */ +module.exports = { + extends: 'lighthouse:default', + audits: [ + // Test the `ignoredPatterns` audit option. + {path: 'errors-in-console', options: {ignoredPatterns: ['An ignored error']}}, + ], +}; diff --git a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js index 759ac32b092f..d3de80f8d691 100644 --- a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js +++ b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js @@ -20,7 +20,7 @@ const expectations = [ }, { id: 'wordpress', }], - InitialHtml: /^.*DoBetterWeb Mega Tester.*aggressive-promise-polyfill.*<\/html>\n$/s, + MainDocumentContent: /^.*DoBetterWeb Mega Tester.*aggressive-promise-polyfill.*<\/html>\n$/s, LinkElements: [ { rel: 'stylesheet', diff --git a/lighthouse-cli/test/smokehouse/smoke-test-dfns.js b/lighthouse-cli/test/smokehouse/smoke-test-dfns.js index 057cee12798c..f5db176d9671 100644 --- a/lighthouse-cli/test/smokehouse/smoke-test-dfns.js +++ b/lighthouse-cli/test/smokehouse/smoke-test-dfns.js @@ -39,7 +39,7 @@ const smokeTests = [{ }, { id: 'dbw', expectations: require('./dobetterweb/dbw-expectations.js'), - config: require('../../../lighthouse-core/config/default-config.js'), + config: require('./dbw-config.js'), batch: 'parallel-second', }, { id: 'redirects', diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index ae2c7b69e7c9..1d5258ed38c6 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -136,7 +136,7 @@ const defaultConfig = { 'meta-elements', 'script-elements', 'iframe-elements', - 'initial-html', + 'main-document-content', 'dobetterweb/appcache', 'dobetterweb/doctype', 'dobetterweb/domstats', diff --git a/lighthouse-core/gather/gatherers/initial-html.js b/lighthouse-core/gather/gatherers/main-document-content.js similarity index 78% rename from lighthouse-core/gather/gatherers/initial-html.js rename to lighthouse-core/gather/gatherers/main-document-content.js index fbaf0bae12da..bb28df0a401f 100644 --- a/lighthouse-core/gather/gatherers/initial-html.js +++ b/lighthouse-core/gather/gatherers/main-document-content.js @@ -9,22 +9,20 @@ const Gatherer = require('./gatherer.js'); const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer.js'); /** - * Collects the content of the initially-requested html document. + * Collects the content of the main html document. */ -class InitialHtml extends Gatherer { +class MainDocumentContent extends Gatherer { /** * @param {LH.Gatherer.PassContext} passContext * @param {LH.Gatherer.LoadData} loadData - * @return {Promise} + * @return {Promise} */ async afterPass(passContext, loadData) { const mainResource = NetworkAnalyzer.findMainDocument(loadData.networkRecords, passContext.url); const driver = passContext.driver; - const mainContent = await driver.getRequestContent(mainResource.requestId); - - return mainContent; + return driver.getRequestContent(mainResource.requestId); } } -module.exports = InitialHtml; +module.exports = MainDocumentContent; diff --git a/lighthouse-core/test/results/artifacts/artifacts.json b/lighthouse-core/test/results/artifacts/artifacts.json index 28acd6c8f81c..f4c834b689cb 100644 --- a/lighthouse-core/test/results/artifacts/artifacts.json +++ b/lighthouse-core/test/results/artifacts/artifacts.json @@ -2113,5 +2113,6 @@ "name": "html", "systemId": "", "publicId": "" - } -} \ No newline at end of file + }, + "MainDocumentContent": "\n\n\n\n\n\nDoBetterWeb Mega Tester... Of Death\n\n\n\n\n\n\n\n\n\n\n\n \n \n \n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n
\n

Do better web tester page

\n Hi there!\n\n \n \n Facebook\n \n \n \n
\n\n
touchmove section
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +} diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index 46b817f87f0d..4ad5f03b0dd3 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -63,8 +63,8 @@ declare global { ConsoleMessages: Crdp.Log.EntryAddedEvent[]; /** All the iframe elements in the page.*/ IFrameElements: Artifacts.IFrameElement[]; - /** The contents of the initial HTML document request. */ - InitialHtml: string; + /** The contents of the main HTML document network resource. */ + MainDocumentContent: string; /** Information on size and loading for all the images in the page. Natural size information for `picture` and CSS images is only available if the image was one of the largest 50 images. */ ImageElements: Artifacts.ImageElement[]; /** All the link elements on the page or equivalently declared in `Link` headers. @see https://html.spec.whatwg.org/multipage/links.html */