Skip to content

Commit 2618b5f

Browse files
feat(cli): use requestedUrl instead of finalUrl for upload context naming (#849)
BREAKING CHANGE: reports uploaded to slightly different location, now based on requestedUrl instead of finalUrl
1 parent 3bf80bf commit 2618b5f

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

packages/cli/src/upload/upload.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ async function runFilesystemTarget(options) {
527527
/** @type {Array<LH.Result>} */
528528
const lhrs = loadSavedLHRs().map(lhr => JSON.parse(lhr));
529529
/** @type {Array<Array<[LH.Result, LH.Result]>>} */
530-
const lhrsByUrl = _.groupBy(lhrs, lhr => lhr.finalUrl).map(lhrs => lhrs.map(lhr => [lhr, lhr]));
530+
const lhrsByUrl = _.groupBy(lhrs, lhr => lhr.requestedUrl).map(lhrs =>
531+
lhrs.map(lhr => [lhr, lhr])
532+
);
531533
const representativeLhrs = computeRepresentativeRuns(lhrsByUrl);
532534

533535
const targetDir = path.resolve(process.cwd(), options.outputDir || '');
@@ -538,7 +540,7 @@ async function runFilesystemTarget(options) {
538540
const manifest = [];
539541
// Process the median LHRs last so duplicate filenames will be overwritten by the median run
540542
for (const lhr of _.sortBy(lhrs, lhr => (representativeLhrs.includes(lhr) ? 10 : 1))) {
541-
const url = new URL(lhr.finalUrl);
543+
const url = new URL(lhr.requestedUrl);
542544
const fetchTimeDate = new Date(new Date(lhr.fetchTime).getTime() || Date.now());
543545
const context = {
544546
hostname: url.hostname,
@@ -557,7 +559,7 @@ async function runFilesystemTarget(options) {
557559

558560
/** @type {LHCI.UploadCommand.ManifestEntry} */
559561
const entry = {
560-
url: lhr.finalUrl,
562+
url: lhr.requestedUrl,
561563
isRepresentativeRun: representativeLhrs.includes(lhr),
562564
htmlPath: path.join(targetDir, htmlPath),
563565
jsonPath: path.join(targetDir, jsonPath),

packages/cli/test/upload-url-hash.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ describe('Lighthouse CI upload filesystem reports with url hash', () => {
3939
// Added unit test for PR#835
4040
it('url with hash in the reportFilenamePattern', async () => {
4141
const lhr = JSON.parse(fs.readFileSync(fakeLhrPath, 'utf8'));
42-
lhr.finalUrl = `https://www.example.com/#/page1`;
42+
lhr.requestedUrl = `https://www.example.com/#/page1`;
4343
lhr.fetchTime = '2022-10-25T22:34:01.000Z';
4444
lhr.categories.performance = {score: 0.5};
4545
lhr.audits['first-contentful-paint'].numericValue = 900;
4646
fs.writeFileSync(fakeLhrPath.replace(/lhr-\d+/, 'lhr-4'), JSON.stringify(lhr));
4747

48-
lhr.finalUrl = `https://www.example.com/#/page2`;
48+
lhr.requestedUrl = `https://www.example.com/#/page2`;
4949
lhr.fetchTime = '2022-10-25T22:34:02.000Z';
5050
lhr.categories.performance = {score: 0.5};
5151
lhr.audits['first-contentful-paint'].numericValue = 1100;
5252
fs.writeFileSync(fakeLhrPath.replace(/lhr-\d+/, 'lhr-5'), JSON.stringify(lhr));
5353

54-
lhr.finalUrl = `https://www.example.com/#/page3`;
54+
lhr.requestedUrl = `https://www.example.com/#/page3`;
5555
lhr.fetchTime = '2022-10-25T22:34:03.000Z';
5656
lhr.categories.performance = {score: 0.5};
5757
lhr.audits['first-contentful-paint'].numericValue = 1000;

packages/cli/test/upload.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('Lighthouse CI upload CLI', () => {
159159

160160
it('should support target=filesystem', async () => {
161161
const lhr = JSON.parse(fs.readFileSync(fakeLhrPath, 'utf8'));
162-
lhr.finalUrl = `https://www.example.com/page`;
162+
lhr.requestedUrl = `https://www.example.com/page`;
163163
lhr.fetchTime = '2020-05-22T22:12:01.000Z';
164164
lhr.audits['first-contentful-paint'].numericValue = 900;
165165
fs.writeFileSync(fakeLhrPath.replace(/lhr-\d+/, 'lhr-1'), JSON.stringify(lhr));

0 commit comments

Comments
 (0)