GoogleChrome / lighthouse-ci

Automate running Lighthouse for every commit, viewing the changes, and preventing regressions
Apache License 2.0
6.41k stars 644 forks source link

Use URL search parameters in the reportFilenamePattern #926

Open ErikBrendel opened 1 year ago

ErikBrendel commented 1 year ago

Is your feature request related to a problem? Please describe.

I would like to generate lhci report files with the target: filesystem upload mechanism, and use information from the search / query string within the filename of the generated report files. This seems to not be possible currently.

To be precise, I have a few test URLs with the following pattern:

https://mypage.com/viewPage?page_id=test1
https://mypage.com/viewPage?page_id=test2&fooparam=value
https://mypage.com/viewPage?page_id=third_page

Describe the solution you'd like

Ideally, I could provide reportFilenamePattern: "%%QUERYPARAM:page_id%%.report.%%EXTENSION%%" to achieve the following output:

test1.report.html
test1.report.json
test2.report.html
test2.report.json
thirdPage.report.html
thirdPage.report.json

If this kind of parameterized placeholder is not feasible, a simpler but also good sultion for me would to use the whole query string reportFilenamePattern: "%%QUERY%%.report.%%EXTENSION%%" to achieve the following output:

page_id_test1.report.html
page_id_test1.report.json
page_id_test2_fooparam_value.report.html
page_id_test2_fooparam_value.report.json
page_id_thirdPage.report.html
page_id_thirdPage.report.json

Potentially relevant part of the code: https://github.com/GoogleChrome/lighthouse-ci/blob/f28992b5ce434e072e2c3c744ac46dc0ddc0f6f4/packages/cli/src/upload/upload.js#L545-L554

Describe alternatives you've considered I could keep the default file names, and write a small JS script that parses the JSON files, generates the newly desired filename manually, and then renames both report files. But this sounds unnecessary when the reportFilenamePattern should solve this.

Additional context The final result HTML files are intended as "build output" from that GitLab CI job, so that developers can take a look into the HTML pages to see more details.