Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should return correct metrics and a valid report', async () => {
const expectedHtmlReport = ReportGenerator.generateReportHtml(reportFixture);
const url = 'https://emanuelemazzotta.com';
const shouldSaveReport = true;
const result = await processRawLighthouseResult(
reportFixture, url, shouldSaveReport,
);
expect({
metrics: {
'lighthouse performance': 98,
'lighthouse pwa': 85,
'lighthouse accessibility': 100,
'lighthouse best-practices': 93,
'lighthouse seo': 100,
},
report: {
[url]: expectedHtmlReport,
},
const saveReport = async (url: string, data: ILighthouseRespose) => {
try {
const report = await ReportGenerator.generateReportHtml(data);
const site = url.replace(/(^\w+:|^)\/\//, '');
await fs.outputFile(path.join(__dirname, '../reports', site, `LATEST.html`), report);
return fs.outputFile(
path.join(__dirname, '../reports', site, `${new Date().toISOString()}.html`),
report
);
} catch (err) {
console.log(`Failed to generate report for ${url} ${JSON.stringify(err)}`);
return Promise.reject('Failed to generate report');
}
};
const processRawLighthouseResult = async (data, url, shouldSaveReport) => {
const htmlReport = shouldSaveReport ? ReportGenerator.generateReportHtml(data) : false;
const { categories } = data;
const scores = R.keys(categories).map((category) => (
{ [`lighthouse ${category.toLowerCase()}`]: categories[category].score * 100 }
));
const lighthouseMetrics = Object.assign({}, ...scores);
return { metrics: lighthouseMetrics, report: { [url]: htmlReport } };
};
const createReport = results => ReportGenerator.generateReportHtml(results);
const createHtmlReport = (results, flags) => {
if (flags.report) {
return ReportGenerator.generateReportHtml(results);
}
return null;
};