Skip to content

Commit

Permalink
fix busted synthetic test trace redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jun 7, 2024
1 parent 4f2d74a commit 5fba3ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
14 changes: 3 additions & 11 deletions core/lib/lantern/lantern.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,10 @@ function createProcessedNavigation(traceEngineResult) {
throw new Error('missing metric scores for main frame');
}

// Grab the latest navigation with scores.
/** @type {Map<MetricName, MetricScore>=} */
let scores;
for (const navigation of Meta.mainFrameNavigations.reverse()) {
const navigationId = navigation.args.data?.navigationId;
if (!navigationId) continue;

scores = scoresByNav.get(navigationId);
if (scores) break;
}
const lastNavigationId = Meta.mainFrameNavigations.at(-1)?.args.data?.navigationId ?? '';
const scores = scoresByNav.get(lastNavigationId);
if (!scores) {
throw new Error('no metric scores found for main frame navigation');
throw new Error('missing metric scores for specified navigation');
}

/** @param {MetricName} metric */
Expand Down
31 changes: 31 additions & 0 deletions core/test/audits/redirects-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ describe('Performance: Redirects audit', () => {

const traceEvents = artifacts.traces.defaultPass.traceEvents;
const navStart = traceEvents.find(e => e.name === 'navigationStart');
const fcp = traceEvents.find(e => e.name === 'firstContentfulPaint');
const lcp = traceEvents.find(e => e.name === 'largestContentfulPaint::Candidate');

const secondNavStart = JSON.parse(JSON.stringify(navStart));
traceEvents.push(secondNavStart);
navStart.args.data.isLoadingMainFrame = true;
Expand All @@ -169,6 +172,16 @@ describe('Performance: Redirects audit', () => {
secondNavStart.args.data.documentLoaderURL = 'https://www.lisairish.com/';
secondNavStart.args.data.navigationId = '2';

const secondFcp = JSON.parse(JSON.stringify(fcp));
traceEvents.push(secondFcp);
secondFcp.args.data.navigationId = '2';
secondFcp.ts += 2;

const secondLcp = JSON.parse(JSON.stringify(lcp));
traceEvents.push(secondLcp);
secondLcp.args.data.navigationId = '2';
secondFcp.ts += 2;

const output = await RedirectsAudit.audit(artifacts, context);
expect(output.details.items).toHaveLength(3);
expect(Math.round(output.score * 100) / 100).toMatchInlineSnapshot(`0`);
Expand Down Expand Up @@ -255,15 +268,33 @@ describe('Performance: Redirects audit', () => {

const traceEvents = artifacts.traces.defaultPass.traceEvents;
const navStart = traceEvents.find(e => e.name === 'navigationStart');
const fcp = traceEvents.find(e => e.name === 'firstContentfulPaint');
const lcp = traceEvents.find(e => e.name === 'largestContentfulPaint::Candidate');

const secondNavStart = JSON.parse(JSON.stringify(navStart));
traceEvents.push(secondNavStart);
secondNavStart.args.data.navigationId = '2';

const secondFcp = JSON.parse(JSON.stringify(fcp));
traceEvents.push(secondFcp);
secondFcp.args.data.navigationId = '2';

const secondLcp = JSON.parse(JSON.stringify(lcp));
traceEvents.push(secondLcp);
secondLcp.args.data.navigationId = '2';

const thirdNavStart = JSON.parse(JSON.stringify(navStart));
traceEvents.push(thirdNavStart);
thirdNavStart.args.data.navigationId = '3';

const thirdFcp = JSON.parse(JSON.stringify(fcp));
traceEvents.push(thirdFcp);
thirdFcp.args.data.navigationId = '3';

const thirdLcp = JSON.parse(JSON.stringify(lcp));
traceEvents.push(thirdLcp);
thirdLcp.args.data.navigationId = '3';

const output = await RedirectsAudit.audit(artifacts, context);
expect(output).toMatchObject({
score: 0,
Expand Down

0 comments on commit 5fba3ae

Please sign in to comment.