From 3277b0bb29c32e76d1bae71cf7a7019ae4784e4d Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Fri, 5 May 2023 11:21:35 -0700 Subject: [PATCH 1/2] tests: remove most usages of `afterPass` --- .../gather/gatherers/accessibility-test.js | 2 +- .../gather/gatherers/cache-contents-test.js | 2 +- .../gather/gatherers/console-messages-test.js | 14 +- .../dobetterweb/optimized-images-test.js | 254 +++++++++--------- .../tags-blocking-first-paint-test.js | 172 ++++++------ .../gather/gatherers/global-listeners-test.js | 2 +- .../gather/gatherers/link-elements-test.js | 19 +- .../gather/gatherers/seo/font-size-test.js | 2 +- .../gatherers/viewport-dimensions-test.js | 2 +- core/test/network-records-to-devtools-log.js | 5 +- 10 files changed, 232 insertions(+), 242 deletions(-) diff --git a/core/test/gather/gatherers/accessibility-test.js b/core/test/gather/gatherers/accessibility-test.js index 4717b3a80cfe..3432e14b5b52 100644 --- a/core/test/gather/gatherers/accessibility-test.js +++ b/core/test/gather/gatherers/accessibility-test.js @@ -23,7 +23,7 @@ describe('Accessibility gatherer', () => { it('propagates error retrieving the results', () => { const error = 'There was an error.'; - return accessibilityGather.afterPass({ + return accessibilityGather.getArtifact({ driver: { executionContext: { async evaluate() { diff --git a/core/test/gather/gatherers/cache-contents-test.js b/core/test/gather/gatherers/cache-contents-test.js index fcc0f3db0c01..722a856dfc97 100644 --- a/core/test/gather/gatherers/cache-contents-test.js +++ b/core/test/gather/gatherers/cache-contents-test.js @@ -17,7 +17,7 @@ describe('Cache Contents gatherer', () => { }); it('throws an error when cache getter returns nothing', () => { - return cacheContentGather.afterPass({ + return cacheContentGather.getArtifact({ driver: { evaluateAsync() { return Promise.resolve(); diff --git a/core/test/gather/gatherers/console-messages-test.js b/core/test/gather/gatherers/console-messages-test.js index 92eb5f63cad7..057cb03e1a8c 100644 --- a/core/test/gather/gatherers/console-messages-test.js +++ b/core/test/gather/gatherers/console-messages-test.js @@ -65,7 +65,7 @@ describe('ConsoleMessages', () => { await consoleGatherer.beforePass(options); driver.defaultSession.fireForTest('Runtime.exceptionThrown', runtimeEx); - const artifact = await consoleGatherer.afterPass(options); + const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); assert.equal(artifact[0].source, 'exception'); @@ -107,7 +107,7 @@ describe('ConsoleMessages', () => { await consoleGatherer.beforePass(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleWarnEvent); - const artifact = await consoleGatherer.afterPass(options); + const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); assert.equal(artifact[0].source, 'console.warn'); @@ -139,7 +139,7 @@ describe('ConsoleMessages', () => { await consoleGatherer.beforePass(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleWarnEvent); - const artifact = await consoleGatherer.afterPass(options); + const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); assert.equal(artifact[0].source, 'console.warn'); @@ -263,7 +263,7 @@ describe('ConsoleMessages', () => { await consoleGatherer.beforePass(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleWarnEvent); - const artifact = await consoleGatherer.afterPass(options); + const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); assert.equal(artifact[0].source, 'console.warn'); @@ -321,7 +321,7 @@ describe('ConsoleMessages', () => { await consoleGatherer.beforePass(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleErrorEvent); - const artifact = await consoleGatherer.afterPass(options); + const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); assert.equal(artifact[0].source, 'console.error'); @@ -361,7 +361,7 @@ describe('ConsoleMessages', () => { await consoleGatherer.beforePass(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleLog); - const artifact = await consoleGatherer.afterPass(options); + const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 0); }); @@ -410,7 +410,7 @@ describe('ConsoleMessages', () => { driver.defaultSession.fireForTest('Log.entryAdded', logEntries[0]); driver.defaultSession.fireForTest('Log.entryAdded', logEntries[1]); - const artifact = await consoleGatherer.afterPass(options); + const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 2); diff --git a/core/test/gather/gatherers/dobetterweb/optimized-images-test.js b/core/test/gather/gatherers/dobetterweb/optimized-images-test.js index 1064ac6ac98e..f89870b73b33 100644 --- a/core/test/gather/gatherers/dobetterweb/optimized-images-test.js +++ b/core/test/gather/gatherers/dobetterweb/optimized-images-test.js @@ -5,109 +5,13 @@ */ import OptimizedImages from '../../../../gather/gatherers/dobetterweb/optimized-images.js'; -import {NetworkRequest} from '../../../../lib/network-request.js'; import {createMockContext} from '../../../gather/mock-driver.js'; - -let context = createMockContext(); -let optimizedImages; - -const traceData = { - networkRecords: [ - { - requestId: '1', - url: 'http://google.com/image.jpg', - mimeType: 'image/jpeg', - resourceSize: 10000000, - transferSize: 20000000, - resourceType: 'Image', - finished: true, - }, - { - requestId: '1', - url: 'http://google.com/transparent.png', - mimeType: 'image/png', - resourceSize: 11000, - transferSize: 20000, - resourceType: 'Image', - finished: true, - }, - { - requestId: '1', - url: 'http://google.com/image.bmp', - mimeType: 'image/bmp', - resourceSize: 12000, - transferSize: 9000, // bitmap was compressed another way - resourceType: 'Image', - finished: true, - }, - { - requestId: '1', - url: 'http://google.com/image.bmp', - mimeType: 'image/bmp', - resourceSize: 12000, - transferSize: 20000, - resourceType: 'Image', - finished: true, - }, - { - requestId: '1', - url: 'http://google.com/vector.svg', - mimeType: 'image/svg+xml', - resourceSize: 13000, - transferSize: 20000, - resourceType: 'Image', - finished: true, - }, - { - requestId: '1', - url: 'http://gmail.com/image.jpg', - mimeType: 'image/jpeg', - resourceSize: 15000, - transferSize: 20000, - resourceType: 'Image', - finished: true, - }, - { - requestId: '1', - url: 'http://gmail.com/image-oopif.jpg', - mimeType: 'image/jpeg', - resourceSize: 15000, - transferSize: 20000, - resourceType: 'Image', - finished: true, - sessionTargetType: 'iframe', // ignore for being an oopif - }, - { - requestId: '1', - url: 'data: image/jpeg ; base64 ,SgVcAT32587935321...', - mimeType: 'image/jpeg', - resourceType: 'Image', - resourceSize: 14000, - transferSize: 20000, - finished: true, - }, - { - requestId: '1', - url: 'http://google.com/big-image.bmp', - mimeType: 'image/bmp', - resourceType: 'Image', - resourceSize: 12000, - transferSize: 20000, - finished: false, // ignore for not finishing - }, - { - requestId: '1', - url: 'http://google.com/not-an-image.bmp', - mimeType: 'image/bmp', - resourceType: 'Document', // ignore for not really being an image - resourceSize: 12000, - transferSize: 20000, - finished: true, - }, - ].map((record) => Object.assign(new NetworkRequest(), record)), -}; +import {networkRecordsToDevtoolsLog} from '../../../network-records-to-devtools-log.js'; describe('Optimized images', () => { + let context = createMockContext(); + let optimizedImages; + // Reset the Gatherer before each test. beforeEach(() => { optimizedImages = new OptimizedImages(); @@ -117,10 +21,102 @@ describe('Optimized images', () => { const encodedSize = params.encoding === 'webp' ? 60 : 80; return Promise.resolve({encodedSize}); }); + + context.dependencies.DevtoolsLog = networkRecordsToDevtoolsLog([ + { + requestId: '1', + url: 'http://google.com/image.jpg', + mimeType: 'image/jpeg', + resourceSize: 10000000, + transferSize: 20000000, + resourceType: 'Image', + finished: true, + }, + { + requestId: '2', + url: 'http://google.com/transparent.png', + mimeType: 'image/png', + resourceSize: 11000, + transferSize: 20000, + resourceType: 'Image', + finished: true, + }, + { + requestId: '3', + url: 'http://google.com/image.bmp', + mimeType: 'image/bmp', + resourceSize: 12000, + transferSize: 9000, // bitmap was compressed another way + resourceType: 'Image', + finished: true, + }, + { + requestId: '4', + url: 'http://google.com/image.bmp', + mimeType: 'image/bmp', + resourceSize: 12000, + transferSize: 20000, + resourceType: 'Image', + finished: true, + }, + { + requestId: '5', + url: 'http://google.com/vector.svg', + mimeType: 'image/svg+xml', + resourceSize: 13000, + transferSize: 20000, + resourceType: 'Image', + finished: true, + }, + { + requestId: '6', + url: 'http://gmail.com/image.jpg', + mimeType: 'image/jpeg', + resourceSize: 15000, + transferSize: 20000, + resourceType: 'Image', + finished: true, + }, + { + requestId: '7', + url: 'http://gmail.com/image-oopif.jpg', + mimeType: 'image/jpeg', + resourceSize: 15000, + transferSize: 20000, + resourceType: 'Image', + finished: true, + sessionTargetType: 'iframe', // ignore for being an oopif + }, + { + requestId: '8', + url: 'data: image/jpeg ; base64 ,SgVcAT32587935321...', + mimeType: 'image/jpeg', + resourceType: 'Image', + resourceSize: 14000, + transferSize: 20000, + finished: true, + }, + { + requestId: '9', + url: 'http://google.com/big-image.bmp', + mimeType: 'image/bmp', + resourceType: 'Image', + finished: false, // ignore for not finishing + }, + { + requestId: '10', + url: 'http://google.com/not-an-image.bmp', + mimeType: 'image/bmp', + resourceType: 'Document', // ignore for not really being an image + resourceSize: 12000, + transferSize: 20000, + finished: true, + }, + ]); }); it('returns all images, sorted with sizes', async () => { - const artifact = await optimizedImages.afterPass(context, traceData); + const artifact = await optimizedImages.getArtifact(context); expect(artifact).toHaveLength(5); expect(artifact).toMatchObject([ { @@ -167,7 +163,7 @@ describe('Optimized images', () => { } }); - return optimizedImages.afterPass(context, traceData).then(artifact => { + return optimizedImages.getArtifact(context).then(artifact => { const failed = artifact.find(record => record.failed); expect(artifact).toHaveLength(5); @@ -176,40 +172,34 @@ describe('Optimized images', () => { }); it('handles non-standard mime types too', async () => { - const traceData = { - networkRecords: [ - { - requestId: '1', - url: 'http://google.com/image.bmp?x-ms', - mimeType: 'image/x-ms-bmp', - resourceSize: 12000, - transferSize: 0, - resourceType: 'Image', - finished: true, - }, - ].map((record) => Object.assign(new NetworkRequest(), record)), - }; - - const artifact = await optimizedImages.afterPass(context, traceData); + context.dependencies.DevtoolsLog = networkRecordsToDevtoolsLog([ + { + requestId: '1', + url: 'http://google.com/image.bmp?x-ms', + mimeType: 'image/x-ms-bmp', + resourceSize: 12000, + transferSize: 0, + resourceType: 'Image', + finished: true, + }, + ]); + const artifact = await optimizedImages.getArtifact(context); expect(artifact).toHaveLength(1); }); it('handles cached images', async () => { - const traceData = { - networkRecords: [ - { - requestId: '1', - url: 'http://google.com/image.jpg', - mimeType: 'image/jpeg', - resourceSize: 10000000, - transferSize: 0, - resourceType: 'Image', - finished: true, - }, - ].map((record) => Object.assign(new NetworkRequest(), record)), - }; - - const artifact = await optimizedImages.afterPass(context, traceData); + context.dependencies.DevtoolsLog = networkRecordsToDevtoolsLog([ + { + requestId: '1', + url: 'http://google.com/image.jpg', + mimeType: 'image/jpeg', + resourceSize: 10000000, + transferSize: 0, + resourceType: 'Image', + finished: true, + }, + ]); + const artifact = await optimizedImages.getArtifact(context); expect(artifact).toHaveLength(1); }); }); diff --git a/core/test/gather/gatherers/dobetterweb/tags-blocking-first-paint-test.js b/core/test/gather/gatherers/dobetterweb/tags-blocking-first-paint-test.js index 4e0f12e514fa..a2713c9de277 100644 --- a/core/test/gather/gatherers/dobetterweb/tags-blocking-first-paint-test.js +++ b/core/test/gather/gatherers/dobetterweb/tags-blocking-first-paint-test.js @@ -6,94 +6,91 @@ import TagsBlockingFirstPaint from '../../../../gather/gatherers/dobetterweb/tags-blocking-first-paint.js'; -import {NetworkRequest} from '../../../../lib/network-request.js'; import {createMockContext} from '../../../gather/mock-driver.js'; +import {networkRecordsToDevtoolsLog} from '../../../network-records-to-devtools-log.js'; let tagsBlockingFirstPaint; -const traceData = { - networkRecords: [ - { - url: 'http://google.com/css/style.css', - mimeType: 'text/css', - transferSize: 10, - networkRequestTime: 10, - networkEndTime: 10, - finished: true, - isLinkPreload: false, - initiator: {type: 'parser'}, - }, - { - url: 'http://google.com/wc/select.html', - mimeType: 'text/html', - transferSize: 11, - networkRequestTime: 11, - networkEndTime: 11, - finished: true, - isLinkPreload: false, - initiator: {type: 'other'}, - }, - { - url: 'http://google.com/js/app.json', - mimeType: 'application/json', - transferSize: 24, - networkRequestTime: 24, - networkEndTime: 24, - finished: true, - isLinkPreload: false, - initiator: {type: 'script'}, - }, - { - url: 'http://google.com/js/app.js', - mimeType: 'text/javascript', - transferSize: 12, - networkRequestTime: 12, - networkEndTime: 22, - finished: true, - isLinkPreload: false, - initiator: {type: 'parser'}, - }, - { - url: 'http://google.com/wc/import.html', - mimeType: 'text/html', - transferSize: 13, - networkRequestTime: 13, - networkEndTime: 13, - finished: true, - isLinkPreload: false, - initiator: {type: 'script'}, - }, - { - url: 'http://google.com/css/ignored.css', - mimeType: 'text/css', - transferSize: 16, - networkRequestTime: 16, - networkEndTime: 16, - finished: true, - isLinkPreload: true, - initiator: {type: 'script'}, - }, - { - url: 'http://google.com/js/ignored.js', - mimeType: 'text/javascript', - transferSize: 16, - networkRequestTime: 16, - networkEndTime: 16, - finished: true, - isLinkPreload: false, - initiator: {type: 'script'}, - }, - { - url: 'http://google.com/js/also-ignored.js', - mimeType: 'text/javascript', - transferSize: 12, - networkRequestTime: 12, - networkEndTime: 22, - finished: false, - isLinkPreload: false, - initiator: {type: 'parser'}, - }, - ].map((record) => Object.assign(new NetworkRequest(), record)), -}; + +const networkRecords = [ + { + url: 'http://google.com/css/style.css', + mimeType: 'text/css', + transferSize: 10, + networkRequestTime: 10, + networkEndTime: 10, + finished: true, + isLinkPreload: false, + initiator: {type: 'parser'}, + }, + { + url: 'http://google.com/wc/select.html', + mimeType: 'text/html', + transferSize: 11, + networkRequestTime: 11, + networkEndTime: 11, + finished: true, + isLinkPreload: false, + initiator: {type: 'other'}, + }, + { + url: 'http://google.com/js/app.json', + mimeType: 'application/json', + transferSize: 24, + networkRequestTime: 24, + networkEndTime: 24, + finished: true, + isLinkPreload: false, + initiator: {type: 'script'}, + }, + { + url: 'http://google.com/js/app.js', + mimeType: 'text/javascript', + transferSize: 12, + networkRequestTime: 12, + networkEndTime: 22, + finished: true, + isLinkPreload: false, + initiator: {type: 'parser'}, + }, + { + url: 'http://google.com/wc/import.html', + mimeType: 'text/html', + transferSize: 13, + networkRequestTime: 13, + networkEndTime: 13, + finished: true, + isLinkPreload: false, + initiator: {type: 'script'}, + }, + { + url: 'http://google.com/css/ignored.css', + mimeType: 'text/css', + transferSize: 16, + networkRequestTime: 16, + networkEndTime: 16, + finished: true, + isLinkPreload: true, + initiator: {type: 'script'}, + }, + { + url: 'http://google.com/js/ignored.js', + mimeType: 'text/javascript', + transferSize: 16, + networkRequestTime: 16, + networkEndTime: 16, + finished: true, + isLinkPreload: false, + initiator: {type: 'script'}, + }, + { + url: 'http://google.com/js/also-ignored.js', + mimeType: 'text/javascript', + networkRequestTime: 12, + finished: false, + isLinkPreload: false, + initiator: {type: 'parser'}, + }, +]; describe('First paint blocking tags', () => { // Reset the Gatherer before each test. @@ -103,7 +100,7 @@ describe('First paint blocking tags', () => { it('return filtered and indexed requests', () => { const actual = TagsBlockingFirstPaint - ._filteredAndIndexedByUrl(traceData.networkRecords); + ._filteredAndIndexedByUrl(networkRecords); return expect(Object.fromEntries(actual)).toMatchObject({ 'http://google.com/css/style.css': { isLinkPreload: false, @@ -152,8 +149,9 @@ describe('First paint blocking tags', () => { const mockContext = createMockContext(); mockContext.driver._executionContext.evaluate .mockResolvedValue([linkDetails, linkDetails, scriptDetails]); + mockContext.dependencies.DevtoolsLog = networkRecordsToDevtoolsLog(networkRecords); - const artifact = await tagsBlockingFirstPaint.afterPass(mockContext, traceData); + const artifact = await tagsBlockingFirstPaint.getArtifact(mockContext); const expected = [ { diff --git a/core/test/gather/gatherers/global-listeners-test.js b/core/test/gather/gatherers/global-listeners-test.js index d3a361dd6c3b..9dc32f331032 100644 --- a/core/test/gather/gatherers/global-listeners-test.js +++ b/core/test/gather/gatherers/global-listeners-test.js @@ -53,7 +53,7 @@ describe('Global Listener Gatherer', () => { connectionStub.sendCommand = sendCommandMock; const driver = new Driver(connectionStub); - const globalListeners = await globalListenerGatherer.afterPass({driver}); + const globalListeners = await globalListenerGatherer.getArtifact({driver}); return expect(globalListeners).toMatchObject(expectedOutput); }); }); diff --git a/core/test/gather/gatherers/link-elements-test.js b/core/test/gather/gatherers/link-elements-test.js index 77b9c126f24a..823b86d1e956 100644 --- a/core/test/gather/gatherers/link-elements-test.js +++ b/core/test/gather/gatherers/link-elements-test.js @@ -40,7 +40,7 @@ describe('Link Elements gatherer', () => { }; } - function getPassData({linkElementsInDOM = [], headers = []}) { + function getContext({linkElementsInDOM = [], headers = []}) { const url = 'https://example.com'; mockMainResource.mockReturnValue({url, responseHeaders: headers, resourceType: 'Document'}); const driver = { @@ -54,8 +54,7 @@ describe('Link Elements gatherer', () => { }, LighthouseRunWarnings: [], }; - const passContext = {driver, url, baseArtifacts, computedCache: new Map()}; - return [passContext, {}]; + return {driver, url, baseArtifacts, dependencies: {}, computedCache: new Map()}; } it('returns elements from DOM', async () => { @@ -65,7 +64,7 @@ describe('Link Elements gatherer', () => { link({source: 'body', rel: 'ICON', href: 'https://example.com/a.png'}), ]; - const result = await new LinkElements().afterPass(...getPassData({linkElementsInDOM})); + const result = await new LinkElements().getArtifact(getContext({linkElementsInDOM})); expect(result).toEqual([ link({source: 'head', rel: 'preconnect', href: 'https://cdn.example.com'}), link({source: 'head', rel: 'stylesheet', href: 'https://example.com/a.css'}), @@ -81,7 +80,7 @@ describe('Link Elements gatherer', () => { {name: 'LINK', value: '; rel=alternate; hreflang=xx'}, ]; - const result = await new LinkElements().afterPass(...getPassData({headers})); + const result = await new LinkElements().getArtifact(getContext({headers})); expect(result).toEqual([ link({source: 'headers', rel: 'prefetch', href: 'https://example.com/', as: 'image'}), link({source: 'headers', rel: 'preconnect', href: 'https://example.com/', crossOrigin: 'anonymous'}), // eslint-disable-line max-len @@ -101,7 +100,7 @@ describe('Link Elements gatherer', () => { {name: 'Link', value: '; rel=prefetch; as=image'}, ]; - const result = await new LinkElements().afterPass(...getPassData({linkElementsInDOM, headers})); + const result = await new LinkElements().getArtifact(getContext({linkElementsInDOM, headers})); expect(result).toEqual([ link({source: 'head', rel: 'stylesheet', href: 'https://example.com/a.css'}), link({source: 'body', rel: 'icon', href: 'https://example.com/a.png'}), @@ -115,11 +114,11 @@ describe('Link Elements gatherer', () => { {name: 'Link', value: 'a'}, ]; - const passData = getPassData({linkElementsInDOM, headers}); - const result = await new LinkElements().afterPass(...passData); + const context = getContext({linkElementsInDOM, headers}); + const result = await new LinkElements().getArtifact(context); expect(result).toEqual([]); - expect(passData[0].baseArtifacts.LighthouseRunWarnings).toHaveLength(1); - expect(passData[0].baseArtifacts.LighthouseRunWarnings[0]).toBeDisplayString( + expect(context.baseArtifacts.LighthouseRunWarnings).toHaveLength(1); + expect(context.baseArtifacts.LighthouseRunWarnings[0]).toBeDisplayString( 'Error parsing `link` header (Unexpected character "a" at offset 22): `a`' ); }); diff --git a/core/test/gather/gatherers/seo/font-size-test.js b/core/test/gather/gatherers/seo/font-size-test.js index c1732a261d52..e55da2c55aa4 100644 --- a/core/test/gather/gatherers/seo/font-size-test.js +++ b/core/test/gather/gatherers/seo/font-size-test.js @@ -144,7 +144,7 @@ describe('Font size gatherer', () => { }; const driver = {defaultSession: session}; - const artifact = await fontSizeGather.afterPass({driver}); + const artifact = await fontSizeGather.getArtifact({driver}); const expectedFailingTextLength = Array.from(smallText.trim()).length; const expectedTotalTextLength = Array.from(smallText.trim()).length + diff --git a/core/test/gather/gatherers/viewport-dimensions-test.js b/core/test/gather/gatherers/viewport-dimensions-test.js index 409be857095e..2c0ad372d808 100644 --- a/core/test/gather/gatherers/viewport-dimensions-test.js +++ b/core/test/gather/gatherers/viewport-dimensions-test.js @@ -17,7 +17,7 @@ describe('ViewportDimensions gatherer', () => { }); it('returns an artifact', () => { - return gatherer.afterPass({ + return gatherer.getArtifact({ driver: { executionContext: { async evaluate() { diff --git a/core/test/network-records-to-devtools-log.js b/core/test/network-records-to-devtools-log.js index 40654e667300..d3a42a06f81c 100644 --- a/core/test/network-records-to-devtools-log.js +++ b/core/test/network-records-to-devtools-log.js @@ -437,7 +437,10 @@ function networkRecordsToDevtoolsLog(networkRecords, options = {}) { devtoolsLog.push(getResponseReceivedEvent(networkRecord, index, normalizedTiming)); devtoolsLog.push(getDataReceivedEvent(networkRecord, index)); - devtoolsLog.push(getLoadingFinishedEvent(networkRecord, index, normalizedTiming)); + + if (networkRecord.finished !== false) { + devtoolsLog.push(getLoadingFinishedEvent(networkRecord, index, normalizedTiming)); + } }); // If in a test, assert that the log will turn into an equivalent networkRecords. From aa2a959004b6fc02422bfb99041e137b7cb2c206 Mon Sep 17 00:00:00 2001 From: Adam Raine Date: Tue, 9 May 2023 16:28:10 -0700 Subject: [PATCH 2/2] beforepass --- .../gather/gatherers/console-messages-test.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/test/gather/gatherers/console-messages-test.js b/core/test/gather/gatherers/console-messages-test.js index 057cb03e1a8c..162460c0f77d 100644 --- a/core/test/gather/gatherers/console-messages-test.js +++ b/core/test/gather/gatherers/console-messages-test.js @@ -62,9 +62,10 @@ describe('ConsoleMessages', () => { const driver = new MockDriver(); const options = {driver}; - await consoleGatherer.beforePass(options); + await consoleGatherer.startInstrumentation(options); driver.defaultSession.fireForTest('Runtime.exceptionThrown', runtimeEx); + await consoleGatherer.stopInstrumentation(options); const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); @@ -104,9 +105,10 @@ describe('ConsoleMessages', () => { const driver = new MockDriver(); const options = {driver}; - await consoleGatherer.beforePass(options); + await consoleGatherer.startInstrumentation(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleWarnEvent); + await consoleGatherer.stopInstrumentation(options); const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); @@ -136,9 +138,10 @@ describe('ConsoleMessages', () => { const driver = new MockDriver(); const options = {driver}; - await consoleGatherer.beforePass(options); + await consoleGatherer.startInstrumentation(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleWarnEvent); + await consoleGatherer.stopInstrumentation(options); const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); @@ -260,9 +263,10 @@ describe('ConsoleMessages', () => { const driver = new MockDriver(); const options = {driver}; - await consoleGatherer.beforePass(options); + await consoleGatherer.startInstrumentation(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleWarnEvent); + await consoleGatherer.stopInstrumentation(options); const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); @@ -318,9 +322,10 @@ describe('ConsoleMessages', () => { const driver = new MockDriver(); const options = {driver}; - await consoleGatherer.beforePass(options); + await consoleGatherer.startInstrumentation(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleErrorEvent); + await consoleGatherer.stopInstrumentation(options); const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 1); @@ -358,9 +363,10 @@ describe('ConsoleMessages', () => { const driver = new MockDriver(); const options = {driver}; - await consoleGatherer.beforePass(options); + await consoleGatherer.startInstrumentation(options); driver.defaultSession.fireForTest('Runtime.consoleAPICalled', consoleLog); + await consoleGatherer.stopInstrumentation(options); const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 0); @@ -406,10 +412,11 @@ describe('ConsoleMessages', () => { const driver = new MockDriver(); const options = {driver}; - await consoleGatherer.beforePass(options); + await consoleGatherer.startInstrumentation(options); driver.defaultSession.fireForTest('Log.entryAdded', logEntries[0]); driver.defaultSession.fireForTest('Log.entryAdded', logEntries[1]); + await consoleGatherer.stopInstrumentation(options); const artifact = await consoleGatherer.getArtifact(options); assert.equal(artifact.length, 2);