-
Notifications
You must be signed in to change notification settings - Fork 6
fix: Issue when hash length is set #182
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
Changes from 3 commits
615b754
005813c
a815490
dc0e665
5e6f67c
275d0f0
6f8d670
d392379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| "@codecov/bundler-plugin-core": patch | ||
| "@codecov/bundle-analyzer": patch | ||
| "@codecov/nextjs-webpack-plugin": patch | ||
| "@codecov/nuxt-plugin": patch | ||
| "@codecov/remix-vite-plugin": patch | ||
| "@codecov/rollup-plugin": patch | ||
| "@codecov/solidstart-plugin": patch | ||
| "@codecov/sveltekit-plugin": patch | ||
| "@codecov/vite-plugin": patch | ||
| "@codecov/webpack-plugin": patch | ||
| --- | ||
|
|
||
| Fix issue with normalizing paths with a custom hash length is set |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,38 @@ const tests: Test[] = [ | |
| }, | ||
| expected: "test.*", | ||
| }, | ||
| { | ||
| name: "should replace '[hash:22]' with '*'", | ||
| input: { | ||
| path: "test.123.chunk.js", | ||
| format: "[name].[hash:22].chunk.js", | ||
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s very commendable that test cases have been added for different types and lengths of hashes. I would suggest adding more edge cases, for instance, to handle unexpected hash values or an unusual hash length. |
||
| expected: "test.*.chunk.js", | ||
| }, | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previously, this test case seems to duplicate others. Removing it would lighten the test suite without losing any value. |
||
| name: "should replace '[contenthash:22]' with '*'", | ||
| input: { | ||
| path: "test.123.chunk.js", | ||
| format: "[name].[contenthash:22].chunk.js", | ||
| }, | ||
| expected: "test.*.chunk.js", | ||
| }, | ||
| { | ||
| name: "should replace '[fullhash:22]' with '*'", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another example of a redundant test that could be removed to make the test suite more efficient. |
||
| input: { | ||
| path: "test.123.chunk.js", | ||
| format: "[name].[fullhash:22].chunk.js", | ||
| }, | ||
| expected: "test.*.chunk.js", | ||
| }, | ||
| { | ||
| name: "should replace '[chunkhash:22]' with '*'", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise, this test case seems to duplicate the previous ones. It tests the same process with similar inputs, therefore, any problematic behavior would cause both of them to fail. We should remove it to lighten the test suite. |
||
| input: { | ||
| path: "test.123.chunk.js", | ||
| format: "[name].[chunkhash:22].chunk.js", | ||
| }, | ||
| expected: "test.*.chunk.js", | ||
| }, | ||
| ]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the test coverage is good for different kind of hashes, it seems to assume that the hashes will always be of length 3. It would be beneficial to test hashes of different lengths to ensure normalisation works correctly in those scenarios as well. |
||
|
|
||
| describe("normalizePath", () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,5 @@ | ||
| const HASH_REGEX = /[a-f0-9]{8,}/i; | ||
| const POTENTIAL_HASHES = [ | ||
| "[hash]", | ||
| "[contenthash]", | ||
| "[fullhash]", | ||
| "[chunkhash]", | ||
| ]; | ||
| const POTENTIAL_HASHES = ["[contenthash", "[fullhash", "[chunkhash", "[hash"]; | ||
nicholas-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const escapeRegex = (string: string): string => | ||
| string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d"); | ||
|
|
@@ -34,8 +29,12 @@ export const normalizePath = (path: string, format: string): string => { | |
| )})`; | ||
|
|
||
| // grab the ending delimiter and create a regex group for it | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reinitializing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree - we can do.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoops, my bad. I used to have this in a loop and removed it but forgot to bump it back up. |
||
| let endingDelimiter = | ||
| format.at(match.hashIndex + match.hashString.length) ?? ""; | ||
| let endingDelimiter = ""; | ||
|
||
| [...format.slice(match.hashIndex)].forEach((char, index) => { | ||
| if (char === "]") { | ||
| endingDelimiter = format.at(match.hashIndex + index + 1) ?? ""; | ||
| } | ||
| }); | ||
|
|
||
| // If the ending delimiter is `[extname]` there won't be a | ||
| // `.<file-extension>` so we need to replace it with a `.` for the | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case seems to duplicate the following ones. They all test the same process with the same kind of input, therefore, any error would cause all of them to fail. It would therefore be more efficient to just keep one of them.