diff --git a/shared/bundle_analysis/comparison.py b/shared/bundle_analysis/comparison.py index 83ceb01e..3d0616fa 100644 --- a/shared/bundle_analysis/comparison.py +++ b/shared/bundle_analysis/comparison.py @@ -209,13 +209,13 @@ def size_changes(self) -> List[RouteChange]: If a route exists on head but not base that is considered "added" and +100% percentage delta Otherwise it is considered "changed" and percentage delta = (diff_size / base_size) * 100 """ - base_sizes = self.base_report.get_size() - head_sizes = self.head_report.get_size() + base_sizes = self.base_report.get_sizes() + head_sizes = self.head_report.get_sizes() all_routes, results = base_sizes.keys() | head_sizes.keys(), [] for route_name in all_routes: # Added new route - if route_name not in base_sizes: + if route_name not in base_sizes or base_sizes[route_name] == 0: results.append( RouteChange( route_name=route_name, diff --git a/shared/bundle_analysis/report.py b/shared/bundle_analysis/report.py index 05be83cc..09bc4906 100644 --- a/shared/bundle_analysis/report.py +++ b/shared/bundle_analysis/report.py @@ -157,13 +157,13 @@ def __init__(self, db_path: str, data: Dict[str, List[AssetReport]]): self.db_path = db_path self.data = data - def get_size(self) -> Dict[str, int]: + def get_sizes(self) -> Dict[str, int]: results = {} for route, asset_reports in self.data.items(): results[route] = sum([asset.size for asset in asset_reports]) return results - def get_size_by_route(self, route: str) -> Optional[int]: + def get_size(self, route: str) -> Optional[int]: if route not in self.data: return None return sum([asset.size for asset in self.data[route]]) diff --git a/tests/unit/bundle_analysis/test_bundle_analysis.py b/tests/unit/bundle_analysis/test_bundle_analysis.py index 01449705..fd3d802c 100644 --- a/tests/unit/bundle_analysis/test_bundle_analysis.py +++ b/tests/unit/bundle_analysis/test_bundle_analysis.py @@ -1041,16 +1041,16 @@ def test_bundle_report_route_report_with_dynamic_imports(): route_report = bundle_report.full_route_report() - assert route_report.get_size() == { + assert route_report.get_sizes() == { "/sverdle/about": 2111, "/sverdle/careers": 2100, "/sverdle/faq": 2110, "/sverdle/users": 2111, } - assert route_report.get_size_by_route("/sverdle/fake") is None - assert route_report.get_size_by_route("/sverdle/about") == 2111 - assert route_report.get_size_by_route("/sverdle/careers") == 2100 - assert route_report.get_size_by_route("/sverdle/faq") == 2110 - assert route_report.get_size_by_route("/sverdle/users") == 2111 + assert route_report.get_size("/sverdle/fake") is None + assert route_report.get_size("/sverdle/about") == 2111 + assert route_report.get_size("/sverdle/careers") == 2100 + assert route_report.get_size("/sverdle/faq") == 2110 + assert route_report.get_size("/sverdle/users") == 2111 finally: report.cleanup()