Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export 'persistAudit' from audit api module to support custom lighthouse scripts #72

Open
dmckernanacv opened this issue Jan 5, 2022 · 0 comments

Comments

@dmckernanacv
Copy link

Hello, I've got a custom lighthouse script which runs outside of the audit service, however I would like to have it reported / tracked by the audit service.

To do this I'm installing this package as a dependency of my lighthouse script, but I need to make use of the 'persistAudit' function from the audit api module: https://github.com/spotify/lighthouse-audit-service/blob/master/src/api/audits/index.ts

Seeing as the other functions are exported, can this be added to the export list? It would allow me to upload the results of an independent lighthouse run to the lighthouse audit service database... Here is my relevant code snippet:

const lhAudit = require('@spotify/lighthouse-audit-service');
const uuid = require('uuid');
const pg = require("pg");
const lighthouse = require('lighthouse');

/* REDACTED */

// A custom run of lighthouse using the official lighthouse package
const result = await lighthouse(url, flags, config);

if (process.env.USE_DB === "true") {
    // Report to lhAuditService
    const audit = lhAudit.Audit.build({
        id: uuid.v4(),
        url: result?.lhr.requestedUrl,
        timeCreated: new Date(result?.lhr.fetchTime),
        timeCompleted: nowDate,
        report: result?.lhr
    });
    await lhAudit.persistAudit(        // This is what I want to do
        new pg.Pool({
            host: process.env.DB_HOST,
            port: process.env.DB_PORT,
            database: process.env.DB_NAME,
            user: process.env.DB_USERNAME,
            password: process.env.DB_PASSWORD
        }),
        audit
    );
}

As a workaround I've copied the source for persistAudit to this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant