Skip to content

Commit 0aacfec

Browse files
Tony133mrazauskas
andauthored
refactor(types): migrate from tsd to tstyche (#392)
* 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> * 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 d61f911 commit 0aacfec

2 files changed

Lines changed: 34 additions & 37 deletions

File tree

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
"fastify": "^5.0.0",
2222
"jsonstream": "^1.0.3",
2323
"neostandard": "^0.13.0",
24-
"tsd": "^0.33.0",
24+
"tstyche": "^7.1.0",
2525
"typescript": "~6.0.2"
2626
},
2727
"scripts": {
2828
"lint": "eslint",
2929
"lint:fix": "eslint --fix",
3030
"test": "npm run test:unit && npm run test:typescript",
31-
"test:typescript": "tsd",
31+
"test:typescript": "tstyche",
3232
"test:unit": "node --test",
3333
"test:coverage": "c8 node --test && c8 report --reporter=html",
3434
"test:unit:verbose": "npm run test:unit -- -Rspec"
@@ -80,10 +80,7 @@
8080
"type": "git",
8181
"url": "git+https://github.com/fastify/fastify-compress.git"
8282
},
83-
"tsd": {
84-
"directory": "types"
85-
},
8683
"publishConfig": {
8784
"access": "public"
8885
}
89-
}
86+
}
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fastify, { FastifyInstance } from 'fastify'
22
import { createReadStream } from 'node:fs'
3-
import { expectError, expectType } from 'tsd'
3+
import { expect } from 'tstyche'
44
import * as zlib from 'node:zlib'
55
import fastifyCompress, { FastifyCompressOptions } from '..'
66

@@ -39,11 +39,11 @@ app.register(fastifyCompress, {
3939
})
4040

4141
app.get('/test-one', async (_request, reply) => {
42-
expectType<void>(reply.compress(stream))
42+
expect(reply.compress(stream)).type.toBe<void>()
4343
})
4444

4545
app.get('/test-two', async (_request, reply) => {
46-
expectError(reply.compress())
46+
expect(reply.compress).type.not.toBeCallableWith()
4747
})
4848

4949
// Instantiation of an app without global
@@ -64,7 +64,7 @@ appWithoutGlobal.get('/one', {
6464
}
6565
}
6666
}, (_request, reply) => {
67-
expectType<void>(reply.type('text/plain').compress(stream))
67+
expect(reply.type('text/plain').compress(stream)).type.toBe<void>()
6868
})
6969

7070
appWithoutGlobal.get('/two', {
@@ -82,27 +82,27 @@ appWithoutGlobal.get('/two', {
8282
}
8383
}
8484
}, (_request, reply) => {
85-
expectType<void>(reply.type('text/plain').compress(stream))
85+
expect(reply.type('text/plain').compress(stream)).type.toBe<void>()
8686
})
8787

88-
expectError(
89-
appWithoutGlobal.get('/throw-a-ts-arg-error-on-shorthand-route', {
90-
compress: 'bad compress route option value',
91-
decompress: 'bad decompress route option value'
92-
}, (_request, reply) => {
93-
expectType<void>(reply.type('text/plain').compress(stream))
94-
})
95-
)
88+
appWithoutGlobal.get('/throw-a-ts-arg-error-on-shorthand-route', {
89+
// @ts-expect-error Type 'string' is not assignable
90+
compress: 'bad compress route option value',
91+
// @ts-expect-error Type 'string' is not assignable
92+
decompress: 'bad decompress route option value'
93+
}, (_request, reply) => {
94+
reply.type('text/plain').compress(stream)
95+
})
9696

97-
expectError(
98-
appWithoutGlobal.route({
99-
method: 'GET',
100-
path: '/throw-a-ts-arg-error',
101-
compress: 'bad compress route option value',
102-
decompress: 'bad decompress route option value',
103-
handler: (_request, reply) => { expectType<void>(reply.type('text/plain').compress(stream)) }
104-
})
105-
)
97+
appWithoutGlobal.route({
98+
method: 'GET',
99+
path: '/throw-a-ts-arg-error',
100+
// @ts-expect-error Type 'string' is not assignable
101+
compress: 'bad compress route option value',
102+
// @ts-expect-error Type 'string' is not assignable
103+
decompress: 'bad decompress route option value',
104+
handler: (_request, reply) => { reply.type('text/plain').compress(stream) }
105+
})
106106

107107
appWithoutGlobal.inject(
108108
{
@@ -113,29 +113,29 @@ appWithoutGlobal.inject(
113113
}
114114
},
115115
(err) => {
116-
expectType<Error | undefined>(err)
116+
expect(err).type.toBe<Error | undefined>()
117117
}
118118
)
119119

120120
// Test that invalid encoding values trigger TypeScript errors
121-
expectError(fastify().register(fastifyCompress, {
121+
expect(fastify().register).type.not.toBeCallableWith(fastifyCompress, {
122122
encodings: ['invalid-encoding']
123-
}))
123+
})
124124

125-
expectError(fastify().register(fastifyCompress, {
125+
expect(fastify().register).type.not.toBeCallableWith(fastifyCompress, {
126126
requestEncodings: ['another-invalid-encoding']
127-
}))
127+
})
128128

129129
// Instantiation of an app that should trigger a typescript error
130130
const appThatTriggerAnError = fastify()
131-
expectError(appThatTriggerAnError.register(fastifyCompress, {
131+
expect(appThatTriggerAnError.register).type.not.toBeCallableWith(fastifyCompress, {
132132
global: true,
133133
thisOptionDoesNotExist: 'trigger a typescript error'
134-
}))
134+
})
135135

136136
app.get('/ts-fetch-response', async (_request, reply) => {
137137
const resp = new Response('ok', { headers: { 'content-type': 'text/plain' } })
138-
expectType<void>(reply.compress(resp))
138+
expect(reply.compress(resp)).type.toBe<void>()
139139
})
140140

141141
app.get('/ts-web-readable-stream', async (_request, reply) => {
@@ -145,5 +145,5 @@ app.get('/ts-web-readable-stream', async (_request, reply) => {
145145
controller.close()
146146
}
147147
})
148-
expectType<void>(reply.compress(stream))
148+
expect(reply.compress(stream)).type.toBe<void>()
149149
})

0 commit comments

Comments
 (0)