Skip to content

Commit

Permalink
feat(cli): Updated runFilesystemTarget fn to use requestedUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspritt-hora committed Feb 15, 2023
1 parent 3560e81 commit e5e05b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/cli/src/upload/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ async function runFilesystemTarget(options) {
/** @type {Array<LH.Result>} */
const lhrs = loadSavedLHRs().map(lhr => JSON.parse(lhr));
/** @type {Array<Array<[LH.Result, LH.Result]>>} */
const lhrsByUrl = _.groupBy(lhrs, lhr => lhr.finalUrl).map(lhrs => lhrs.map(lhr => [lhr, lhr]));
const lhrsByUrl = _.groupBy(lhrs, lhr => lhr.requestedUrl).map(lhrs =>
lhrs.map(lhr => [lhr, lhr])
);
const representativeLhrs = computeRepresentativeRuns(lhrsByUrl);

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

/** @type {LHCI.UploadCommand.ManifestEntry} */
const entry = {
url: lhr.finalUrl,
url: lhr.requestedUrl,
isRepresentativeRun: representativeLhrs.includes(lhr),
htmlPath: path.join(targetDir, htmlPath),
jsonPath: path.join(targetDir, jsonPath),
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/upload-url-hash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ describe('Lighthouse CI upload filesystem reports with url hash', () => {
// Added unit test for PR#835
it('url with hash in the reportFilenamePattern', async () => {
const lhr = JSON.parse(fs.readFileSync(fakeLhrPath, 'utf8'));
lhr.finalUrl = `https://www.example.com/#/page1`;
lhr.requestedUrl = `https://www.example.com/#/page1`;
lhr.fetchTime = '2022-10-25T22:34:01.000Z';
lhr.categories.performance = {score: 0.5};
lhr.audits['first-contentful-paint'].numericValue = 900;
fs.writeFileSync(fakeLhrPath.replace(/lhr-\d+/, 'lhr-4'), JSON.stringify(lhr));

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

lhr.finalUrl = `https://www.example.com/#/page3`;
lhr.requestedUrl = `https://www.example.com/#/page3`;
lhr.fetchTime = '2022-10-25T22:34:03.000Z';
lhr.categories.performance = {score: 0.5};
lhr.audits['first-contentful-paint'].numericValue = 1000;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('Lighthouse CI upload CLI', () => {

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

0 comments on commit e5e05b8

Please sign in to comment.