11import fastify , { FastifyInstance } from 'fastify'
22import { createReadStream } from 'node:fs'
3- import { expectError , expectType } from 'tsd '
3+ import { expect } from 'tstyche '
44import * as zlib from 'node:zlib'
55import fastifyCompress , { FastifyCompressOptions } from '..'
66
@@ -39,11 +39,11 @@ app.register(fastifyCompress, {
3939} )
4040
4141app . get ( '/test-one' , async ( _request , reply ) => {
42- expectType < void > ( reply . compress ( stream ) )
42+ expect ( reply . compress ( stream ) ) . type . toBe < void > ( )
4343} )
4444
4545app . 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
7070appWithoutGlobal . 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
107107appWithoutGlobal . 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
130130const 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
136136app . 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
141141app . 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