Skip to content

Commit 2ab66c0

Browse files
committed
wip: restore tests
1 parent c5ee251 commit 2ab66c0

File tree

8 files changed

+332
-48
lines changed

8 files changed

+332
-48
lines changed

package-lock.json

Lines changed: 8 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@supabase/auth-js": "2.71.1",
5454
"@supabase/functions-js": "2.4.5",
5555
"@supabase/node-fetch": "2.6.15",
56-
"@supabase/postgrest-js": "file:../postgrest-js",
56+
"@supabase/postgrest-js": "https://pkg.pr.new/supabase/postgrest-js/@supabase/postgrest-js@78e9fcc",
5757
"@supabase/realtime-js": "2.15.1",
5858
"@supabase/storage-js": "^2.10.4"
5959
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Metadata } from 'next'
2+
3+
export const metadata: Metadata = {
4+
title: 'Supabase Integration Test',
5+
description: 'Testing Supabase integration with Next.js',
6+
}
7+
8+
export default function RootLayout({ children }: { children: React.ReactNode }) {
9+
return (
10+
<html lang="en">
11+
<body>{children}</body>
12+
</html>
13+
)
14+
}

test/integration/next/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"lint": "next lint",
88
"test": "playwright test",
99
"test:ui": "playwright test --ui",
10-
"test:debug": "playwright test --debug"
10+
"test:debug": "playwright test --debug",
11+
"test:types": "npx tsd --files tests/types/*.test-d.ts"
1112
},
1213
"dependencies": {
1314
"@radix-ui/react-checkbox": "^1.3.1",
@@ -37,6 +38,7 @@
3738
"postcss": "^8",
3839
"tailwindcss": "^3.4.1",
3940
"tailwindcss-animate": "^1.0.7",
41+
"tsd": "^0.33.0",
4042
"typescript": "^5"
4143
}
4244
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import { createServerClient, createBrowserClient } from '@supabase/ssr'
2+
import { expectType } from 'tsd'
3+
4+
// Copied from ts-expect
5+
// https://github.com/TypeStrong/ts-expect/blob/master/src/index.ts#L23-L27
6+
export type TypeEqual<Target, Value> = (<T>() => T extends Target ? 1 : 2) extends <
7+
T
8+
>() => T extends Value ? 1 : 2
9+
? true
10+
: false
11+
12+
type Database = {
13+
public: {
14+
Tables: {
15+
shops: {
16+
Row: {
17+
address: string | null
18+
id: number
19+
shop_geom: unknown | null
20+
}
21+
Insert: {
22+
address?: string | null
23+
id: number
24+
shop_geom?: unknown | null
25+
}
26+
Update: {
27+
address?: string | null
28+
id?: number
29+
shop_geom?: unknown | null
30+
}
31+
Relationships: []
32+
}
33+
}
34+
Views: {
35+
[_ in never]: never
36+
}
37+
Functions: {
38+
[_ in never]: never
39+
}
40+
Enums: {
41+
[_ in never]: never
42+
}
43+
CompositeTypes: {
44+
[_ in never]: never
45+
}
46+
}
47+
}
48+
49+
{
50+
// createBrowserClient should return a typed client
51+
const pg12Client = createBrowserClient<Database>('HTTP://localhost:3000', '')
52+
const res12 = await pg12Client.from('shops').select('*')
53+
expectType<
54+
TypeEqual<
55+
| {
56+
address: string | null
57+
id: number
58+
shop_geom: unknown | null
59+
}[]
60+
| null,
61+
typeof res12.data
62+
>
63+
>(true)
64+
}
65+
66+
{
67+
// createBrowserClient should infer everything to any without types provided
68+
const pg12Client = createBrowserClient('HTTP://localhost:3000', '')
69+
const res12 = await pg12Client.from('shops').select('address, id, relation(field)')
70+
expectType<
71+
TypeEqual<
72+
| {
73+
address: any
74+
id: any
75+
relation: {
76+
field: any
77+
}[]
78+
}[]
79+
| null,
80+
typeof res12.data
81+
>
82+
>(true)
83+
}
84+
85+
{
86+
// createServerClient should return a typed client
87+
const pg12Server = createServerClient<Database>('HTTP://localhost:3000', '')
88+
const res12 = await pg12Server.from('shops').select('*')
89+
expectType<
90+
TypeEqual<
91+
| {
92+
address: string | null
93+
id: number
94+
shop_geom: unknown | null
95+
}[]
96+
| null,
97+
typeof res12.data
98+
>
99+
>(true)
100+
}
101+
102+
{
103+
// createServerClient should infer everything to any without types provided
104+
const pg12Server = createServerClient('HTTP://localhost:3000', '')
105+
const res12 = await pg12Server.from('shops').select('address, id, relation(field)')
106+
expectType<
107+
TypeEqual<
108+
| {
109+
address: any
110+
id: any
111+
relation: {
112+
field: any
113+
}[]
114+
}[]
115+
| null,
116+
typeof res12.data
117+
>
118+
>(true)
119+
}
120+
// Should be able to get a PostgrestVersion 13 client from __InternalSupabase
121+
{
122+
type DatabaseWithInternals = {
123+
__InternalSupabase: {
124+
PostgrestVersion: '13'
125+
}
126+
public: {
127+
Tables: {
128+
shops: {
129+
Row: {
130+
address: string | null
131+
id: number
132+
shop_geom: unknown | null
133+
}
134+
Insert: {
135+
address?: string | null
136+
id: number
137+
shop_geom?: unknown | null
138+
}
139+
Update: {
140+
address?: string | null
141+
id?: number
142+
shop_geom?: unknown | null
143+
}
144+
Relationships: []
145+
}
146+
}
147+
Views: {
148+
[_ in never]: never
149+
}
150+
Functions: {
151+
[_ in never]: never
152+
}
153+
Enums: {
154+
[_ in never]: never
155+
}
156+
CompositeTypes: {
157+
[_ in never]: never
158+
}
159+
}
160+
}
161+
const pg13BrowserClient = createBrowserClient<DatabaseWithInternals>('HTTP://localhost:3000', '')
162+
const pg13ServerClient = createServerClient<DatabaseWithInternals>('HTTP://localhost:3000', '', {
163+
cookies: { getAll: () => [], setAll: () => {} },
164+
})
165+
const res13 = await pg13BrowserClient.from('shops').update({ id: 21 }).maxAffected(1)
166+
expectType<typeof res13.data>(null)
167+
const res13Server = await pg13ServerClient.from('shops').update({ id: 21 }).maxAffected(1)
168+
expectType<typeof res13Server.data>(null)
169+
}
170+
{
171+
// Should default to PostgrestVersion 12
172+
const pg12BrowserClient = createBrowserClient<Database>('HTTP://localhost:3000', '')
173+
const pg12ServerClient = createServerClient<Database>('HTTP://localhost:3000', '', {
174+
cookies: { getAll: () => [], setAll: () => {} },
175+
})
176+
const res12 = await pg12BrowserClient.from('shops').update({ id: 21 }).maxAffected(1)
177+
expectType<typeof res12.Error>('maxAffected method only available on postgrest 13+')
178+
const res12Server = await pg12ServerClient.from('shops').update({ id: 21 }).maxAffected(1)
179+
expectType<typeof res12Server.Error>('maxAffected method only available on postgrest 13+')
180+
}

test/integration/next/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
}
2525
},
2626
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
27-
"exclude": ["node_modules"]
27+
"exclude": ["node_modules", "test/types/*.test-d.ts"]
2828
}

0 commit comments

Comments
 (0)