Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Lighthouse stringify extension #272

Merged
merged 7 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ yarn.lock
lib
coverage/
tsconfig.tsbuildinfo
.tmp
2 changes: 1 addition & 1 deletion .mocharc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
// Allow `console.log`s to show up during test execution
logLevel: 'debug',
exit: !!process.env.CI,
spec: 'test/*.test.ts',
spec: 'test/**/*.test.ts',
extension: ['ts'],
timeout: 25 * 1000,
reporter: process.env.CI ? 'spec' : 'dot',
Expand Down
151 changes: 151 additions & 0 deletions __snapshots__/LighthouseStringifyExtension.test.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
exports['LighthouseStringifyExtension handles ending timespan 1'] = `
const fs = require('fs');
const puppeteer = require('puppeteer'); // v13.0.0 or later

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const timeout = 5000;
page.setDefaultTimeout(timeout);

const flags = {"screenEmulation":{"disabled":true}}
const config = undefined;
const lhApi = await import('lighthouse/core/fraggle-rock/api.js');
const lhFlow = await lhApi.startFlow(page, {name: "Test Flow", config, flags});
{
const targetPage = page;
await targetPage.setViewport({"width":757,"height":988})
}
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
promises.push(targetPage.waitForNavigation());
await targetPage.goto("https://example.com");
await Promise.all(promises);
}
await lhFlow.endNavigation();
await lhFlow.startTimespan();
{
const targetPage = page;
const element = await waitForSelectors([["#button"]], targetPage, { timeout, visible: true });
await scrollIntoViewIfNeeded(element, timeout);
await element.click({
offset: {
x: 61,
y: 13.5625,
},
});
}
await lhFlow.endTimespan();
const lhFlowReport = await lhFlow.generateReport();
fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)

await
`;

exports['LighthouseStringifyExtension handles ending navigation 1'] = `
const fs = require('fs');
const puppeteer = require('puppeteer'); // v13.0.0 or later

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const timeout = 5000;
page.setDefaultTimeout(timeout);

const flags = {"screenEmulation":{"disabled":true}}
const config = undefined;
const lhApi = await import('lighthouse/core/fraggle-rock/api.js');
const lhFlow = await lhApi.startFlow(page, {name: "Test Flow", config, flags});
{
const targetPage = page;
await targetPage.setViewport({"width":757,"height":988})
}
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
promises.push(targetPage.waitForNavigation());
await targetPage.goto("https://example.com");
await Promise.all(promises);
}
await lhFlow.endNavigation();
await lhFlow.startTimespan();
{
const targetPage = page;
const element = await waitForSelectors([["#button"]], targetPage, { timeout, visible: true });
await scrollIntoViewIfNeeded(element, timeout);
await element.click({
offset: {
x: 61,
y: 13.5625,
},
});
}
await lhFlow.endTimespan();
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
promises.push(targetPage.waitForNavigation());
await targetPage.goto("https://example.com/page/");
await Promise.all(promises);
}
await lhFlow.endNavigation();
const lhFlowReport = await lhFlow.generateReport();
fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)

await
`;

exports[
'LighthouseStringifyExtension handles multiple sequential navigations 1'
] = `
const fs = require('fs');
const puppeteer = require('puppeteer'); // v13.0.0 or later

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const timeout = 5000;
page.setDefaultTimeout(timeout);

const flags = {"screenEmulation":{"disabled":true}}
const config = undefined;
const lhApi = await import('lighthouse/core/fraggle-rock/api.js');
const lhFlow = await lhApi.startFlow(page, {name: "Test Flow", config, flags});
{
const targetPage = page;
await targetPage.setViewport({"width":757,"height":988})
}
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
promises.push(targetPage.waitForNavigation());
await targetPage.goto("https://example.com");
await Promise.all(promises);
}
await lhFlow.endNavigation();
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
promises.push(targetPage.waitForNavigation());
const element = await waitForSelectors([["#link"]], targetPage, { timeout, visible: true });
await scrollIntoViewIfNeeded(element, timeout);
await element.click({
offset: {
x: 61,
y: 13.5625,
},
});
await Promise.all(promises);
}
await lhFlow.endNavigation();
const lhFlowReport = await lhFlow.generateReport();
fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)

await
`;
Loading