Skip to content

Commit

Permalink
core(trace-processing): add backport for pubads (#14700)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Jan 24, 2023
1 parent 5e17931 commit 1826c75
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
22 changes: 22 additions & 0 deletions cli/test/smokehouse/test-definitions/pubads.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,29 @@ const expectations = {
runWarnings: {length: '>0'},
audits: {
// We just want to ensure the plugin had a chance to run without error.
'tag-load-time': {scoreDisplayMode: 'notApplicable'},
'bid-request-from-page-start': {scoreDisplayMode: 'notApplicable'},
'ad-request-from-page-start': {scoreDisplayMode: 'notApplicable'},
'first-ad-render': {scoreDisplayMode: 'notApplicable'},
'cumulative-ad-shift': {scoreDisplayMode: 'notApplicable'},
'total-ad-blocking-time': {scoreDisplayMode: 'notApplicable'},
'gpt-bids-parallel': {scoreDisplayMode: 'notApplicable'},
'serial-header-bidding': {scoreDisplayMode: 'notApplicable'},
'bottleneck-requests': {scoreDisplayMode: 'notApplicable'},
'script-injected-tags': {scoreDisplayMode: 'notApplicable'},
'blocking-load-events': {scoreDisplayMode: 'notApplicable'},
'ad-render-blocking-resources': {scoreDisplayMode: 'notApplicable'},
'ad-blocking-tasks': {scoreDisplayMode: 'notApplicable'},
'ad-request-critical-path': {scoreDisplayMode: 'notApplicable'},
'ads-in-viewport': {scoreDisplayMode: 'notApplicable'},
'async-ad-tags': {scoreDisplayMode: 'notApplicable'},
'loads-ad-tag-over-https': {scoreDisplayMode: 'notApplicable'},
'loads-gpt-from-official-source': {scoreDisplayMode: 'notApplicable'},
'viewport-ad-density': {scoreDisplayMode: 'notApplicable'},
'ad-top-of-viewport': {scoreDisplayMode: 'notApplicable'},
'duplicate-tags': {scoreDisplayMode: 'notApplicable'},
'deprecated-gpt-api-usage': {scoreDisplayMode: 'notApplicable'},
'gpt-errors-overall': {scoreDisplayMode: 'notApplicable'},
},
},
};
Expand Down
25 changes: 19 additions & 6 deletions core/computed/processed-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@ import LHTraceProcessor from '../lib/lh-trace-processor.js';

class ProcessedNavigation {
/**
* @param {LH.Trace} trace
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.ProcessedNavigation>}
*/
static async compute_(trace, context) {
const processedTrace = await ProcessedTrace.request(trace, context);
* @param {LH.Trace | LH.Artifacts.ProcessedTrace} traceOrProcessedTrace
* @return {traceOrProcessedTrace is LH.Artifacts.ProcessedTrace}
*/
static isProcessedTrace(traceOrProcessedTrace) {
return 'timeOriginEvt' in traceOrProcessedTrace;
}

/**
* @param {LH.Trace | LH.Artifacts.ProcessedTrace} traceOrProcessedTrace
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.ProcessedNavigation>}
*/
static async compute_(traceOrProcessedTrace, context) {
// TODO: Remove this backport once pubads passes in a raw trace.
if (this.isProcessedTrace(traceOrProcessedTrace)) {
return LHTraceProcessor.processNavigation(traceOrProcessedTrace);
}

const processedTrace = await ProcessedTrace.request(traceOrProcessedTrace, context);
return LHTraceProcessor.processNavigation(processedTrace);
}
}
Expand Down
18 changes: 18 additions & 0 deletions core/test/computed/processed-navigation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import {ProcessedNavigation} from '../../computed/processed-navigation.js';
import {ProcessedTrace} from '../../computed/processed-trace.js';
import {readJson} from '../test-utils.js';

const pwaTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);
Expand Down Expand Up @@ -117,6 +118,23 @@ describe('ProcessedTrace', () => {
});
});

it('accepts a processed trace as input', async () => {
const context = {computedCache: new Map()};
const processedTrace = await ProcessedTrace.request(pwaTrace, context);
const processedNavigation = await ProcessedNavigation.request(processedTrace, context);

expect(processedNavigation.timings).toEqual({
domContentLoaded: 560.294,
firstContentfulPaint: 498.87,
firstContentfulPaintAllFrames: 498.87,
firstMeaningfulPaint: 783.328,
firstPaint: 498.853,
load: 2198.898,
timeOrigin: 0,
traceEnd: 12539.872,
});
});

it('fails with NO_NAVSTART', async () => {
const context = {computedCache: new Map()};
const compute = async () => {
Expand Down

0 comments on commit 1826c75

Please sign in to comment.