Skip to content

Commit cec784f

Browse files
authored
Run tests with zod v4 (#645)
1 parent 19e7e72 commit cec784f

File tree

8 files changed

+248
-38
lines changed

8 files changed

+248
-38
lines changed

packages/app/zod-extras/package.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,11 @@
4242
"@biomejs/biome": "^1.9.4",
4343
"@lokalise/biome-config": "^2.0.0",
4444
"@lokalise/tsconfig": "^1.3.0",
45-
"@types/node": "^22.15.21",
46-
"@typescript-eslint/eslint-plugin": "^8.32.1",
47-
"@typescript-eslint/parser": "^8.32.1",
48-
"@vitest/coverage-v8": "^3.1.4",
49-
"eslint": "^8.55.0",
50-
"eslint-plugin-import": "^2.29.0",
51-
"eslint-plugin-vitest": "0.4.1",
52-
"prettier": "^3.1.1",
53-
"rimraf": "^5.0.5",
45+
"@types/node": "^22.15.30",
46+
"@vitest/coverage-v8": "^3.2.2",
47+
"rimraf": "^6.0.1",
5448
"typescript": "^5.8.3",
55-
"vitest": "^3.1.4",
56-
"zod": "^3.25.7"
49+
"vitest": "^3.2.2",
50+
"zod": "^3.25.56"
5751
}
5852
}

packages/app/zod-extras/src/utils/numberSplitFactory.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { z } from 'zod'
2+
import { z } from 'zod/v4'
33

44
import { numberSplitFactory } from './numberSplitFactory.ts'
55

@@ -32,6 +32,15 @@ describe('numberSplitFactory', () => {
3232
const splitter = numberSplitFactory()
3333
const schema = z.preprocess(splitter, z.array(z.number()))
3434

35-
expect(() => schema.parse(123)).toThrow(/Expected array, received number/)
35+
expect(() => schema.parse(123)).toThrowErrorMatchingInlineSnapshot(`
36+
[ZodError: [
37+
{
38+
"expected": "array",
39+
"code": "invalid_type",
40+
"path": [],
41+
"message": "Invalid input: expected array, received number"
42+
}
43+
]]
44+
`)
3645
})
3746
})

packages/app/zod-extras/src/utils/stringSplitFactory.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { z } from 'zod'
2+
import { z } from 'zod/v4'
33

44
import { stringSplitFactory } from './stringSplitFactory.ts'
55

@@ -48,6 +48,15 @@ describe('stringSplitFactory', () => {
4848
const splitter = stringSplitFactory()
4949
const schema = z.preprocess(splitter, z.array(z.number()))
5050

51-
expect(() => schema.parse(123)).toThrow(/Expected array, received number/)
51+
expect(() => schema.parse(123)).toThrowErrorMatchingInlineSnapshot(`
52+
[ZodError: [
53+
{
54+
"expected": "array",
55+
"code": "invalid_type",
56+
"path": [],
57+
"message": "Invalid input: expected array, received number"
58+
}
59+
]]
60+
`)
5261
})
5362
})

packages/app/zod-extras/src/utils/toArrayPreprocessor.test.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { z } from 'zod'
2+
import { z } from 'zod/v4'
33

44
import { toArrayPreprocessor } from './toArrayPreprocessor.ts'
55

@@ -92,7 +92,18 @@ describe('toArrayPreprocessor', () => {
9292
SCHEMA.parse({
9393
payload: { foo: 'bar' },
9494
}),
95-
).toThrow(/Expected array, received object/)
95+
).toThrowErrorMatchingInlineSnapshot(`
96+
[ZodError: [
97+
{
98+
"expected": "array",
99+
"code": "invalid_type",
100+
"path": [
101+
"payload"
102+
],
103+
"message": "Invalid input: expected array, received object"
104+
}
105+
]]
106+
`)
96107
})
97108

98109
it('does not convert date input', () => {
@@ -104,7 +115,18 @@ describe('toArrayPreprocessor', () => {
104115
SCHEMA.parse({
105116
createdAt: new Date(),
106117
}),
107-
).toThrow(/Expected array, received date/)
118+
).toThrowErrorMatchingInlineSnapshot(`
119+
[ZodError: [
120+
{
121+
"expected": "array",
122+
"code": "invalid_type",
123+
"path": [
124+
"createdAt"
125+
],
126+
"message": "Invalid input: expected array, received Date"
127+
}
128+
]]
129+
`)
108130
})
109131

110132
it('does not convert undefined input', () => {
@@ -130,7 +152,18 @@ describe('toArrayPreprocessor', () => {
130152
SCHEMA.parse({
131153
createdAt: null,
132154
}),
133-
).toThrow(/Expected array, received null/)
155+
).toThrowErrorMatchingInlineSnapshot(`
156+
[ZodError: [
157+
{
158+
"expected": "array",
159+
"code": "invalid_type",
160+
"path": [
161+
"createdAt"
162+
],
163+
"message": "Invalid input: expected array, received null"
164+
}
165+
]]
166+
`)
134167
})
135168

136169
it('does not convert function input', () => {
@@ -142,6 +175,17 @@ describe('toArrayPreprocessor', () => {
142175
SCHEMA.parse({
143176
name: (x: string) => x,
144177
}),
145-
).toThrow(/Expected array, received function/)
178+
).toThrowErrorMatchingInlineSnapshot(`
179+
[ZodError: [
180+
{
181+
"expected": "array",
182+
"code": "invalid_type",
183+
"path": [
184+
"name"
185+
],
186+
"message": "Invalid input: expected array, received function"
187+
}
188+
]]
189+
`)
146190
})
147191
})

packages/app/zod-extras/src/utils/toBooleanPreprocessor.test.ts

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { z } from 'zod'
2+
import { z } from 'zod/v4'
33

44
import { toBooleanPreprocessor } from './toBooleanPreprocessor.ts'
55

@@ -61,7 +61,18 @@ describe('toBooleanPreprocessor', () => {
6161
SCHEMA.parse({
6262
foo: 'bar',
6363
}),
64-
).toThrow(/Expected boolean, received string/)
64+
).toThrowErrorMatchingInlineSnapshot(`
65+
[ZodError: [
66+
{
67+
"expected": "boolean",
68+
"code": "invalid_type",
69+
"path": [
70+
"foo"
71+
],
72+
"message": "Invalid input: expected boolean, received string"
73+
}
74+
]]
75+
`)
6576
})
6677

6778
it('does not convert invalid numbers to boolean', () => {
@@ -73,7 +84,18 @@ describe('toBooleanPreprocessor', () => {
7384
SCHEMA.parse({
7485
isActive: 123,
7586
}),
76-
).toThrow(/Expected boolean, received number/)
87+
).toThrowErrorMatchingInlineSnapshot(`
88+
[ZodError: [
89+
{
90+
"expected": "boolean",
91+
"code": "invalid_type",
92+
"path": [
93+
"isActive"
94+
],
95+
"message": "Invalid input: expected boolean, received number"
96+
}
97+
]]
98+
`)
7799
})
78100

79101
it('does not convert boolean input', () => {
@@ -102,7 +124,18 @@ describe('toBooleanPreprocessor', () => {
102124
SCHEMA.parse({
103125
payload: { foo: 'bar' },
104126
}),
105-
).toThrow(/Expected boolean, received object/)
127+
).toThrowErrorMatchingInlineSnapshot(`
128+
[ZodError: [
129+
{
130+
"expected": "boolean",
131+
"code": "invalid_type",
132+
"path": [
133+
"payload"
134+
],
135+
"message": "Invalid input: expected boolean, received object"
136+
}
137+
]]
138+
`)
106139
})
107140

108141
it('does not convert date input', () => {
@@ -114,7 +147,18 @@ describe('toBooleanPreprocessor', () => {
114147
SCHEMA.parse({
115148
createdAt: new Date(),
116149
}),
117-
).toThrow(/Expected boolean, received date/)
150+
).toThrowErrorMatchingInlineSnapshot(`
151+
[ZodError: [
152+
{
153+
"expected": "boolean",
154+
"code": "invalid_type",
155+
"path": [
156+
"createdAt"
157+
],
158+
"message": "Invalid input: expected boolean, received Date"
159+
}
160+
]]
161+
`)
118162
})
119163

120164
it('does not convert undefined input', () => {
@@ -140,6 +184,17 @@ describe('toBooleanPreprocessor', () => {
140184
SCHEMA.parse({
141185
name: (x: string) => x,
142186
}),
143-
).toThrow(/Expected boolean, received function/)
187+
).toThrowErrorMatchingInlineSnapshot(`
188+
[ZodError: [
189+
{
190+
"expected": "boolean",
191+
"code": "invalid_type",
192+
"path": [
193+
"name"
194+
],
195+
"message": "Invalid input: expected boolean, received function"
196+
}
197+
]]
198+
`)
144199
})
145200
})

packages/app/zod-extras/src/utils/toDatePreprocessor.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { z } from 'zod'
2+
import { z } from 'zod/v4'
33

44
import { toDatePreprocessor } from './toDateProcessor.ts'
55

@@ -47,6 +47,17 @@ describe('toDatePreprocessor', () => {
4747
SCHEMA.parse({
4848
createdAt: (x: string) => x,
4949
}),
50-
).toThrow(/Expected date, received function/)
50+
).toThrowErrorMatchingInlineSnapshot(`
51+
[ZodError: [
52+
{
53+
"expected": "date",
54+
"code": "invalid_type",
55+
"path": [
56+
"createdAt"
57+
],
58+
"message": "Invalid input: expected date, received function"
59+
}
60+
]]
61+
`)
5162
})
5263
})

0 commit comments

Comments
 (0)