Skip to content

zip file viewer: omit profile extension if it is .json#5079

Merged
julienw merged 6 commits into
firefox-devtools:mainfrom
joshuaobrien:omit-extensions
Sep 9, 2024
Merged

zip file viewer: omit profile extension if it is .json#5079
julienw merged 6 commits into
firefox-devtools:mainfrom
joshuaobrien:omit-extensions

Conversation

@joshuaobrien

Copy link
Copy Markdown
Contributor

Closes #4289

@codecov

codecov Bot commented Aug 8, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.49%. Comparing base (9dd06a0) to head (0dcb287).
Report is 41 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5079   +/-   ##
=======================================
  Coverage   88.49%   88.49%           
=======================================
  Files         304      304           
  Lines       27461    27467    +6     
  Branches     7430     7431    +1     
=======================================
+ Hits        24302    24308    +6     
  Misses       2934     2934           
  Partials      225      225           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@julienw julienw self-requested a review September 3, 2024 14:40

@julienw julienw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch and thanks for your patience, sorry for the delay in reviewing the patch!

Here are some comments, please tell me what you think!

Comment thread src/test/components/ZipFileTree.test.js Outdated
].forEach((fileName) => screen.getByText(fileName));
});

it('removes .json and .json.gz extensions', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the new test!

Comment thread src/test/components/ZipFileTree.test.js Outdated
await setup();

['profile1', 'profile2', 'profile3', 'profile4'].forEach((fileName) =>
screen.getByText(fileName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the jest-dom library, which makes it possible to be somewhat more explicit in our expectations, with something such as:

expect(screen.getByText(..)).toBeInTheDocument()

Normally there's a eslint rule for that, but I think it doesn't find it because of the forEach

@joshuaobrien joshuaobrien Sep 5, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was aiming to match the style in the existing test above, but being more explicit is my preference too. I've gone ahead and updated both tests.

There may be a reason it was like this that I am overlooking though, so please let me know if you'd prefer it to be changed back!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes I see
I believe the main reason is that this wasn't caught by the eslint rule :-)
Thanks for updating

Comment thread src/test/components/ZipFileTree.test.js Outdated
'profile3.json.gz',
'profile4.json',
].forEach((fileName) => {
expect(() => screen.getByText(fileName)).toThrow();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly it would be more explicit to write it like this:

expect(screen.queryByText(fileName)).not.toBeInTheDocument()

it('preserves extensions other than .json and .json.gz', async () => {
await setup();

expect(screen.getByText('profile.pdf')).toBeInTheDocument();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's good 👍

Comment thread src/profile-logic/zip-files.js Outdated
Comment on lines +199 to +205
const EXTENSIONS_TO_OMIT = ['.json', '.json.gz'];
const matchedExtension = EXTENSIONS_TO_OMIT.find((extension) =>
name.endsWith(extension)
);
if (matchedExtension) {
name = name.slice(0, name.length - matchedExtension.length);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have done it with a regexp such as:

let name = ...
const extensionsToOmitRe = /\.json(\.gz)?$/;
name = name.replace(extensionsToOmitRe, "");

It's terser but also maybe less explicit for some people.

Your solution is valid too, and I don't think one is better than the other in most cases, so I'll let you decide which one you prefer (just in case you didn't think of the RegExp based solution).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

I tend to lean away from using regex for most cases, so if possible I'd prefer to keep it as is

Comment thread src/profile-logic/zip-files.js Outdated
}

let name = this._zipFileTable.partName[zipTableIndex];
const EXTENSIONS_TO_OMIT = ['.json', '.json.gz'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh actually it looks like we don't support .json.gz files inside a zip file, it just doesn't work... So it makes no sense to remove it . Can you change it and just keep ".json"? I think it makes sense to keep an array in case we want to add some more later. (Or otherwise use the Regexp like mentioned in the other comment)

And maybe eventually we'll need to support .json.gz inside a zip...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@joshuaobrien joshuaobrien requested a review from julienw September 5, 2024 11:33
@joshuaobrien joshuaobrien changed the title zip file viewer: omit profile extensions if they are .json or .json.gz zip file viewer: omit profile extension if it is .json Sep 5, 2024

@julienw julienw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@julienw julienw enabled auto-merge September 9, 2024 10:19
@julienw julienw merged commit b2df669 into firefox-devtools:main Sep 9, 2024
@julienw julienw mentioned this pull request Sep 16, 2024
julienw added a commit that referenced this pull request Sep 16, 2024
[Florian Quèze] differential timestamp compression when serializing processed profiles (#5033)
[joshuaobrien] Zip file viewer: omit profile extension if it is .json (#5079)
[Paul Adenot] Allow typing '?' in `contenteditable` elements without having the help menu pop in (#5124)
[Julien Wajsberg] Enable the Friulian locale (#5127)

Thanks also to our localizers!
fur: Fabio Tomat
nl: simonmeulenbeek
tr: Grk, Nazım Can Altınova
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the profile extensions if they end with .json or .json.gz in the zip file viewer

2 participants