Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!config.outputHtml) {
/* eslint-disable-next-line no-param-reassign */
config.outputHtml = commandOptions.lighthouseOutputHtml as string;
}
}
const auditStartEvent: AuditStartEvent = {
config,
options,
url,
};
await EventEmitter.fire(`module/lighthouse/audit/start`, auditStartEvent);
const audit: Audit = await lighthouse(
url,
{
...options,
port: options.chromePort,
},
config,
);
const auditEndEvent: AuditEndEvent = {
audit,
config,
options,
url,
};
await EventEmitter.fire(`module/lighthouse/audit/end`, auditEndEvent);
if (!config.outputHtml) {
/* eslint-disable-next-line no-param-reassign */
config.outputHtml = commandOptions.lighthouseOutputHtml as string;
}
}
const auditStartEvent: AuditStartEvent = {
config,
options,
url,
};
await EventEmitter.fire(`module/lighthouse/audit/start`, auditStartEvent);
const audit: Audit = await lighthouse(
url,
{
...options,
port: options.chromePort,
},
config,
);
const auditEndEvent: AuditEndEvent = {
audit,
config,
options,
url,
};
await EventEmitter.fire(`module/lighthouse/audit/end`, auditEndEvent);
export const runLighthouse = async (log: Logger, url: string) => {
try {
log.debug({ url }, 'Running lighthouse')
const results = await lighthouse(
url,
{
output: 'json',
// provided by build environment, ref OPS-383
port: Number(process.env.CHROME_REMOTE_DEBUGGING_PORT) || 9222,
skipAutolaunch: true,
},
{
extends: 'lighthouse:default',
settings: {},
},
)
return results
} catch (err) {
log.error({ err }, 'Could not run lighthouse!')
export default async function test(
url,
config = getConfig(),
{chromeFlags, ...options} = getOptions(),
) {
const chrome = await launch({chromeFlags});
const {lhr: result} =
await lighthouse(url, {port: chrome.port, ...options}, config);
await chrome.kill();
return result;
}
const launchChromeAndRunLighthouse = async url => {
try {
log(`fetching ${url}`)
const chromeFlags = ['--headless', '--no-sandbox', '--disable-gpu']
const chrome = await chromeLauncher.launch({
chromeFlags,
connectionPollInterval: 10000
})
log('running lighthouse')
const results = await lighthouse(
url,
{ chromeFlags, port: chrome.port },
null
)
delete results.artifacts
await chrome.kill()
return results
} catch (e) {
throw e
}
}
const works = browsers.map((browser, index) => {
const target = targets[index];
const port = new URL(browser.wsEndpoint()).port;
const opts: any = {port};
return lighthouse(target.url, opts, lighthouseConfig)
.then((result: any) => {
context.addReport(target, result);
return browser.close();
});
});