UNPKG

@qavajs/steps-lighthouse

Version:

qavajs steps to perform lighthouse audit

63 lines 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@qavajs/core"); // @ts-ignore const lighthouseModule = import('lighthouse').then(module => module.default); const adapter_1 = require("./adapter"); async function audit(world, config) { const page = world.playwright ? (0, adapter_1.playwrightAdapter)(world.playwright.page) : await (0, adapter_1.wdioAdapter)(world.wdio.browser); const lighthouse = await lighthouseModule; const flags = { output: 'html' }; const results = await lighthouse(page.url(), flags, config, page); if (!results) throw new Error(`Lighthouse audit report was not generated`); const reportHtml = results.report; world.attach(Buffer.from(reportHtml).toString('base64'), 'base64:text/html'); return results; } /** * Perform lighthouse audit * @example * When I perform lighthouse audit and save results as 'lighthouseReport' */ (0, core_1.When)('I perform lighthouse audit and save results as {value}', async function (resultsKey) { const results = await audit(this); resultsKey.set(results.lhr); }); /** * Perform lighthouse audit with provided config * @example * When I perform lighthouse audit and save results as 'lighthouseReport': * """ * { * "extends": "lighthouse:default", * "settings": { * "formFactor": "desktop", * "screenEmulation": { * "mobile": false, * "width": 1350, * "height": 940, * "deviceScaleFactor": 1, * "disabled": false * } * } * } * """ */ (0, core_1.When)('I perform lighthouse audit and save results as {value}:', async function (resultsKey, rawConfig) { const config = JSON.parse(await this.getValue(rawConfig)); const results = await audit(this, config); resultsKey.set(results.lhr); }); /** * Perform lighthouse audit with provided config * @example * When I perform lighthouse audit with '#lhConfig' and save results as 'lighthouseReport': */ (0, core_1.When)('I perform lighthouse audit with {value} config and save results as {value}', async function (configKey, resultsKey) { const results = await audit(this, await configKey.value()); resultsKey.set(results.lhr); }); //# sourceMappingURL=steps.js.map