@codechecks/lighthouse-keeper
Version:
Keep an eye on Google Lighthouse score changes
44 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
if (process.env.NODE_ENV !== "test") {
const pkg = require("../package.json");
require("please-upgrade-node")(pkg);
}
const client_1 = require("@codechecks/client");
const reports_1 = require("./reports");
const options_1 = require("./options");
const lighthouse_1 = require("./lighthouse/lighthouse");
const compareReports_1 = require("./compareReports");
const uploadHtmlReport_1 = require("./uploadHtmlReport");
const start_server_1 = require("./start-server");
exports.ARTIFACT_ROOT = "lighthouse-keeper";
async function lighthouseKeeper(_options = {}) {
const options = options_1.parseOptions(_options);
let server;
if (options.buildPath) {
server = await start_server_1.startServer(options.buildPath);
}
const lighthouseReport = await lighthouse_1.runLighthouseAndGetReport(options.url);
client_1.codechecks.saveValue(`${exports.ARTIFACT_ROOT}/full-report.json`, lighthouseReport);
const reportLink = await uploadHtmlReport_1.uploadHtmlReport(lighthouseReport.htmlReport);
if (!client_1.codechecks.isPr()) {
if (server) {
server.close();
}
return;
}
const baseReport = await client_1.codechecks.getValue(`${exports.ARTIFACT_ROOT}/full-report.json`);
const reportComparison = compareReports_1.compareReports(baseReport, lighthouseReport);
await client_1.codechecks.report(reports_1.getReport({
reportComparison,
baselineExists: !!baseReport,
reportLink,
minScores: options.minScores,
}));
if (server) {
server.close();
}
}
exports.lighthouseKeeper = lighthouseKeeper;
exports.default = lighthouseKeeper;
//# sourceMappingURL=index.js.map