-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
91 lines (72 loc) · 2.56 KB
/
test.ts
File metadata and controls
91 lines (72 loc) · 2.56 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
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
import type { Event } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import {
getFirstSentryEnvelopeRequest,
getMultipleSentryEnvelopeRequests,
shouldSkipTracingTest,
} from '../../../../utils/helpers';
async function mockSupabaseRoute(page: Page) {
await page.route('**/rest/v1/todos**', route => {
return route.fulfill({
status: 200,
body: JSON.stringify({
userNames: ['John', 'Jane'],
}),
headers: {
'Content-Type': 'application/json',
},
});
});
}
const bundle = process.env.PW_BUNDLE || '';
// We only want to run this in non-CDN bundle mode
if (bundle.startsWith('bundle')) {
sentryTest.skip();
}
sentryTest('should capture Supabase database operation breadcrumbs', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
return;
}
await mockSupabaseRoute(page);
const url = await getLocalTestUrl({ testDir: __dirname });
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
expect(eventData.breadcrumbs).toBeDefined();
expect(eventData.breadcrumbs).toContainEqual({
timestamp: expect.any(Number),
type: 'supabase',
category: 'db.insert',
message: 'insert(...) filter(columns, ) from(todos)',
data: expect.objectContaining({
query: expect.arrayContaining(['filter(columns, )']),
}),
});
});
sentryTest('should capture multiple Supabase operations in sequence', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
return;
}
await mockSupabaseRoute(page);
const url = await getLocalTestUrl({ testDir: __dirname });
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url });
expect(events).toHaveLength(2);
events.forEach(event => {
expect(
event.breadcrumbs?.some(breadcrumb => breadcrumb.type === 'supabase' && breadcrumb?.category?.startsWith('db.')),
).toBe(true);
});
});
sentryTest('should include correct data payload in Supabase breadcrumbs', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
return;
}
await mockSupabaseRoute(page);
const url = await getLocalTestUrl({ testDir: __dirname });
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
const supabaseBreadcrumb = eventData.breadcrumbs?.find(b => b.type === 'supabase');
expect(supabaseBreadcrumb).toBeDefined();
expect(supabaseBreadcrumb?.data).toMatchObject({
query: expect.arrayContaining(['filter(columns, )']),
});
});