Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 9351e4e

Browse files
committed
Bundle analysis: Temp mock for routes field of Assets
1 parent 4a2bb9b commit 9351e4e

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

graphql_api/tests/test_commit.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,3 +3256,70 @@ def test_bundle_analysis_report_size_filtered_no_value(self, get_storage_service
32563256
"bundleDataFiltered": {"size": {"gzip": 20, "uncompress": 20}},
32573257
},
32583258
}
3259+
3260+
@patch("graphql_api.dataloader.bundle_analysis.get_appropriate_storage_service")
3261+
def test_bundle_analysis_asset_routes(self, get_storage_service):
3262+
storage = MemoryStorageService({})
3263+
get_storage_service.return_value = storage
3264+
3265+
head_commit_report = CommitReportFactory(
3266+
commit=self.commit, report_type=CommitReport.ReportType.BUNDLE_ANALYSIS
3267+
)
3268+
3269+
with open(
3270+
"./services/tests/samples/bundle_with_assets_and_modules.sqlite", "rb"
3271+
) as f:
3272+
storage_path = StoragePaths.bundle_report.path(
3273+
repo_key=ArchiveService.get_archive_hash(self.repo),
3274+
report_key=head_commit_report.external_id,
3275+
)
3276+
storage.write_file(get_bucket_name(), storage_path, f)
3277+
3278+
query = """
3279+
query FetchCommit($org: String!, $repo: String!, $commit: String!) {
3280+
owner(username: $org) {
3281+
repository(name: $repo) {
3282+
... on Repository {
3283+
commit(id: $commit) {
3284+
bundleAnalysis {
3285+
bundleAnalysisReport {
3286+
__typename
3287+
... on BundleAnalysisReport {
3288+
bundle(name: "b5") {
3289+
asset(name: "assets/LazyComponent-fcbb0922.js") {
3290+
name
3291+
normalizedName
3292+
routes
3293+
}
3294+
}
3295+
}
3296+
}
3297+
}
3298+
}
3299+
}
3300+
}
3301+
}
3302+
}
3303+
"""
3304+
3305+
variables = {
3306+
"org": self.org.username,
3307+
"repo": self.repo.name,
3308+
"commit": self.commit.commitid,
3309+
}
3310+
data = self.gql_request(query, variables=variables)
3311+
commit = data["owner"]["repository"]["commit"]
3312+
3313+
asset_report = commit["bundleAnalysis"]["bundleAnalysisReport"]["bundle"][
3314+
"asset"
3315+
]
3316+
3317+
assert asset_report is not None
3318+
assert asset_report["name"] == "assets/LazyComponent-fcbb0922.js"
3319+
assert asset_report["normalizedName"] == "assets/LazyComponent-*.js"
3320+
assert asset_report["routes"] == [
3321+
"/",
3322+
"/about",
3323+
"/login",
3324+
"/super/long/url/path",
3325+
]

graphql_api/types/bundle_analysis/base.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type BundleAsset {
5555
after: DateTime
5656
branch: String
5757
): BundleAnalysisMeasurements
58+
routes: [String!]
5859
}
5960

6061
type BundleReport {

graphql_api/types/bundle_analysis/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ def resolve_asset_report_measurements(
158158
return bundle_analysis_measurements.compute_asset(bundle_asset)
159159

160160

161+
@bundle_asset_bindable.field("routes")
162+
def resolve_routes(
163+
bundle_asset: AssetReport, info: GraphQLResolveInfo
164+
) -> Optional[List[str]]:
165+
return ["/", "/about", "/login", "/super/long/url/path"]
166+
167+
161168
# ============= Bundle Report Bindable =============
162169

163170

0 commit comments

Comments
 (0)