diff --git a/src/__test__/utils.test-d.ts b/src/__test__/utils.test-d.ts new file mode 100644 index 0000000..ff52acc --- /dev/null +++ b/src/__test__/utils.test-d.ts @@ -0,0 +1,26 @@ +import { describe, expectTypeOf, it } from "vitest"; +import { allHeaderFields, headerField } from "../utils.ts"; + +describe("headerField", () => { + it("has correct return type", () => { + expectTypeOf( + headerField("Some-Header", "Addresses") + ).toEqualTypeOf<`header:Some-Header:asAddresses`>(); + + expectTypeOf( + headerField("From", "Raw") + ).toEqualTypeOf<`header:From:asRaw`>(); + }); +}); + +describe("allHeaderFields", () => { + it("has correct return type", () => { + expectTypeOf( + allHeaderFields("Some-Header", "Addresses") + ).toEqualTypeOf<`header:Some-Header:asAddresses:all`>(); + + expectTypeOf( + allHeaderFields("From", "Raw") + ).toEqualTypeOf<`header:From:asRaw:all`>(); + }); +}); diff --git a/src/__test__/utils.test.ts b/src/__test__/utils.test.ts new file mode 100644 index 0000000..c2666fa --- /dev/null +++ b/src/__test__/utils.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from "vitest"; +import { allHeaderFields, headerField } from "../utils.ts"; + +describe("headerField", () => { + it("passes name and form arguments into string", () => { + expect(headerField("Some-Header", "Addresses")).toBe( + "header:Some-Header:asAddresses" + ); + }); +}); + +describe("allHeaderFields", () => { + it("applies correct suffix", async () => { + expect(allHeaderFields("Some-Header", "Addresses")).toBe( + "header:Some-Header:asAddresses:all" + ); + }); +}); diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..703c917 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*"], + "exclude": ["src/**/__test__"] +} diff --git a/tsconfig.json b/tsconfig.json index 8c50101..1344c5a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,10 @@ "declaration": true, "outDir": "dist", "declarationMap": true, - "noUnusedLocals": true + "noUnusedLocals": true, + "types": [ + "vitest/importMeta" + ] }, "include": ["src/**/*"] } diff --git a/tsup.config.js b/tsup.config.js index 16c7426..28177b3 100644 --- a/tsup.config.js +++ b/tsup.config.js @@ -11,6 +11,6 @@ export default defineConfig({ target: ["es2018"], sourcemap: true, async onSuccess() { - execSync("tsc"); + execSync("tsc --project tsconfig.build.json"); } }); diff --git a/vitest.config.ts b/vitest.config.ts index 691b3ff..354e0f4 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -3,7 +3,8 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { typecheck: { - enabled: true - } - } + enabled: true, + }, + includeSource: ["src/**/*.ts"], + }, });