Skip to content

Commit b83ce97

Browse files
committed
Fix tests
1 parent a6c4654 commit b83ce97

File tree

10 files changed

+119
-33
lines changed

10 files changed

+119
-33
lines changed

dev-packages/browser-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@playwright/test": "~1.50.0",
4444
"@sentry-internal/rrweb": "2.34.0",
4545
"@sentry/browser": "9.10.0",
46+
"@supabase/supabase-js": "2.49.3",
4647
"axios": "1.8.2",
4748
"babel-loader": "^8.2.2",
4849
"fflate": "0.8.2",

dev-packages/browser-integration-tests/suites/integrations/supabase/db-operations/init.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as Sentry from '@sentry/browser';
2-
import { createClient } from '@supabase/supabase-js';
3-
42

3+
import { createClient } from '@supabase/supabase-js';
54
window.Sentry = Sentry;
65

76
const supabase = createClient(
@@ -12,9 +11,7 @@ const supabase = createClient(
1211
Sentry.init({
1312
dsn: 'https://[email protected]/1337',
1413
integrations: [
15-
new Sentry.BrowserTracing({
16-
tracingOrigins: ['localhost', 'my.supabase.co'],
17-
}),
14+
Sentry.browserTracingIntegration(),
1815
Sentry.supabaseIntegration(supabase)
1916
],
2017
tracesSampleRate: 1.0,

dev-packages/browser-integration-tests/suites/integrations/supabase/db-operations/test.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
import { expect } from '@playwright/test';
1+
import { Page, expect } from '@playwright/test';
22
import type { Event } from '@sentry/core';
33

44
import { sentryTest } from '../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest, getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers';
66

7+
async function mockSupabaseRoute(page: Page) {
8+
await page.route('**/rest/v1/todos**', route => {
9+
return route.fulfill({
10+
status: 200,
11+
body: JSON.stringify({
12+
userNames: ['John', 'Jane'],
13+
}),
14+
headers: {
15+
'Content-Type': 'application/json',
16+
},
17+
});
18+
});
19+
}
20+
721
sentryTest('should capture Supabase database operation breadcrumbs', async ({ getLocalTestUrl, page }) => {
22+
await mockSupabaseRoute(page);
23+
824
const url = await getLocalTestUrl({ testDir: __dirname });
925

1026
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
@@ -20,6 +36,8 @@ sentryTest('should capture Supabase database operation breadcrumbs', async ({ ge
2036
});
2137

2238
sentryTest('should capture multiple Supabase operations in sequence', async ({ getLocalTestUrl, page }) => {
39+
await mockSupabaseRoute(page);
40+
2341
const url = await getLocalTestUrl({ testDir: __dirname });
2442

2543
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url });
@@ -34,16 +52,18 @@ sentryTest('should capture multiple Supabase operations in sequence', async ({ g
3452
});
3553

3654
sentryTest('should include correct data payload in Supabase breadcrumbs', async ({ getLocalTestUrl, page }) => {
55+
await mockSupabaseRoute(page);
56+
3757
const url = await getLocalTestUrl({ testDir: __dirname });
3858

3959
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
4060

41-
const supaBreadcrumb = eventData.breadcrumbs?.find(b => b.type === 'supabase');
61+
const supabaseBreadcrumb = eventData.breadcrumbs?.find(b => b.type === 'supabase');
4262

43-
expect(supaBreadcrumb).toBeDefined();
44-
expect(supaBreadcrumb?.data).toMatchObject({
45-
table: expect.any(String),
46-
operation: expect.any(String),
47-
timestamp: expect.any(Number),
63+
expect(supabaseBreadcrumb).toBeDefined();
64+
expect(supabaseBreadcrumb?.data).toMatchObject({
65+
query: expect.arrayContaining([
66+
"filter(columns, )"
67+
]),
4868
});
4969
});

dev-packages/e2e-tests/test-applications/supabase-nextjs/lib/initSupabaseAdmin.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const NEXT_PUBLIC_SUPABASE_URL = 'http://localhost:54321';
66
const SUPABASE_SERVICE_ROLE_KEY =
77
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU';
88

9-
export const supabase = createClient(NEXT_PUBLIC_SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, {
9+
export const supabaseClient = createClient(NEXT_PUBLIC_SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, {
1010
auth: {
1111
persistSession: false,
1212
autoRefreshToken: false,
@@ -15,7 +15,5 @@ export const supabase = createClient(NEXT_PUBLIC_SUPABASE_URL, SUPABASE_SERVICE_
1515
});
1616

1717
Sentry.addIntegration(
18-
Sentry.supabaseIntegration({
19-
supabaseClient: supabase,
20-
}),
18+
Sentry.supabaseIntegration(supabaseClient),
2119
);

dev-packages/e2e-tests/test-applications/supabase-nextjs/lib/initSupabaseAnon.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ const NEXT_PUBLIC_SUPABASE_URL = 'http://localhost:54321';
66
const NEXT_PUBLIC_SUPABASE_ANON_KEY =
77
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4cGxvcmV0ZXN0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2';
88

9-
export const supabase = createClient(NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY);
9+
export const supabaseClient = createClient(NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY);
1010

11-
Sentry.addIntegration(
12-
Sentry.supabaseIntegration({
13-
supabaseClient: supabase,
14-
}),
15-
);
11+
Sentry.addIntegration(Sentry.supabaseIntegration(supabaseClient));

dev-packages/e2e-tests/test-applications/supabase-nextjs/pages/_app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { supabase } from '@/lib/initSupabaseAnon'
1+
import { supabaseClient } from '@/lib/initSupabaseAnon'
22
import { SessionContextProvider } from '@supabase/auth-helpers-react'
33
import type { AppProps } from 'next/app'
44

55
export default function App({ Component, pageProps }: AppProps) {
66
return (
7-
<SessionContextProvider supabaseClient={supabase}>
7+
<SessionContextProvider supabaseClient={supabaseClient}>
88
<Component {...pageProps} />
99
</SessionContextProvider>
1010
)

dev-packages/e2e-tests/test-applications/supabase-nextjs/pages/api/add-todo-entry.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
22
import type { NextApiRequest, NextApiResponse } from 'next';
3-
import { supabase } from '@/lib/initSupabaseAdmin';
3+
import { supabaseClient } from '@/lib/initSupabaseAdmin';
44

55
type Data = {
66
data: any;
77
error: any;
88
};
99

1010
async function login() {
11-
const { data, error } = await supabase.auth.signInWithPassword({
11+
const { data, error } = await supabaseClient.auth.signInWithPassword({
1212
1313
password: 'sentry.test',
1414
});
@@ -21,7 +21,7 @@ async function login() {
2121
}
2222

2323
async function addTodoEntry(userId?: string) {
24-
const { error } = await supabase.from('todos').insert({ task: 'test', user_id: userId }).select().single();
24+
const { error } = await supabaseClient.from('todos').insert({ task: 'test', user_id: userId }).select().single();
2525

2626
if (error) {
2727
console.log('error', error);
@@ -33,7 +33,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
3333

3434
await addTodoEntry(user?.id);
3535

36-
const { data, error } = await supabase.from('todos').select('*');
36+
const { data, error } = await supabaseClient.from('todos').select('*');
3737

3838
if (error) {
3939
console.log('error', error);

dev-packages/e2e-tests/test-applications/supabase-nextjs/pages/api/create-test-user.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
22
import type { NextApiRequest, NextApiResponse } from 'next';
3-
import { supabase } from '@/lib/initSupabaseAdmin';
3+
import { supabaseClient } from '@/lib/initSupabaseAdmin';
44

55
type Data = {
66
data: any;
77
error: any;
88
};
99

1010
async function deleteExistingUsers() {
11-
const { data: { users }, error } = await supabase.auth.admin.listUsers()
11+
const { data: { users }, error } = await supabaseClient.auth.admin.listUsers()
1212

1313
for (const user of users) {
14-
const { error } = await supabase.auth.admin.deleteUser(user.id, true);
14+
const { error } = await supabaseClient.auth.admin.deleteUser(user.id, true);
1515
if (error) console.log('error', error);
1616
}
1717
}
1818

1919
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
2020
await deleteExistingUsers();
2121

22-
const { data, error } = await supabase.auth.admin.createUser({
22+
const { data, error } = await supabaseClient.auth.admin.createUser({
2323
2424
password: 'sentry.test',
2525
email_confirm: true,

packages/core/src/integrations/supabase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ const instrumentSupabase = (supabaseClient: unknown): void => {
416416

417417
const INTEGRATION_NAME = 'Supabase';
418418

419-
const _supabaseIntegration = (({ supabaseClient } = {}) => {
419+
const _supabaseIntegration = ((supabaseClient) => {
420420
return {
421421
name: INTEGRATION_NAME,
422422
setupOnce() {

yarn.lock

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
resolved "https://registry.yarnpkg.com/@adobe/css-tools/-/css-tools-4.4.2.tgz#c836b1bd81e6d62cd6cdf3ee4948bcdce8ea79c8"
9090
integrity sha512-baYZExFpsdkBNuvGKTKWCwKH57HRZLVtycZS05WTQNVOiXVSeAki3nU35zlRbToeMW8aHlJfyS+1C4BOv27q0A==
9191

92+
"@adobe/css-tools@^4.4.0":
93+
version "4.4.2"
94+
resolved "https://registry.yarnpkg.com/@adobe/css-tools/-/css-tools-4.4.2.tgz#c836b1bd81e6d62cd6cdf3ee4948bcdce8ea79c8"
95+
integrity sha512-baYZExFpsdkBNuvGKTKWCwKH57HRZLVtycZS05WTQNVOiXVSeAki3nU35zlRbToeMW8aHlJfyS+1C4BOv27q0A==
96+
9297
9398
version "2.0.2"
9499
resolved "https://registry.yarnpkg.com/@ai-sdk/provider-utils/-/provider-utils-2.0.2.tgz#ea9d510be442b38bd40ae50dbf5b64ffc396952b"
@@ -7210,6 +7215,63 @@
72107215
dependencies:
72117216
"@testing-library/dom" "^9.3.1"
72127217

7218+
"@supabase/[email protected]":
7219+
version "2.69.1"
7220+
resolved "https://registry.yarnpkg.com/@supabase/auth-js/-/auth-js-2.69.1.tgz#fcf310d24dfab823ffbf22191e6ceaef933360d8"
7221+
integrity sha512-FILtt5WjCNzmReeRLq5wRs3iShwmnWgBvxHfqapC/VoljJl+W8hDAyFmf1NVw3zH+ZjZ05AKxiKxVeb0HNWRMQ==
7222+
dependencies:
7223+
"@supabase/node-fetch" "^2.6.14"
7224+
7225+
"@supabase/[email protected]":
7226+
version "2.4.4"
7227+
resolved "https://registry.yarnpkg.com/@supabase/functions-js/-/functions-js-2.4.4.tgz#45fcd94d546bdfa66d01f93a796ca0304ec154b8"
7228+
integrity sha512-WL2p6r4AXNGwop7iwvul2BvOtuJ1YQy8EbOd0dhG1oN1q8el/BIRSFCFnWAMM/vJJlHWLi4ad22sKbKr9mvjoA==
7229+
dependencies:
7230+
"@supabase/node-fetch" "^2.6.14"
7231+
7232+
"@supabase/[email protected]", "@supabase/node-fetch@^2.6.14":
7233+
version "2.6.15"
7234+
resolved "https://registry.yarnpkg.com/@supabase/node-fetch/-/node-fetch-2.6.15.tgz#731271430e276983191930816303c44159e7226c"
7235+
integrity sha512-1ibVeYUacxWYi9i0cf5efil6adJ9WRyZBLivgjs+AUpewx1F3xPi7gLgaASI2SmIQxPoCEjAsLAzKPgMJVgOUQ==
7236+
dependencies:
7237+
whatwg-url "^5.0.0"
7238+
7239+
"@supabase/[email protected]":
7240+
version "1.19.2"
7241+
resolved "https://registry.yarnpkg.com/@supabase/postgrest-js/-/postgrest-js-1.19.2.tgz#cb721860fefd9ec2818bbafc56de4314c0ebca81"
7242+
integrity sha512-MXRbk4wpwhWl9IN6rIY1mR8uZCCG4MZAEji942ve6nMwIqnBgBnZhZlON6zTTs6fgveMnoCILpZv1+K91jN+ow==
7243+
dependencies:
7244+
"@supabase/node-fetch" "^2.6.14"
7245+
7246+
"@supabase/[email protected]":
7247+
version "2.11.2"
7248+
resolved "https://registry.yarnpkg.com/@supabase/realtime-js/-/realtime-js-2.11.2.tgz#7f7399c326be717eadc9d5e259f9e2690fbf83dd"
7249+
integrity sha512-u/XeuL2Y0QEhXSoIPZZwR6wMXgB+RQbJzG9VErA3VghVt7uRfSVsjeqd7m5GhX3JR6dM/WRmLbVR8URpDWG4+w==
7250+
dependencies:
7251+
"@supabase/node-fetch" "^2.6.14"
7252+
"@types/phoenix" "^1.5.4"
7253+
"@types/ws" "^8.5.10"
7254+
ws "^8.18.0"
7255+
7256+
"@supabase/[email protected]":
7257+
version "2.7.1"
7258+
resolved "https://registry.yarnpkg.com/@supabase/storage-js/-/storage-js-2.7.1.tgz#761482f237deec98a59e5af1ace18c7a5e0a69af"
7259+
integrity sha512-asYHcyDR1fKqrMpytAS1zjyEfvxuOIp1CIXX7ji4lHHcJKqyk+sLl/Vxgm4sN6u8zvuUtae9e4kDxQP2qrwWBA==
7260+
dependencies:
7261+
"@supabase/node-fetch" "^2.6.14"
7262+
7263+
"@supabase/[email protected]":
7264+
version "2.49.3"
7265+
resolved "https://registry.yarnpkg.com/@supabase/supabase-js/-/supabase-js-2.49.3.tgz#789b01074b9e62ea6e41657ad65b3c06610ea3c5"
7266+
integrity sha512-42imTuAm9VEQGlXT0O6zrSwNnsIblU1eieqrAWj8HSmFaYkxepk/IuUVw1M5hKelk0ZYlqDKNwRErI1rF1EL4w==
7267+
dependencies:
7268+
"@supabase/auth-js" "2.69.1"
7269+
"@supabase/functions-js" "2.4.4"
7270+
"@supabase/node-fetch" "2.6.15"
7271+
"@supabase/postgrest-js" "1.19.2"
7272+
"@supabase/realtime-js" "2.11.2"
7273+
"@supabase/storage-js" "2.7.1"
7274+
72137275
"@sveltejs/kit@^2.0.2":
72147276
version "2.0.2"
72157277
resolved "https://registry.yarnpkg.com/@sveltejs/kit/-/kit-2.0.2.tgz#bd02523fe570ddaf89148bffb1eb2233c458054b"
@@ -8041,6 +8103,11 @@
80418103
pg-protocol "*"
80428104
pg-types "^2.2.0"
80438105

8106+
"@types/phoenix@^1.5.4":
8107+
version "1.6.6"
8108+
resolved "https://registry.yarnpkg.com/@types/phoenix/-/phoenix-1.6.6.tgz#3c1ab53fd5a23634b8e37ea72ccacbf07fbc7816"
8109+
integrity sha512-PIzZZlEppgrpoT2QgbnDU+MMzuR6BbCjllj0bM70lWoejMeNJAxCchxnv7J3XFkI8MpygtRpzXrIlmWUBclP5A==
8110+
80448111
"@types/prop-types@*":
80458112
version "15.7.3"
80468113
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
@@ -8257,6 +8324,13 @@
82578324
dependencies:
82588325
"@types/node" "*"
82598326

8327+
"@types/ws@^8.5.10":
8328+
version "8.18.0"
8329+
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.18.0.tgz#8a2ec491d6f0685ceaab9a9b7ff44146236993b5"
8330+
integrity sha512-8svvI3hMyvN0kKCJMvTJP/x6Y/EoQbepff882wL+Sn5QsXb3etnamgrJq4isrBxSJj5L2AuXcI0+bgkoAXGUJw==
8331+
dependencies:
8332+
"@types/node" "*"
8333+
82608334
"@typescript-eslint/eslint-plugin@^5.48.0":
82618335
version "5.48.0"
82628336
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.48.0.tgz#54f8368d080eb384a455f60c2ee044e948a8ce67"

0 commit comments

Comments
 (0)