Skip to content

Commit

Permalink
core: fix build-sample-reports (#13865)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Apr 19, 2022
1 parent 0fcdf96 commit af8f2f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
5 changes: 4 additions & 1 deletion build/build-sample-reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ const DIST = path.join(LH_ROOT, 'dist');
});

generateFlowReports();
})();
})().catch(err => {
console.error(err);
process.exit(1);
});

function generateFlowReports() {
const filenameToFlowResult = {
Expand Down
18 changes: 16 additions & 2 deletions lighthouse-core/fraggle-rock/gather/navigation-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
'use strict';

const puppeteer = require('puppeteer-core');
const log = require('lighthouse-logger');
const Driver = require('./driver.js');
const Runner = require('../../runner.js');
Expand Down Expand Up @@ -43,6 +44,9 @@ const NetworkRecords = require('../../computed/network-records.js');

/** @typedef {Omit<Parameters<typeof collectPhaseArtifacts>[0], 'phase'>} PhaseState */

const DEFAULT_HOSTNAME = '127.0.0.1';
const DEFAULT_PORT = 9222;

/**
* @param {{driver: Driver, config: LH.Config.FRConfig, options?: InternalOptions}} args
* @return {Promise<{baseArtifacts: LH.FRBaseArtifacts}>}
Expand Down Expand Up @@ -299,11 +303,11 @@ async function _cleanup({requestedUrl, driver, config}) {

/**
* @param {LH.NavigationRequestor|undefined} requestor
* @param {{page: LH.Puppeteer.Page, config?: LH.Config.Json, configContext?: LH.Config.FRContext}} options
* @param {{page?: LH.Puppeteer.Page, config?: LH.Config.Json, configContext?: LH.Config.FRContext}} options
* @return {Promise<LH.Gatherer.FRGatherResult>}
*/
async function navigationGather(requestor, options) {
const {page, configContext = {}} = options;
const {configContext = {}} = options;
log.setLevel(configContext.logLevel || 'error');

const {config} = initializeConfig(options.config, {...configContext, gatherMode: 'navigation'});
Expand All @@ -321,6 +325,16 @@ async function navigationGather(requestor, options) {
const runnerOptions = {config, computedCache};
const artifacts = await Runner.gather(
async () => {
let {page} = options;

// For navigation mode, we shouldn't connect to a browser in audit mode,
// therefore we connect to the browser in the gatherFn callback.
if (!page) {
const {hostname = DEFAULT_HOSTNAME, port = DEFAULT_PORT} = configContext;
const browser = await puppeteer.connect({browserURL: `http://${hostname}:${port}`});
page = await browser.newPage();
}

const driver = new Driver(page);
const context = {
driver,
Expand Down
11 changes: 2 additions & 9 deletions lighthouse-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
'use strict';

const puppeteer = require('puppeteer-core');
const Runner = require('./runner.js');
const log = require('lighthouse-logger');
const ChromeProtocol = require('./gather/connections/cri.js');
Expand All @@ -15,9 +14,6 @@ const fraggleRock = require('./fraggle-rock/api.js');

/** @typedef {import('./gather/connections/connection.js')} Connection */

const DEFAULT_HOSTNAME = '127.0.0.1';
const DEFAULT_PORT = 9222;

/*
* The relationship between these root modules:
*
Expand All @@ -42,15 +38,12 @@ const DEFAULT_PORT = 9222;
* @return {Promise<LH.RunnerResult|undefined>}
*/
async function lighthouse(url, flags = {}, configJSON, page) {
if (!page) {
const {hostname = DEFAULT_HOSTNAME, port = DEFAULT_PORT} = flags;
const browser = await puppeteer.connect({browserURL: `http://${hostname}:${port}`});
page = await browser.newPage();
}
const configContext = {
configPath: flags.configPath,
settingsOverrides: flags,
logLevel: flags.logLevel,
hostname: flags.hostname,
port: flags.port,
};
return fraggleRock.navigation(url, {page, config: configJSON, configContext});
}
Expand Down
2 changes: 2 additions & 0 deletions types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ declare module Config {
settingsOverrides?: SharedFlagsSettings & Pick<LH.Flags, 'plugins'>;
skipAboutBlank?: boolean;
logLevel?: string;
hostname?: string;
port?: number;
}

interface SharedPassNavigationJson {
Expand Down

0 comments on commit af8f2f0

Please sign in to comment.