question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: hooks to inspect and modify report data

See original GitHub issue

After running into some of the issues described in both #138 and #154, I have a suggestion that might make it easier for folks to work around the lack of built-in support for features like matrix builds (desktop + mobile) and URL determinism, taking the burden of implementing them off you and other contributors:

Lots of other platforms and tools (Rollup is one) offer declarative hooks that allow the configuration to inspect and even modify data (in place) at specific points in the execution lifecycle.

In my specific case, I’m trying to use Lighthouse CI to run scheduled reports on a list of URLs that either aren’t under our control or have content that isn’t managed in GitHub. Currently, builds for which the git SHA hasn’t changed (which will be typical because the actions are run on a schedule) fail because the hashes are the same.

I’m going to gloss very heavily over the implementation details because I haven’t looked at how builds are scheduled or structured, but hopefully you’ll get where I’m going. Some examples:

  • Before running the builds, a hook could modify the list of builds to run to include desktop runs for each, e.g.

    module.exports = {
      ci: {
        hooks: {
          beforeRunBuilds ({ builds }) {
            for (const { hash, settings, ...build } of builds) {
              builds.push({
                ...build,
                hash: `${hash}-desktop`,
                settings: {
                  ...settings,
                  emulatedFormFactor: 'desktop'
                }
              })
            }
          }
        }
      }
    }
    
  • Before the builds are uploaded, a hook could modify the hashes to ensure that they’re unique (in the case of my scheduled runs):

    const date = (new Date()).d.toLocaleDateString()
    module.exports = {
      ci: {
        hooks: {
          beforeUploadBuild ({ build }) {
            build.hash = `${build.hash}@${date}`
          }
        }
      }
    }
    
  • Or there could even be a hash hook to modify the data used to generate the hash for each build:

    const date = (new Date()).d.toLocaleDateString()
    module.exports = {
      ci: {
        hooks: {
          beforeHash ({ hash }) {
            // assuming a hash object that's JSON.stringify()'d before being hashed into a string
            hash.date = date
          }
        }
      }
    }
    

If you’re uncomfortable with hooks living in the configuration, plugins might be a good place to enable them. That would also make it easier for folks to distribute reusable packages that do very specific things: enable desktop + mobile builds, or further expand a matrix of testing environments; ensure that build hashes involve the current date, time, or some other changing context.

LHCI is such a great tool, and I would love to help with this if I can. Thanks for considering it!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

1reaction
patrickhulcecommented, Sep 8, 2020

That’s the rough area we’ll need for beforeCollect but unfortunately it’s the one that requires the most internal restructuring. (We’ll need to create the idea of a collection object that contains the URL, settings, etc which currently exists only implicitly)

2 and 3 might be easier to get started with contributing if you want to start there? 😃

1reaction
patrickhulcecommented, Sep 2, 2020

For the specific problem of duplicate hashes, yes but as a broader solution to the “use desktop settings for this run” problem I like the hooks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making Sense of React Hooks - Medium
If the React community embraces the Hooks proposal, it will reduce the number of concepts you need to juggle when writing React applications....
Read more >
Business Com- test 1 Flashcards - Quizlet
Informational reports present data without analysis or recommendations. ... purpose of providing a "hook" in the introduction of a proposal? give 3 examples....
Read more >
Report Hooks - Criterion - Read the Docs
Report hooks are functions that are called at key moments during the testing process. These are useful to report statistics gathered during the...
Read more >
[MDL-44078] Proposal: API standard in Moodle that uses ...
I quite like the hooks proposal, however I'd be tempted to add a weight parameter to tweak execution order of a hook relative...
Read more >
Federal Register, Volume 64 Issue 155 (Thursday, August 12, 1999)
This proposal also would require modification of the attachment supports of the inner locking hooks; and a detailed inspection of the safety-lock hooks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found