Skip to content

Commit f9105eb

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
Add inline source maps test for DuplicatedJavaScript insight
Bug: none Change-Id: Ibb268f40a753baa120b689caa3cbabe3b5c3d4b5 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6518813 Reviewed-by: Paul Irish <paulirish@chromium.org> Auto-Submit: Connor Clark <cjamcl@chromium.org> Commit-Queue: Connor Clark <cjamcl@chromium.org>
1 parent a14b1f3 commit f9105eb

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

front_end/models/trace/insights/DuplicatedJavaScript.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {getFirstOrError, getInsightOrError, processTrace} from '../../../testing
77
import type * as Trace from '../trace.js';
88

99
describeWithEnvironment('DuplicatedJavaScript', function() {
10-
it('works', async () => {
10+
it('works (external source maps)', async () => {
1111
const {data, insights} = await processTrace(this, 'dupe-js.json.gz');
1212
assert.strictEqual(insights.size, 1);
1313
const insight = getInsightOrError(
@@ -46,4 +46,44 @@ describeWithEnvironment('DuplicatedJavaScript', function() {
4646

4747
assert.deepEqual(insight.metricSavings, {FCP: 100, LCP: 100} as Trace.Insights.Types.MetricSavings);
4848
});
49+
50+
it('works (inline source maps)', async () => {
51+
const {data, insights} = await processTrace(this, 'dupe-js-inline-maps.json.gz');
52+
assert.strictEqual(insights.size, 1);
53+
const insight = getInsightOrError(
54+
'DuplicatedJavaScript', insights, getFirstOrError(data.Meta.navigationsByNavigationId.values()));
55+
56+
const duplication = insight.duplicationGroupedByNodeModules;
57+
const results = Object.fromEntries(
58+
[...duplication.entries()].filter(v => v[1].estimatedDuplicateBytes > 1000 * 25).map(([key, data]) => {
59+
return [key, data.duplicates.map(v => ({url: v.script.url, transferSize: v.attributedSize}))];
60+
}));
61+
const url1 = 'https://dupe-modules-lh-inline-data.surge.sh/bundle-smaller.js?v1';
62+
const url2 = 'https://dupe-modules-lh-inline-data.surge.sh/bundle-smaller.js?v2';
63+
const url3 = 'https://dupe-modules-lh-inline-data.surge.sh/bundle-smaller.js?v3';
64+
const url4 = 'https://dupe-modules-lh-inline-data.surge.sh/bundle-smaller.js?v4';
65+
66+
assert.deepEqual(results, {
67+
'node_modules/filestack-js': [
68+
{url: url1, transferSize: 104143},
69+
{url: url2, transferSize: 104143},
70+
{url: url3, transferSize: 104143},
71+
{url: url4, transferSize: 104143},
72+
],
73+
'node_modules/@headlessui/react': [
74+
{url: url1, transferSize: 13863},
75+
{url: url2, transferSize: 13863},
76+
{url: url3, transferSize: 13863},
77+
{url: url4, transferSize: 13863},
78+
],
79+
'node_modules/react-query': [
80+
{url: url1, transferSize: 9933},
81+
{url: url2, transferSize: 9933},
82+
{url: url3, transferSize: 9933},
83+
{url: url4, transferSize: 9933},
84+
],
85+
});
86+
87+
assert.deepEqual(insight.metricSavings, {FCP: 50, LCP: 50} as Trace.Insights.Types.MetricSavings);
88+
});
4989
});

front_end/panels/timeline/fixtures/traces/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ copy_to_gen("traces") {
2626
"dom-size-long.json.gz",
2727
"dom-size-overlap.json.gz",
2828
"dom-size.json.gz",
29+
"dupe-js-inline-maps.json.gz",
2930
"dupe-js.json.gz",
3031
"enhanced-traces.json.gz",
3132
"example-dot-com.json.gz",

front_end/panels/timeline/fixtures/traces/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Trace containing a cross-origin navigation where DOM size events from the pre-na
7171

7272
A bunch of bundles with the exact same content: https://dupe-modules-lh-2.surge.sh/
7373

74+
### dupe-js-inline-maps.json.gz
75+
76+
Like above, but the source maps are inline data urls. https://dupe-modules-lh-inline-data.surge.sh/smaller.html
77+
7478
### enhanced-traces.json.gz
7579

7680
a) Contains traces with metadata needed to power a rehydrated session for enhanced tracing.
Binary file not shown.

front_end/testing/TraceLoader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ export class TraceLoader {
251251
return new SDK.SourceMap.SourceMap(scriptUrl, sourceMapUrl, cachedRawSourceMap);
252252
}
253253

254+
if (sourceMapUrl.startsWith('data:')) {
255+
const rawSourceMap = await (await fetch(sourceMapUrl)).json();
256+
return new SDK.SourceMap.SourceMap(scriptUrl, sourceMapUrl, rawSourceMap);
257+
}
258+
254259
return null;
255260
},
256261
})

0 commit comments

Comments
 (0)