Skip to content

Commit fb0086d

Browse files
committed
add test for 0-CLS value
1 parent 885dd18 commit fb0086d

File tree

2 files changed

+65
-0
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls-standalone-spans

2 files changed

+65
-0
lines changed

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls-standalone-spans/template.html

+3
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
</head>
66
<body>
77
<div id="content"></div>
8+
<p>
9+
Some content
10+
</p>
811
</body>
912
</html>

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls-standalone-spans/test.ts

+62
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,68 @@ sentryTest('captures a "POOR" CLS vital with its source as a standalone span.',
234234
});
235235
});
236236

237+
sentryTest(
238+
'captures a 0 CLS vital as a standalone span if no layout shift occurred',
239+
async ({ getLocalTestPath, page }) => {
240+
const spanEnvelopePromise = getMultipleSentryEnvelopeRequests<SpanEnvelope>(
241+
page,
242+
1,
243+
{ envelopeType: 'span' },
244+
properFullEnvelopeRequestParser,
245+
);
246+
247+
const url = await getLocalTestPath({ testDir: __dirname });
248+
await page.goto(url);
249+
250+
await page.waitForTimeout(1000);
251+
252+
await hidePage(page);
253+
254+
const spanEnvelope = (await spanEnvelopePromise)[0];
255+
256+
const spanEnvelopeHeaders = spanEnvelope[0];
257+
const spanEnvelopeItem = spanEnvelope[1][0][1];
258+
259+
expect(spanEnvelopeItem).toEqual({
260+
data: {
261+
'sentry.exclusive_time': 0,
262+
'sentry.op': 'ui.webvital.cls',
263+
'sentry.origin': 'auto.http.browser.cls',
264+
transaction: expect.stringContaining('index.html'),
265+
'user_agent.original': expect.stringContaining('Chrome'),
266+
},
267+
description: 'Layout shift',
268+
exclusive_time: 0,
269+
measurements: {
270+
cls: {
271+
unit: '',
272+
value: 0,
273+
},
274+
},
275+
op: 'ui.webvital.cls',
276+
origin: 'auto.http.browser.cls',
277+
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
278+
span_id: expect.stringMatching(/[a-f0-9]{16}/),
279+
segment_id: expect.stringMatching(/[a-f0-9]{16}/),
280+
start_timestamp: expect.any(Number),
281+
timestamp: spanEnvelopeItem.start_timestamp,
282+
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
283+
});
284+
285+
expect(spanEnvelopeHeaders).toEqual({
286+
sent_at: expect.any(String),
287+
trace: {
288+
environment: 'production',
289+
public_key: 'public',
290+
sample_rate: '1',
291+
sampled: 'true',
292+
trace_id: spanEnvelopeItem.trace_id,
293+
// no transaction, because span source is URL
294+
},
295+
});
296+
},
297+
);
298+
237299
sentryTest(
238300
'captures CLS increases after the pageload span ended, when page is hidden',
239301
async ({ getLocalTestPath, page }) => {

0 commit comments

Comments
 (0)