Skip to content

Commit

Permalink
Merge pull request #139 from wp-media/enhancement/121-json-comments
Browse files Browse the repository at this point in the history
Closes #121 Add "comments" in the JSON of expected results
  • Loading branch information
hanna-meda authored Sep 17, 2024
2 parents ffbb4e7 + e067b99 commit 704cdd4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/support/results/expectedResultsDesktop.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"enabled": true
},
"lcp_single_double": {
"comment": "LCP on this template is from an <input> tag which is not handled by default. Hence, we expect no LCP to be identified.",
"lcp": [],
"viewport": [],
"enabled": true
Expand Down Expand Up @@ -311,6 +312,7 @@
"enabled": true
},
"lcp_6647_svgbg_template": {
"comment": "Contains only SVG and background-image styles starting with data:image. Those are not captured by our OCI feature.",
"lcp": [],
"viewport": [],
"enabled": true
Expand Down
2 changes: 2 additions & 0 deletions src/support/results/expectedResultsMobile.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"enabled": true
},
"lcp_single_double": {
"comment": "LCP on this template is from an <input> tag which is not handled by default. Hence, we expect no LCP to be identified.",
"lcp": [
],
"viewport": [],
Expand Down Expand Up @@ -306,6 +307,7 @@
"enabled": true
},
"lcp_6647_svgbg_template": {
"comment": "Contains only SVG and background-image styles starting with data:image. Those are not captured by our OCI feature.",
"lcp": [],
"viewport": [],
"enabled": true
Expand Down
13 changes: 8 additions & 5 deletions src/support/steps/lcp-beacon-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import fs from 'fs/promises';
let data: string,
truthy: boolean = true,
failMsg: string,
jsonData: Record<string, { lcp: string[]; viewport: string[]; enabled: boolean }>,
jsonData: Record<string, { lcp: string[]; viewport: string[]; enabled: boolean, comment: string; }>,
isDbResultAvailable: boolean = true;

const actual: LcpData = {};
Expand Down Expand Up @@ -71,7 +71,7 @@ When('I visit the urls for {string}', async function (this: ICustomWorld, formFa
await this.page.waitForFunction(() => {
const beacon = document.querySelector('[data-name="wpr-wpr-beacon"]');
return beacon && beacon.getAttribute('beacon-completed') === 'true';
});
}, { timeout: 900000 });

if (formFactor !== 'desktop') {
isMobile = 1;
Expand All @@ -95,7 +95,8 @@ When('I visit the urls for {string}', async function (this: ICustomWorld, formFa
actual[key] = {
url: url,
lcp: resultFromStdout[0].lcp,
viewport: resultFromStdout[0].viewport
viewport: resultFromStdout[0].viewport,
comment: jsonData[key].comment ?? ''
}
}
}
Expand Down Expand Up @@ -125,7 +126,8 @@ Then('lcp and atf should be as expected for {string}', async function (this: ICu
// Check if expected lcp is present in actual lcp.
if (!actual[key].lcp.includes(lcp)) {
truthy = false;
failMsg += `Expected LCP for ${formFactor} - ${lcp} for ${actual[key].url} is not present in actual - ${actual[key].lcp}\n\n\n`;
failMsg += `Expected LCP for ${formFactor} - ${lcp} for ${actual[key].url} is not present in actual - ${actual[key].lcp}
more info -- ( ${actual[key].comment} )\n\n\n`;
}
}

Expand All @@ -134,7 +136,8 @@ Then('lcp and atf should be as expected for {string}', async function (this: ICu
for (const viewport of expected.viewport) {
if (!actual[key].viewport.includes(viewport)) {
truthy = false;
failMsg += `Expected Viewport for ${formFactor} - ${viewport} for ${actual[key].url} is not present in actual - ${actual[key].viewport}\n\n\n`;
failMsg += `Expected Viewport for ${formFactor} - ${viewport} for ${actual[key].url} is not present in actual - ${actual[key].viewport}
more info -- ( ${actual[key].comment} )\n\n\n`;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export interface LcpData {
[key: string]: {
url: string,
lcp: string,
viewport: string
viewport: string,
comment: string
}
}

Expand Down

0 comments on commit 704cdd4

Please sign in to comment.