diff --git a/package.json b/package.json index 06fea71..ab33e38 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint": "eslint", "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", - "test:typescript": "tsd", + "test:typescript": "tstyche", "test:unit": "c8 --100 node --test" }, "keywords": [ @@ -65,16 +65,13 @@ "eslint": "^9.17.0", "fastify": "^5.0.0", "neostandard": "^0.13.0", - "tsd": "^0.33.0", + "tstyche": "^7.1.0", "typescript": "~6.0.2" }, "dependencies": { "fastify-plugin": "^5.0.0", "toad-cache": "^3.7.0" }, - "tsd": { - "directory": "test" - }, "publishConfig": { "access": "public" } diff --git a/types/index.test-d.ts b/types/index.tst.ts similarity index 85% rename from types/index.test-d.ts rename to types/index.tst.ts index 4040e66..55c26e4 100644 --- a/types/index.test-d.ts +++ b/types/index.tst.ts @@ -1,5 +1,5 @@ import fastify, { FastifyRequest } from 'fastify' -import { expectType } from 'tsd' +import { expect } from 'tstyche' import fastifyCors, { AsyncOriginFunction, FastifyCorsOptions, @@ -240,7 +240,10 @@ appHttp2.register(fastifyCors, { }) appHttp2.register(fastifyCors, { - origin: (origin: string | undefined, cb: (err: Error | null, allow: boolean) => void) => { + origin: ( + origin: string | undefined, + cb: (err: Error | null, allow: boolean) => void + ) => { if (origin === undefined || /localhost/.test(origin)) { cb(null, true) return @@ -259,39 +262,47 @@ appHttp2.register(fastifyCors, { strictPreflight: false }) -appHttp2.register(fastifyCors, (): FastifyCorsOptionsDelegate => (_req, cb) => { - cb(null, { - origin: [/\*/, /something/], - allowedHeaders: ['authorization', 'content-type'], - methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], - credentials: true, - exposedHeaders: ['authorization'], - maxAge: 13000, - cacheControl: 13000, - preflightContinue: false, - optionsSuccessStatus: 200, - preflight: false, - strictPreflight: false - }) -}) +appHttp2.register( + fastifyCors, + (): FastifyCorsOptionsDelegate => (_req, cb) => { + cb(null, { + origin: [/\*/, /something/], + allowedHeaders: ['authorization', 'content-type'], + methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], + credentials: true, + exposedHeaders: ['authorization'], + maxAge: 13000, + cacheControl: 13000, + preflightContinue: false, + optionsSuccessStatus: 200, + preflight: false, + strictPreflight: false + }) + } +) -appHttp2.register(fastifyCors, (): FastifyCorsOptionsDelegatePromise => () => { - return Promise.resolve({ - origin: [/\*/, /something/], - allowedHeaders: ['authorization', 'content-type'], - methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], - credentials: true, - exposedHeaders: ['authorization'], - maxAge: 13000, - cacheControl: 13000, - preflightContinue: false, - optionsSuccessStatus: 200, - preflight: false, - strictPreflight: false - }) -}) +appHttp2.register( + fastifyCors, + (): FastifyCorsOptionsDelegatePromise => () => { + return Promise.resolve({ + origin: [/\*/, /something/], + allowedHeaders: ['authorization', 'content-type'], + methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], + credentials: true, + exposedHeaders: ['authorization'], + maxAge: 13000, + cacheControl: 13000, + preflightContinue: false, + optionsSuccessStatus: 200, + preflight: false, + strictPreflight: false + }) + } +) -const delegate: FastifyPluginOptionsDelegate = () => async () => { +const delegate: FastifyPluginOptionsDelegate< + FastifyCorsOptionsDelegatePromise +> = () => async () => { return { origin: [/\*/, /something/], allowedHeaders: ['authorization', 'content-type'], @@ -372,17 +383,19 @@ appHttp2.register(fastifyCors, delegate) appHttp2.register(fastifyCors, { hook: 'preParsing', origin: function (origin, cb) { - expectType(origin) + expect(origin).type.toBe() cb(null, false) - }, + } }) -const asyncOriginFn: AsyncOriginFunction = async function (origin): Promise { - expectType(origin) +const asyncOriginFn: AsyncOriginFunction = async function ( + origin +): Promise { + expect(origin).type.toBe() return false } appHttp2.register(fastifyCors, { hook: 'preParsing', - origin: asyncOriginFn, + origin: asyncOriginFn })