-
Notifications
You must be signed in to change notification settings - Fork 8
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
Bundle Analysis: Add asset comparison and fetching PR files #480
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,45 +111,164 @@ def test_bundle_analysis_comparison(): | |
) | ||
|
||
bundle_comparison = comparison.bundle_comparison("sample") | ||
asset_changes = bundle_comparison.asset_changes() | ||
assert set(asset_changes) == set( | ||
[ | ||
AssetChange( | ||
asset_name="assets/other-*.svg", | ||
change_type=AssetChange.ChangeType.ADDED, | ||
size_delta=5126, | ||
), | ||
AssetChange( | ||
asset_name="assets/index-*.css", | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=0, | ||
), | ||
AssetChange( | ||
asset_name="assets/LazyComponent-*.js", | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=0, | ||
), | ||
AssetChange( | ||
asset_name="assets/index-*.js", | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=100, | ||
), | ||
AssetChange( | ||
asset_name="assets/index-*.js", | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=0, | ||
), | ||
AssetChange( | ||
asset_name="assets/react-*.svg", | ||
change_type=AssetChange.ChangeType.REMOVED, | ||
size_delta=-4126, | ||
), | ||
] | ||
asset_comparisons = bundle_comparison.asset_comparisons() | ||
assert len(asset_comparisons) == 6 | ||
|
||
asset_comparison_d = {} | ||
for asset_comparison in asset_comparisons: | ||
key = ( | ||
asset_comparison.base_asset_report.hashed_name | ||
if asset_comparison.base_asset_report | ||
else None, | ||
asset_comparison.head_asset_report.hashed_name | ||
if asset_comparison.head_asset_report | ||
else None, | ||
) | ||
assert key not in asset_comparison_d | ||
asset_comparison_d[key] = asset_comparison | ||
|
||
# Check asset change is correct | ||
assert asset_comparison_d[ | ||
("assets/index-666d2e09.js", "assets/index-666d2e09.js") | ||
].asset_change() == AssetChange( | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=0, | ||
asset_name="assets/index-*.js", | ||
percentage_delta=0, | ||
size_base=144577, | ||
size_head=144577, | ||
) | ||
assert asset_comparison_d[ | ||
("assets/index-c8676264.js", "assets/index-c8676264.js") | ||
].asset_change() == AssetChange( | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=100, | ||
asset_name="assets/index-*.js", | ||
percentage_delta=64.94, | ||
size_base=154, | ||
size_head=254, | ||
) | ||
assert asset_comparison_d[ | ||
(None, "assets/other-35ef61ed.svg") | ||
].asset_change() == AssetChange( | ||
change_type=AssetChange.ChangeType.ADDED, | ||
size_delta=5126, | ||
asset_name="assets/other-*.svg", | ||
percentage_delta=100, | ||
size_base=0, | ||
size_head=5126, | ||
) | ||
assert asset_comparison_d[ | ||
("assets/index-d526a0c5.css", "assets/index-d526a0c5.css") | ||
].asset_change() == AssetChange( | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=0, | ||
asset_name="assets/index-*.css", | ||
percentage_delta=0, | ||
size_base=1421, | ||
size_head=1421, | ||
) | ||
assert asset_comparison_d[ | ||
("assets/LazyComponent-fcbb0922.js", "assets/LazyComponent-fcbb0922.js") | ||
].asset_change() == AssetChange( | ||
change_type=AssetChange.ChangeType.CHANGED, | ||
size_delta=0, | ||
asset_name="assets/LazyComponent-*.js", | ||
percentage_delta=0, | ||
size_base=294, | ||
size_head=294, | ||
) | ||
assert asset_comparison_d[ | ||
("assets/react-35ef61ed.svg", None) | ||
].asset_change() == AssetChange( | ||
change_type=AssetChange.ChangeType.REMOVED, | ||
size_delta=-4126, | ||
asset_name="assets/react-*.svg", | ||
percentage_delta=-100, | ||
size_base=4126, | ||
size_head=0, | ||
) | ||
|
||
# Check asset contributing modules is correct | ||
module_reports = asset_comparison_d[ | ||
("assets/index-666d2e09.js", "assets/index-666d2e09.js") | ||
].contributing_modules() | ||
assert [module.name for module in module_reports] == [ | ||
"./vite/modulepreload-polyfill", | ||
"./commonjsHelpers.js", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/jsx-runtime.js?commonjs-module", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/cjs/react-jsx-runtime.production.min.js?commonjs-exports", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/index.js?commonjs-module", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/cjs/react.production.min.js?commonjs-exports", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/cjs/react.production.min.js", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/index.js", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/cjs/react-jsx-runtime.production.min.js", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/react/jsx-runtime.js", | ||
"../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/client.js?commonjs-exports", | ||
"../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/index.js?commonjs-module", | ||
"../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.production.min.js?commonjs-exports", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/scheduler/index.js?commonjs-module", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/scheduler/cjs/scheduler.production.min.js?commonjs-exports", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/scheduler/cjs/scheduler.production.min.js", | ||
"../../node_modules/.pnpm/[email protected]/node_modules/scheduler/index.js", | ||
"../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.production.min.js", | ||
"../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/index.js", | ||
"../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/client.js", | ||
"./vite/preload-helper", | ||
"./src/assets/react.svg", | ||
"../../../../../../vite.svg", | ||
"./src/App.css", | ||
"./src/App.tsx", | ||
"./src/index.css", | ||
"./src/main.tsx", | ||
"./index.html", | ||
] | ||
module_reports = asset_comparison_d[ | ||
("assets/index-c8676264.js", "assets/index-c8676264.js") | ||
].contributing_modules() | ||
assert [module.name for module in module_reports] == [ | ||
"./src/IndexedLazyComponent/IndexedLazyComponent.tsx", | ||
"./src/IndexedLazyComponent/index.ts", | ||
"./src/Other.tsx", | ||
] | ||
module_reports = asset_comparison_d[ | ||
(None, "assets/other-35ef61ed.svg") | ||
].contributing_modules() | ||
assert [module.name for module in module_reports] == [] | ||
module_reports = asset_comparison_d[ | ||
("assets/index-d526a0c5.css", "assets/index-d526a0c5.css") | ||
].contributing_modules() | ||
assert [module.name for module in module_reports] == [] | ||
module_reports = asset_comparison_d[ | ||
("assets/LazyComponent-fcbb0922.js", "assets/LazyComponent-fcbb0922.js") | ||
].contributing_modules() | ||
assert [module.name for module in module_reports] == [ | ||
"./src/LazyComponent/LazyComponent.tsx", | ||
] | ||
module_reports = asset_comparison_d[ | ||
("assets/react-35ef61ed.svg", None) | ||
].contributing_modules() | ||
assert [module.name for module in module_reports] == [] | ||
|
||
# Check asset contributing modules is correct when pr_files are used for filtering | ||
module_reports = asset_comparison_d[ | ||
("assets/index-666d2e09.js", "assets/index-666d2e09.js") | ||
].contributing_modules( | ||
pr_changed_files=[ | ||
"src/index.css", | ||
"src/main.tsx", | ||
"./index.html", | ||
"/src/App.css", | ||
] # first 3 is in, 4th is not | ||
) | ||
assert [module.name for module in module_reports] == [ | ||
"./src/index.css", | ||
"./src/main.tsx", | ||
"./index.html", | ||
] | ||
|
||
total_size_delta = bundle_comparison.total_size_delta() | ||
assert total_size_delta == 1100 | ||
assert total_size_delta == sum([change.size_delta for change in asset_changes]) | ||
assert comparison.percentage_delta == 0.73 | ||
|
||
with pytest.raises(MissingBundleError): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Delete the old entries in the table before inserting the new data.