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

feat(cli): use requestedUrl instead of finalUrl for upload context naming #849

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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