Skip to content

Commit dc2540d

Browse files
Tony133mrazauskas
andauthored
refactor(types): migrate from tsd to tstyche (#837)
* refactor(types): migrate from tsd to tstyche * chore: update package.json * chore: update index.tst.ts Co-authored-by: Tom Mrazauskas <tom@mrazauskas.de> Signed-off-by: Antonio Tripodi <Tony133@users.noreply.github.com> --------- Signed-off-by: Antonio Tripodi <Tony133@users.noreply.github.com> Co-authored-by: Tom Mrazauskas <tom@mrazauskas.de>
1 parent 03199b7 commit dc2540d

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"benchmark": "node --expose-gc ./benchmark/bench-cmp-lib.js",
1313
"lint": "eslint",
1414
"lint:fix": "eslint --fix",
15-
"test:typescript": "tsd",
15+
"test:typescript": "tstyche",
1616
"test:unit": "c8 node --test",
1717
"test": "npm run test:unit && npm run test:typescript"
1818
},
@@ -72,7 +72,7 @@
7272
"neostandard": "^0.13.0",
7373
"simple-git": "^3.30.0",
7474
"tinybench": "^6.0.0",
75-
"tsd": "^0.33.0",
75+
"tstyche": "^7.1.0",
7676
"typebox": "^1.0.81",
7777
"typescript": "~6.0.2",
7878
"webpack": "^5.104.1"
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Test using this disabled, see https://github.com/fastify/fast-json-stringify/pull/683
22
import Ajv from 'ajv'
33
import build, { restore, Schema, validLargeArrayMechanisms } from '..'
4-
import { expectError, expectType } from 'tsd'
4+
import { expect } from 'tstyche'
55

66
// Number schemas
77
build({
@@ -26,9 +26,10 @@ build({
2626
build({
2727
type: 'number'
2828
}, { rounding: 'trunc' })
29-
expectError(build({
29+
30+
expect(build).type.not.toBeCallableWith({
3031
type: 'number'
31-
}, { rounding: 'invalid' }))
32+
}, { rounding: 'invalid' })
3233

3334
// String schema
3435
build({
@@ -153,7 +154,6 @@ build({
153154
})({ something: 'a string', somethingElse: 42 })
154155

155156
// String schema with format
156-
157157
build({
158158
type: 'string',
159159
format: 'date-time'
@@ -181,7 +181,6 @@ str = build({
181181
type: 'number'
182182
}, { mode: 'standalone' })
183183
*/
184-
185184
const debugCompiled = build({
186185
title: 'default string',
187186
type: 'object',
@@ -191,11 +190,12 @@ const debugCompiled = build({
191190
}
192191
}
193192
}, { mode: 'debug' })
194-
expectType<ReturnType<typeof build>>(build.restore(debugCompiled))
195-
expectType<ReturnType<typeof build>>(restore(debugCompiled))
196193

197-
expectType<string[]>(build.validLargeArrayMechanisms)
198-
expectType<string[]>(validLargeArrayMechanisms)
194+
expect(build.restore(debugCompiled)).type.toBe(build({} as Schema))
195+
expect(restore(debugCompiled)).type.toBe(build({} as Schema))
196+
197+
expect(build.validLargeArrayMechanisms).type.toBe<string[]>()
198+
expect(validLargeArrayMechanisms).type.toBe<string[]>()
199199

200200
/**
201201
* Schema inference
@@ -211,10 +211,11 @@ const stringify3 = build({
211211
type: 'object',
212212
properties: { a: { type: 'string' } },
213213
})
214+
214215
stringify3<InferenceSchema>({ id: '123' })
215216
stringify3<InferenceSchema>({ a: 123, id: '123' })
216-
expectError(stringify3<InferenceSchema>({ anotherOne: 'bar' }))
217-
expectError(stringify3<Schema>({ a: 'bar' }))
217+
expect(stringify3<InferenceSchema>).type.not.toBeCallableWith({ anotherOne: 'bar' })
218+
expect(stringify3<Schema>).type.not.toBeCallableWith({ a: 'bar' })
218219

219220
// Without inference
220221
const stringify4 = build({
@@ -231,29 +232,28 @@ const stringify5 = build({
231232
type: 'string',
232233
})
233234
stringify5('foo')
234-
expectError(stringify5({ id: '123' }))
235+
expect(stringify5).type.not.toBeCallableWith({ id: '123' })
235236

236237
// Without inference - null type
237238
const stringify6 = build({
238239
type: 'null',
239240
})
240241
stringify6(null)
241-
expectError(stringify6('a string'))
242+
expect(stringify6).type.not.toBeCallableWith('a string')
242243

243244
// Without inference - boolean type
244245
const stringify7 = build({
245246
type: 'boolean',
246247
})
247248
stringify7(true)
248-
expectError(stringify7('a string'))
249+
expect(stringify7).type.not.toBeCallableWith('a string')
249250

250251
// largeArrayMechanism
251-
252252
build({}, { largeArrayMechanism: 'json-stringify' })
253253
build({}, { largeArrayMechanism: 'default' })
254-
expectError(build({} as Schema, { largeArrayMechanism: 'invalid' }))
254+
expect(build).type.not.toBeCallableWith({} as Schema, { largeArrayMechanism: 'invalid' })
255255

256256
build({}, { largeArraySize: 2000 })
257257
build({}, { largeArraySize: '2e4' })
258258
build({}, { largeArraySize: 2n })
259-
expectError(build({} as Schema, { largeArraySize: ['asdf'] }))
259+
expect(build).type.not.toBeCallableWith({} as Schema, { largeArraySize: ['asdf'] })

0 commit comments

Comments
 (0)