-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
175 lines (165 loc) · 4.74 KB
/
test.ts
File metadata and controls
175 lines (165 loc) · 4.74 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { expect } from '@playwright/test';
import type { Event } from '@sentry/core';
import { sentryTest } from '../../../utils/fixtures';
import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers';
sentryTest(
'captures console messages correctly and adds a synthetic stack trace if `attachStackTrace` is set to `true`',
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });
const [, events] = await Promise.all([page.goto(url), getMultipleSentryEnvelopeRequests<Event>(page, 7)]);
expect(events).toHaveLength(7);
const logEvent = events.find(event => event.message === 'console log');
const warnEvent = events.find(event => event.message === 'console warn');
const infoEvent = events.find(event => event.message === 'console info');
const errorEvent = events.find(event => event.message === 'console error');
const traceEvent = events.find(event => event.message === 'console trace');
const errorWithErrorEvent = events.find(
event => event.exception?.values?.[0].value === 'console error with error object',
);
const traceWithErrorEvent = events.find(
event => event.exception?.values?.[0].value === 'console trace with error object',
);
expect(logEvent).toEqual(
expect.objectContaining({
level: 'log',
logger: 'console',
extra: {
arguments: ['console log'],
},
message: 'console log',
}),
);
expect(logEvent?.exception?.values![0]).toMatchObject({
mechanism: {
handled: true,
type: 'console',
synthetic: true,
},
value: 'console log',
stacktrace: {
frames: expect.any(Array),
},
});
expect(warnEvent).toEqual(
expect.objectContaining({
level: 'warning',
logger: 'console',
extra: {
arguments: ['console warn'],
},
message: 'console warn',
}),
);
expect(warnEvent?.exception?.values![0]).toMatchObject({
mechanism: {
handled: true,
type: 'console',
synthetic: true,
},
value: 'console warn',
stacktrace: {
frames: expect.any(Array),
},
});
expect(infoEvent).toEqual(
expect.objectContaining({
level: 'info',
logger: 'console',
extra: {
arguments: ['console info'],
},
message: 'console info',
}),
);
expect(infoEvent?.exception?.values![0]).toMatchObject({
mechanism: {
handled: true,
type: 'console',
synthetic: true,
},
value: 'console info',
stacktrace: {
frames: expect.any(Array),
},
});
expect(errorEvent).toEqual(
expect.objectContaining({
level: 'error',
logger: 'console',
extra: {
arguments: ['console error'],
},
message: 'console error',
}),
);
expect(errorEvent?.exception?.values![0]).toMatchObject({
mechanism: {
handled: true,
type: 'console',
synthetic: true,
},
value: 'console error',
stacktrace: {
frames: expect.any(Array),
},
});
expect(traceEvent).toEqual(
expect.objectContaining({
level: 'log',
logger: 'console',
extra: {
arguments: ['console trace'],
},
message: 'console trace',
}),
);
expect(traceEvent?.exception?.values![0]).toMatchObject({
mechanism: {
handled: true,
type: 'console',
synthetic: true,
},
value: 'console trace',
stacktrace: {
frames: expect.any(Array),
},
});
expect(errorWithErrorEvent).toEqual(
expect.objectContaining({
level: 'error',
logger: 'console',
extra: {
arguments: [
{
message: 'console error with error object',
name: 'Error',
stack: expect.any(String),
},
],
},
exception: expect.any(Object),
}),
);
expect(errorWithErrorEvent?.exception?.values?.[0].value).toBe('console error with error object');
expect(errorWithErrorEvent?.exception?.values?.[0].mechanism).toEqual({
handled: true,
type: 'console',
});
expect(traceWithErrorEvent).toEqual(
expect.objectContaining({
level: 'log',
logger: 'console',
extra: {
arguments: [
{
message: 'console trace with error object',
name: 'Error',
stack: expect.any(String),
},
],
},
}),
);
expect(traceWithErrorEvent?.exception?.values?.[0].value).toBe('console trace with error object');
},
);