Skip to content

Commit fa6c8e1

Browse files
avalletesoedirgo
andauthored
chore(tests): setup zod type checking unify (#627)
* chore(tests): use zod schemas for both type assertions and rutime results validations * fix(types): self-reference relationship unwanted intersection * chore: context for tsconfig.test.json --------- Co-authored-by: Bobbie Soedirgo <[email protected]>
1 parent c0d25d3 commit fa6c8e1

File tree

8 files changed

+240
-111
lines changed

8 files changed

+240
-111
lines changed

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ module.exports = {
66
maxWorkers: 1,
77
// Ensure deterministic test order
88
testSequencer: '<rootDir>/test/testSequencer.js',
9+
globals: {
10+
// For consistency between VSCode and type-check
11+
// https://github.com/supabase/postgrest-js/pull/627#discussion_r2236995331
12+
'ts-jest': {
13+
tsconfig: 'tsconfig.test.json'
14+
}
15+
}
916
}

package-lock.json

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
"test:update": "run-s db:clean db:run db:generate-test-types && jest --runInBand --updateSnapshot && run-s db:clean",
4343
"test:types": "run-s build && tsd --files 'test/**/*.test-d.ts'",
4444
"test:types:watch": "run-s build && tsd --files 'test/**/*.test-d.ts' --watch",
45+
"type-check": "tsc --noEmit --project tsconfig.json",
46+
"type-check:test": "tsc --noEmit --project tsconfig.test.json",
4547
"db:clean": "cd test/db && docker compose down --volumes",
4648
"db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000",
4749
"db:generate-test-types": "cd test/db && docker compose up --detach && wait-for-localhost 8080 && curl --location 'http://0.0.0.0:8080/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' > ../types.generated.ts && sed -i '' 's/export type Json = .*/export type Json = unknown;/' ../types.generated.ts"
@@ -64,6 +66,7 @@
6466
"type-fest": "^4.32.0",
6567
"typedoc": "^0.22.16",
6668
"typescript": "^4.5.5",
67-
"wait-for-localhost-cli": "^3.0.0"
69+
"wait-for-localhost-cli": "^3.0.0",
70+
"zod": "^3.25.76"
6871
}
6972
}

src/select-query-parser/result.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ export type ProcessNodes<
205205
RelationName,
206206
Relationships,
207207
RestNodes,
208-
Acc & FieldResult
208+
// Replace fields that exist in both Acc and FieldResult instead of intersecting
209+
Omit<Acc, keyof FieldResult> & FieldResult
209210
>
210211
: FieldResult extends SelectQueryError<infer E>
211212
? SelectQueryError<E>

test/relationships-join-operations.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,12 @@ test('join over a 1-M relation with both nullables and non-nullables fields usin
528528
}
529529
`)
530530
let result: Exclude<typeof res.data, null>
531-
type ExpectedType = Prettify<
532-
Database['public']['Tables']['best_friends']['Row'] & {
533-
first_user: string & Database['public']['Tables']['users']['Row']
534-
}
535-
>
531+
type ExpectedType = {
532+
id: number
533+
first_user: Database['public']['Tables']['users']['Row']
534+
second_user: string
535+
third_wheel: string | null
536+
}
536537
let expected: {
537538
first_friend_of: ExpectedType[]
538539
second_friend_of: Array<Database['public']['Tables']['best_friends']['Row']>

0 commit comments

Comments
 (0)