3.0.8 • Published 5 years ago

@dreipol/lighthouse-runner v3.0.8

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

lighthouse-runner

CircleCI Codacy Badge

Dreihouse is a tool to run automated lighthouse audits for a webproject. Dreihouse has the advantage to be more configurable than lighthouse.

Use Cases

There are several usecases for an automated audit tool like this. You can implement it into your CI so you'll never deploy a page with bad performances again. Or if you wan't to see if a site enhances over time. You can also implement it in a gulp command.

Install

npm i @dreipol/lighthouse-runner

Config

fieldtypedefaultvalue
pathsArray['/']Array of url paths. All these routes are tested and reported
chromeFlagsArray['--window-size=1200,800']Array of additional chrome flags. See all
folderstring./dreihouse-reportsDefine location to store the reports
disableEmulationbooleantrueApplay device emulation
disableThrottlingbooleantrueDisable Network and CPU throttling
initialPageLoadbooleantrueDefine whether the page should be visited before the audits are run (Cache stuff)
preAuditScriptsArray<PreAuditScriptInterface>Current available persisters are html json and `html-dashboard
reportArray['html']Different reporters. Thos will process the generated audit results. cli, html, json-dashboard, json

preAuditScripts

In order to handle login forms, or do other modifications of the page before lighthouse audits the page, you can add some preAuditScripts in the config. Those scripts are executed right before lighthouse starts. These scripts have to implement the PreAuditScriptInterface interface.

Before execution of this script, the browser instance will already be on the inital url, passed in the execute method of Dreihouse

Here is an example of such login script

ES6

    module.exports = {
        execute:async(logger, page) {
            await page.waitForSelector('#username', { visible: true });
            await page.waitForSelector('#password', { visible: true });
            
            const usernameInput = await page.$('#username');
            const passwordInput = await page.$('#password');
            
            await usernameInput.type(process.env.LOGIN_USERNAME);
            await passwordInput.type(process.env.LOGIN_PASSWORD);
            
            await passwordInput.press('Enter');
        }
    }

ES5

    module.exports = {
    execute: function(logger, page) {
        return page.waitForSelector('#id_password', { visible: true })
            .then(() => {
                return page.$('#id_password');
            })
            .then((passwordInput) => {
                return passwordInput.type(process.env.LOCKDOWN_PASSWORD)
                    .then(() => {
                        return passwordInput;
                    });
            })
            .then((passwordInput) => {
                return passwordInput.press('Enter');
            });
    },
};

Now in your config file you can load the login script

...
saveReport: true,
budget: {
    ...
},
preAuditScripts: [
    require('your/login/script.js'),
],
reporters: {
    modules: [
        ...
        
        

Example

    paths: [
        '/',
    ],
    folder: './dreihouse-reports',
    tag: 'desktop',
    chromeFlags: ['--window-size=1280,1024', '--headless'],
    initialPageload: false,
    disableEmulation: true,
    disableThrottling: true,
    preAuditScripts: [
        loginScript,
    ],
    budget: {
        dreipol: 0.9,
        seo: 0.9,
        performance: 0.9,
        pwa: 0.9,
        accessibility: 0.9,
        'best-practices': 0.9,
    },

Programmatic use

In order to modify dreihouse to your needs, you can orchestrate dreihouse programmatically.

In this example script we run the audit every 15s and use the cli to report the results but only start the chrome once and reuse the connection.

    import Dreihouse from "@dreipol/lighthouse-runner/dist/Dreihouse";
    
    const dreihouse = new Dreihouse(CONFIG, ['cli']);
    
    async function run() {
        await dreihouse.startChrome(INITIAL_URL);
        await execute();
    }
    
    async function execute() {
        await dreihouse.audit(URL);
        setTimeout(async () => {
            await execute();
        }, 15000);
    }
    
    
    run();

Tools

3.0.8

5 years ago

3.0.7

5 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.3.3

6 years ago

2.3.0

6 years ago

2.2.3

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.27.1

6 years ago

0.27.0

6 years ago

0.26.0

6 years ago

0.25.1

6 years ago

0.25.0

6 years ago

0.24.0

6 years ago

0.23.5

6 years ago

0.23.4

6 years ago

0.23.3

6 years ago

0.23.2

6 years ago

0.23.1

6 years ago

0.22.1

6 years ago

0.18.0

6 years ago

0.17.3

6 years ago

0.17.2

6 years ago

0.17.1

6 years ago

0.17.0

6 years ago

0.16.1

6 years ago

0.16.0

6 years ago

0.15.1

6 years ago

0.15.0

6 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.13.3

6 years ago

0.13.2

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.12.0

6 years ago

0.11.0

6 years ago

0.10.3

6 years ago

0.10.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago