From c6c06ac9756f06a1c4b38de22574a6c41706f3d8 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Wed, 6 May 2026 21:47:55 +0200 Subject: [PATCH] refactor(types): migrate from tsd to tstyche --- package.json | 6 ++-- types/index.test-d.ts | 67 ---------------------------------------- types/index.tst.ts | 71 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 70 deletions(-) delete mode 100644 types/index.test-d.ts create mode 100644 types/index.tst.ts diff --git a/package.json b/package.json index 02c9de5..abaef4b 100644 --- a/package.json +++ b/package.json @@ -63,14 +63,14 @@ "eslint": "^9.17.0", "neostandard": "^0.12.0", "supertest": "6.3.4", - "tsd": "^0.33.0" + "tstyche": "^7.0.0" }, "scripts": { "lint": "eslint", "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:coverage": "c8 --reporter html node --test", - "test:typescript": "tsd", + "test:typescript": "tstyche", "test:unit": "c8 --100 node --test" } -} +} \ No newline at end of file diff --git a/types/index.test-d.ts b/types/index.test-d.ts deleted file mode 100644 index 1711484..0000000 --- a/types/index.test-d.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { Dirent } from 'node:fs' -import { resolve } from 'node:path' -import { Readable } from 'node:stream' -import { expectType } from 'tsd' -import send, { DirectorySendResult, ErrorSendResult, FileSendResult, SendResult } from '..' - -send.mime.define({ - 'application/x-my-type': ['x-mt', 'x-mtt'] -}) - -expectType<(value: string) => boolean>(send.isUtf8MimeType) -expectType(send.isUtf8MimeType('application/json')) - -const req: any = {} - -{ - const result = await send(req, '/test.html', { - acceptRanges: true, - maxContentRangeChunkSize: 10, - immutable: true, - maxAge: 0, - root: resolve(__dirname, '/wwwroot') - }) - - expectType(result) - expectType(result.statusCode) - expectType>(result.headers) - expectType(result.stream) -} - -{ - const result = await send(req, '/test.html', { contentType: true, maxAge: 0, root: resolve(__dirname, '/wwwroot') }) - - expectType(result) - expectType(result.statusCode) - expectType>(result.headers) - expectType(result.stream) -} - -{ - const result = await send(req, '/test.html', { contentType: false, root: resolve(__dirname, '/wwwroot') }) - - expectType(result) - expectType(result.statusCode) - expectType>(result.headers) - expectType(result.stream) -} - -const result = await send(req, '/test.html') -switch (result.type) { - case 'file': { - expectType(result) - expectType(result.metadata.path) - expectType(result.metadata.stat) - break - } - case 'directory': { - expectType(result) - expectType(result.metadata.path) - expectType(result.metadata.requestPath) - break - } - case 'error': { - expectType(result) - expectType(result.metadata.error) - } -} diff --git a/types/index.tst.ts b/types/index.tst.ts new file mode 100644 index 0000000..032a54f --- /dev/null +++ b/types/index.tst.ts @@ -0,0 +1,71 @@ +import { Dirent } from 'node:fs' +import { resolve } from 'node:path' +import { Readable } from 'node:stream' +import { expect } from 'tstyche' +import send, { + DirectorySendResult, + ErrorSendResult, + FileSendResult, + SendResult +} from '..' + +send.mime.define({ + 'application/x-my-type': ['x-mt', 'x-mtt'] +}) + +expect(send.isUtf8MimeType).type.toBe<(value: string) => boolean>() +expect(send.isUtf8MimeType('application/json')).type.toBe() + +const req: any = {}; + +(async () => { + { + const result = await send(req, '/test.html', { + acceptRanges: true, + maxContentRangeChunkSize: 10, + immutable: true, + maxAge: 0, + root: resolve(__dirname, '/wwwroot') + }) + + expect(result).type.toBe() + expect(result.statusCode).type.toBe() + expect(result.headers).type.toBe>() + expect(result.stream).type.toBe() + } + + { + const result = await send(req, '/test.html', { + contentType: true, + maxAge: 0, + root: resolve(__dirname, '/wwwroot') + }) + + expect(result).type.toBe() + expect(result.statusCode).type.toBe() + expect(result.headers).type.toBe>() + expect(result.stream).type.toBe() + } + + const result = await send(req, '/test.html') + + switch (result.type) { + case 'file': { + expect(result).type.toBe() + expect(result.metadata.path).type.toBe() + expect(result.metadata.stat).type.toBe() + break + } + case 'directory': { + expect(result).type.toBe() + expect(result.metadata.path).type.toBe() + expect(result.metadata.requestPath).type.toBe() + break + } + case 'error': { + expect(result).type.toBe() + expect(result.metadata.error).type.toBe() + break + } + } +})()