Skip to content

Commit

Permalink
fix typings DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Oct 16, 2023
1 parent 4c3717b commit 5a8fde6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 209 deletions.
22 changes: 13 additions & 9 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import wsPlugin, { WebsocketHandler, SocketStream } from '..';
import fastifyWebsocket, { WebsocketHandler, SocketStream, fastifyWebsocket as namedFastifyWebsocket, default as defaultFastifyWebsocket } from '..';
import type { IncomingMessage } from "http";
import fastify, { RouteOptions, FastifyRequest, FastifyInstance, FastifyReply, RequestGenericInterface, FastifyBaseLogger, RawServerDefault, FastifySchema, RawRequestDefaultExpression, RawServerBase, ContextConfigDefault, RawReplyDefaultExpression } from 'fastify';
import { expectType } from 'tsd';
Expand All @@ -9,10 +9,10 @@ import { Static, Type } from '@sinclair/typebox'
import { ResolveFastifyRequestType } from 'fastify/types/type-provider';

const app: FastifyInstance = fastify();
app.register(wsPlugin);
app.register(wsPlugin, {});
app.register(wsPlugin, { options: { maxPayload: 123 } });
app.register(wsPlugin, {
app.register(fastifyWebsocket);
app.register(fastifyWebsocket, {});
app.register(fastifyWebsocket, { options: { maxPayload: 123 } });
app.register(fastifyWebsocket, {
errorHandler: function errorHandler(error: Error, connection: SocketStream, request: FastifyRequest, reply: FastifyReply): void {
expectType<FastifyInstance>(this);
expectType<Error>(error)
Expand All @@ -21,9 +21,9 @@ app.register(wsPlugin, {
expectType<FastifyReply>(reply)
}
});
app.register(wsPlugin, { options: { perMessageDeflate: true } });
app.register(wsPlugin, { preClose: function syncPreclose() {} });
app.register(wsPlugin, { preClose: async function asyncPreclose(){} });
app.register(fastifyWebsocket, { options: { perMessageDeflate: true } });
app.register(fastifyWebsocket, { preClose: function syncPreclose() {} });
app.register(fastifyWebsocket, { preClose: async function asyncPreclose(){} });

app.get('/websockets-via-inferrence', { websocket: true }, async function (connection, request) {
expectType<FastifyInstance>(this);
Expand Down Expand Up @@ -197,4 +197,8 @@ server.get('/websockets-no-type-inference',
expectType<unknown>(request.body);
expectType<unknown>(request.query);
expectType<IncomingMessage['headers']>(request.headers);
});
});

expectType<typeof fastifyWebsocket>(namedFastifyWebsocket);
expectType<typeof fastifyWebsocket>(defaultFastifyWebsocket);

200 changes: 0 additions & 200 deletions types/named-import.test-d.ts

This file was deleted.

0 comments on commit 5a8fde6

Please sign in to comment.