-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
93 lines (73 loc) · 3.52 KB
/
test.ts
File metadata and controls
93 lines (73 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { expect } from '@playwright/test';
import type { ProfileChunkEnvelope } from '@sentry/core';
import { sentryTest } from '../../../utils/fixtures';
import {
countEnvelopes,
getMultipleSentryEnvelopeRequests,
properFullEnvelopeRequestParser,
shouldSkipTracingTest,
} from '../../../utils/helpers';
import { validateProfile, validateProfilePayloadMetadata } from '../test-utils';
sentryTest(
'does not send profile envelope when document-policy is not set',
async ({ page, getLocalTestUrl, browserName }) => {
if (shouldSkipTracingTest() || browserName !== 'chromium') {
// Profiling only works when tracing is enabled
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });
// Assert that no profile_chunk envelope is sent without policy header
const chunkCount = await countEnvelopes(page, { url, envelopeType: 'profile_chunk', timeout: 1500 });
expect(chunkCount).toBe(0);
},
);
sentryTest('sends profile_chunk envelopes in manual mode', async ({ page, getLocalTestUrl, browserName }) => {
if (shouldSkipTracingTest() || browserName !== 'chromium') {
// Profiling only works when tracing is enabled
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname, responseHeaders: { 'Document-Policy': 'js-profiling' } });
// In manual mode we start and stop once -> expect exactly one chunk
const profileChunkEnvelopes = await getMultipleSentryEnvelopeRequests<ProfileChunkEnvelope>(
page,
2,
{ url, envelopeType: 'profile_chunk', timeout: 8000 },
properFullEnvelopeRequestParser,
);
expect(profileChunkEnvelopes.length).toBe(2);
// Validate the first chunk thoroughly
const profileChunkEnvelopeItem = profileChunkEnvelopes[0][1][0];
const envelopeItemHeader = profileChunkEnvelopeItem[0];
const envelopeItemPayload1 = profileChunkEnvelopeItem[1];
expect(envelopeItemHeader).toEqual({ type: 'profile_chunk', platform: 'javascript' });
expect(envelopeItemPayload1.profile).toBeDefined();
const profilerId1 = envelopeItemPayload1.profiler_id;
validateProfilePayloadMetadata(envelopeItemPayload1);
validateProfile(envelopeItemPayload1.profile, {
expectedFunctionNames: ['startJSSelfProfile', 'fibonacci', 'largeSum'],
minSampleDurationMs: 20,
isChunkFormat: true,
});
// only contains fibonacci
const functionNames1 = envelopeItemPayload1.profile.frames.map(frame => frame.function).filter(name => name !== '');
expect(functionNames1).toEqual(expect.not.arrayContaining(['fibonacci1', 'fibonacci2', 'fibonacci3']));
// === PROFILE CHUNK 2 ===
const profileChunkEnvelopeItem2 = profileChunkEnvelopes[1][1][0];
const envelopeItemHeader2 = profileChunkEnvelopeItem2[0];
const envelopeItemPayload2 = profileChunkEnvelopeItem2[1];
expect(envelopeItemHeader2).toEqual({ type: 'profile_chunk', platform: 'javascript' });
expect(envelopeItemPayload2.profile).toBeDefined();
expect(envelopeItemPayload2.profiler_id).toBe(profilerId1); // same profiler id for the whole session
validateProfilePayloadMetadata(envelopeItemPayload2);
validateProfile(envelopeItemPayload2.profile, {
expectedFunctionNames: [
'startJSSelfProfile',
'fibonacci1', // called by fibonacci2
'fibonacci2',
],
isChunkFormat: true,
});
// does not contain notProfiledFib (called during unprofiled part)
const functionNames2 = envelopeItemPayload2.profile.frames.map(frame => frame.function).filter(name => name !== '');
expect(functionNames2).toEqual(expect.not.arrayContaining(['notProfiledFib']));
});