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

Change a way of eliding filenames #1437

Merged
merged 4 commits into from
Jan 11, 2017

Conversation

maciej-ka
Copy link
Contributor

@maciej-ka maciej-ka commented Jan 7, 2017

Elide hash in filename even if the file length doesn't extend maximum.
Always present file extension in elided form.
Show full url in the title attribute (it will be seen on mouse hover).

Closes: #1372

@maciej-ka maciej-ka changed the title Change way to elide filenames Change a way to elide filenames Jan 7, 2017
@maciej-ka maciej-ka changed the title Change a way to elide filenames Change a way of eliding filenames Jan 7, 2017
@maciej-ka maciej-ka changed the title Change a way of eliding filenames WIP: Change a way of eliding filenames Jan 7, 2017
Elide hash in filename, even if the file length doesn't extend maximum.
Always present file extension in elided form.

Closes: GoogleChrome#1372
@maciej-ka maciej-ka changed the title WIP: Change a way of eliding filenames Change a way of eliding filenames Jan 7, 2017
});

it('Elides long names with hash', () => {
const url = superLongName.slice(0, -3)
Copy link
Contributor

Choose a reason for hiding this comment

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

templates str would be great here:

`${superLongName.slice(0, -3)}-f303dec6eec305a4fab8025577db3c2feb418148ac75ba378281399fb1ba670b.css`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid with indent and const keyword that would exceed lint line width

@@ -129,3 +129,32 @@ describe('CRC Formatter', () => {
assert.ok(truncatedURLRegExp.test(output));
});
});


describe('parseURL', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like there are some html tests above. Can you add a test for the title attr addition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, added

if (file.length > MAX_FILENAME_LENGTH) {
file = file.slice(0, MAX_FILENAME_LENGTH) + '...';
const dotIndex = file.lastIndexOf('.');
file =
Copy link
Contributor

Choose a reason for hiding this comment

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

file = file.slice(0, MAX_FILENAME_LENGTH - 1 - (file.length - dotIndex)) +
    `\u2026${file.slice(dotIndex)}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

it('Elides hashes', () => {
const url = 'http://example.com/file-f303dec6eec305a4fab8025577db3c2feb418148ac75ba378281399fb1ba670b.css';
const result = criticalRequestChainFormatter.parseURL(url);
assert.equal(result.file, '/file-f303dec\u2026.css');
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test for a hash in the middle:

url = 'http://example.com/file-f303dec6eec305a4fab80378281399fb1ba670b-somethingmore.css';
result = criticalRequestChainFormatter.parseURL(url);
assert.equal(result.file, '/file-f303dec\u2026-somethingmore.css');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@maciej-ka maciej-ka force-pushed the elide-filenames branch 3 times, most recently from 00f16f4 to 5854941 Compare January 7, 2017 20:53
@maciej-ka
Copy link
Contributor Author

maciej-ka commented Jan 7, 2017

@ebidel, thanks for a rapid fast code review! Changes done.

@ebidel
Copy link
Contributor

ebidel commented Jan 9, 2017

Thanks @Lokson. Good by me. @paulirish is this what you had in mind?

@maciej-ka
Copy link
Contributor Author

You're welcome!

@paulirish
Copy link
Member

@Lokson looks good. It probably makes sense to move this logic into url-shim.js. Wanna do that in a followup PR or this one?
up to you, i'm good with either way.

@brendankenny
Copy link
Member

It probably makes sense to move this logic into url-shim.js

how much of it though? Just eliding long filenames or also the part about stripping down to the end of the parsedResourceURL.pathname?

@paulirish
Copy link
Member

It probably makes sense to move this logic into url-shim.js

how much of it though? Just eliding long filenames or also the part about stripping down to the end of the parsedResourceURL.pathname?

both. in devtools source we call it getDisplayName.. basically the UI friendly representation of the URL

@wardpeet
Copy link
Collaborator

maybe for lighthouse a good name would be getShortname?

@maciej-ka
Copy link
Contributor Author

Static URL.getDisplayName(url) extracted. Function expects a string and returns a string. This version should be easiest to reuse which comes at a cost of one extra parse call new URL(url). Because not many urls are presented, this is probably irrelevant.

@paulirish
Copy link
Member

yup! sgtm. nice work @Lokson

@paulirish paulirish merged commit a28bc00 into GoogleChrome:master Jan 11, 2017
andrewrota pushed a commit to andrewrota/lighthouse that referenced this pull request Jan 13, 2017
Elide hash in filename, even if the file length doesn't extend maximum.
Always present file extension in elided form.

Closes: GoogleChrome#1372

* Refactor and add tests
* Extract getDisplayName into url-shim
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.

None yet

5 participants