Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const suffix = blockedUrlPatterns.length === 0 ? ".original" : ".blocked";
const options = {
blockedUrlPatterns,
chromeFlags: ['--no-sandbox', '--headless', '--disable-gpu','--max-wait-for-load 20000']
};
const status = {};
try {
const results = await launchChromeAndRunLighthouse(url, options,budget);
// we create the HTML
const html = ReportGenerator.generateReport(results.lhr, 'html')
status.ok = true;
// save the oupiut in process.env.REPORTS_PATH
// we create the report names
const htmlName = createReportName(url,`${suffix}.html`)
const jsonName = createReportName(url,`${suffix}.json`);
// Let's save the files
fs.writeFileSync(`${process.env.REPORTS_PATH}${jsonName}`,results.report);
fs.writeFileSync(`${process.env.REPORTS_PATH}${htmlName}`,html);
status.report = htmlName;
status.reportJSON = jsonName;
async start() {
this.spinner = ora( `Start ${this.auditName} audit for ${this.url}` ).start();
try {
const results = await this.launchChromeAndRunLighthouse( this.url, this.config );
const html = ReportGenerator.generateReport( results, 'html' );
this.spinner.succeed( `Finish ${this.auditName} audit for ${this.url}` );
return html;
} catch ( e ) {
this.spinner.fail( `Finish ${this.auditName} audit for ${this.url}` );
return JSON.stringify( e );
}
}
const createJsonReport = (results, flags) => {
if (flags.report && flags.jsonReport) {
return ReportGenerator.generateReport(results, 'json');
}
return null;
};
async function saveExthouseResult(ext, format, lhr) {
const report = ReportGenerator.generateReport(lhr, format)
const path = join(process.cwd(), `exthouse-${normalizeExtName(ext.name)}-${getFilenameDate(lhr)}.${format}`)
await writeFile(path, report)
if (format === formats.html) await open(path)
}