Skip to content

Commit

Permalink
core: update residual usages of legacy runner
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Jul 6, 2023
1 parent c0efe60 commit ebcbe78
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 40 deletions.
13 changes: 3 additions & 10 deletions core/config/config-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {getModuleDirectory} from '../../esm-utils.js';

const require = createRequire(import.meta.url);

/** @typedef {typeof import('../gather/gatherers/gatherer.js').Gatherer} GathererConstructor */
/** @typedef {typeof import('../gather/base-gatherer.js').default} GathererConstructor */
/** @typedef {typeof import('../audits/audit.js')['Audit']} Audit */
/** @typedef {InstanceType<GathererConstructor>} Gatherer */

Expand Down Expand Up @@ -160,7 +160,7 @@ function mergeConfigFragmentArrayByKey(baseArray, extensionArray, keyFn) {
* - {instance: myGathererInstance}
*
* @param {LH.Config.GathererJson} gatherer
* @return {{instance?: Gatherer, implementation?: GathererConstructor, path?: string}} passes
* @return {{instance?: Gatherer, implementation?: GathererConstructor, path?: string}}
*/
function expandGathererShorthand(gatherer) {
if (typeof gatherer === 'string') {
Expand All @@ -178,7 +178,7 @@ function expandGathererShorthand(gatherer) {
} else if (typeof gatherer === 'function') {
// just GathererConstructor
return {implementation: gatherer};
} else if (gatherer && typeof gatherer.beforePass === 'function') {
} else if (gatherer && typeof gatherer.getArtifact === 'function') {
// just GathererInstance
return {instance: gatherer};
} else {
Expand Down Expand Up @@ -595,13 +595,6 @@ function deepCloneConfigJson(json) {

// Copy arrays that could contain non-serializable properties to allow for programmatic
// injection of audit and gatherer implementations.
if (Array.isArray(cloned.passes) && Array.isArray(json.passes)) {
for (let i = 0; i < cloned.passes.length; i++) {
const pass = cloned.passes[i];
pass.gatherers = (json.passes[i].gatherers || []).map(gatherer => shallowClone(gatherer));
}
}

if (Array.isArray(json.audits)) {
cloned.audits = json.audits.map(audit => shallowClone(audit));
}
Expand Down
14 changes: 7 additions & 7 deletions core/config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ function filterAuditsByGatherMode(audits, mode) {
/**
* Optional `supportedModes` property can explicitly exclude a category even if some audits are available.
*
* @param {LH.Config.LegacyResolvedConfig['categories']} categories
* @param {LH.Config.ResolvedConfig['categories']} categories
* @param {LH.Gatherer.GatherMode} mode
* @return {LH.Config.LegacyResolvedConfig['categories']}
* @return {LH.Config.ResolvedConfig['categories']}
*/
function filterCategoriesByGatherMode(categories, mode) {
if (!categories) return null;
Expand All @@ -186,9 +186,9 @@ function filterCategoriesByGatherMode(categories, mode) {
/**
* Filters a categories object and their auditRefs down to the specified category ids.
*
* @param {LH.Config.LegacyResolvedConfig['categories']} categories
* @param {LH.Config.ResolvedConfig['categories']} categories
* @param {string[] | null | undefined} onlyCategories
* @return {LH.Config.LegacyResolvedConfig['categories']}
* @return {LH.Config.ResolvedConfig['categories']}
*/
function filterCategoriesByExplicitFilters(categories, onlyCategories) {
if (!categories || !onlyCategories) return categories;
Expand All @@ -202,7 +202,7 @@ function filterCategoriesByExplicitFilters(categories, onlyCategories) {
* Logs a warning if any specified onlyCategory is not a known category that can
* be included.
*
* @param {LH.Config.LegacyResolvedConfig['categories']} allCategories
* @param {LH.Config.ResolvedConfig['categories']} allCategories
* @param {string[] | null} onlyCategories
* @return {void}
*/
Expand All @@ -220,9 +220,9 @@ function warnOnUnknownOnlyCategories(allCategories, onlyCategories) {
* Filters a categories object and their auditRefs down to the set that can be computed using
* only the specified audits.
*
* @param {LH.Config.LegacyResolvedConfig['categories']} categories
* @param {LH.Config.ResolvedConfig['categories']} categories
* @param {Array<LH.Config.AuditDefn>} availableAudits
* @return {LH.Config.LegacyResolvedConfig['categories']}
* @return {LH.Config.ResolvedConfig['categories']}
*/
function filterCategoriesByAvailableAudits(categories, availableAudits) {
if (!categories) return categories;
Expand Down
1 change: 0 additions & 1 deletion core/gather/gatherers/seo/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const MINIMAL_LEGIBLE_FONT_SIZE_PX = 12;
// limit number of protocol calls to make sure that gatherer doesn't take more than 1-2s
const MAX_NODES_SOURCE_RULE_FETCHED = 50; // number of nodes to fetch the source font-size rule

/** @typedef {import('../../../legacy/gather/driver.js')} Driver */
/** @typedef {LH.Artifacts.FontSize['analyzedFailingNodesData'][0]} NodeFontData */
/** @typedef {Map<number, {fontSize: number, textLength: number}>} BackendIdsToFontData */

Expand Down
2 changes: 1 addition & 1 deletion core/lib/navigation-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function getNonHtmlError(finalRecord) {
* Returns an error if the page load should be considered failed, e.g. from a
* main document request failure, a security issue, etc.
* @param {LH.LighthouseError|undefined} navigationError
* @param {{url: string, loadFailureMode: LH.Gatherer.PassContext['passConfig']['loadFailureMode'], networkRecords: Array<LH.Artifacts.NetworkRequest>, warnings: Array<string | LH.IcuMessage>}} context
* @param {{url: string, loadFailureMode: LH.Config.SharedPassNavigationJson['loadFailureMode'], networkRecords: Array<LH.Artifacts.NetworkRequest>, warnings: Array<string | LH.IcuMessage>}} context
* @return {LH.LighthouseError|undefined}
*/
function getPageLoadError(navigationError, context) {
Expand Down
35 changes: 14 additions & 21 deletions core/test/gather/fetcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,29 @@
*/

import {Fetcher} from '../../gather/fetcher.js';
import {Driver} from '../../legacy/gather/driver.js';
import {Connection} from '../../legacy/gather/connections/connection.js';
import {fnAny, mockCommands} from '../test-utils.js';
import {fnAny} from '../test-utils.js';
import {createMockSession} from './mock-driver.js';

const {createMockSendCommandFn} = mockCommands;

/** @type {Connection} */
let connectionStub;
/** @type {Driver} */
let driver;
let mockSession = createMockSession();
/** @type {Fetcher} */
let fetcher;

beforeEach(() => {
connectionStub = new Connection();
driver = new Driver(connectionStub);
fetcher = new Fetcher(driver.defaultSession);
mockSession = createMockSession();
fetcher = new Fetcher(mockSession.asSession());
});

describe('._readIOStream', () => {
it('reads contents of stream', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('IO.read', {data: 'Hello World!', eof: true, base64Encoded: false});

const data = await fetcher._readIOStream('1');
expect(data).toEqual('Hello World!');
});

it('combines multiple reads', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('IO.read', {data: 'Hello ', eof: false, base64Encoded: false})
.mockResponse('IO.read', {data: 'World', eof: false, base64Encoded: false})
.mockResponse('IO.read', {data: '!', eof: true, base64Encoded: false});
Expand All @@ -45,7 +38,7 @@ describe('._readIOStream', () => {

it('decodes if base64', async () => {
const buffer = Buffer.from('Hello World!').toString('base64');
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('IO.read', {data: buffer, eof: true, base64Encoded: true});

const data = await fetcher._readIOStream('1');
Expand All @@ -55,7 +48,7 @@ describe('._readIOStream', () => {
it('decodes multiple base64 reads', async () => {
const buffer1 = Buffer.from('Hello ').toString('base64');
const buffer2 = Buffer.from('World!').toString('base64');
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('IO.read', {data: buffer1, eof: false, base64Encoded: true})
.mockResponse('IO.read', {data: buffer2, eof: true, base64Encoded: true});

Expand All @@ -64,7 +57,7 @@ describe('._readIOStream', () => {
});

it('throws on timeout', async () => {
connectionStub.sendCommand = fnAny()
mockSession.sendCommand
.mockReturnValue(Promise.resolve({data: 'No stop', eof: false, base64Encoded: false}));

const dataPromise = fetcher._readIOStream('1', {timeout: 50});
Expand All @@ -84,7 +77,7 @@ describe('._fetchResourceOverProtocol', () => {
});

it('fetches a file', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: true, httpStatusCode: 200, stream: '1'},
Expand All @@ -95,7 +88,7 @@ describe('._fetchResourceOverProtocol', () => {
});

it('returns null when resource could not be fetched', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: false, httpStatusCode: 404},
Expand All @@ -106,7 +99,7 @@ describe('._fetchResourceOverProtocol', () => {
});

it('throws on timeout', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: false, httpStatusCode: 404},
Expand All @@ -117,7 +110,7 @@ describe('._fetchResourceOverProtocol', () => {
});

it('uses remaining time on _readIOStream', async () => {
connectionStub.sendCommand = createMockSendCommandFn()
mockSession.sendCommand
.mockResponse('Page.getFrameTree', {frameTree: {frame: {id: 'FRAME'}}})
.mockResponse('Network.loadNetworkResource', {
resource: {success: true, httpStatusCode: 200, stream: '1'},
Expand Down

0 comments on commit ebcbe78

Please sign in to comment.