Skip to content

Commit

Permalink
Add util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
htunnicliff committed Oct 30, 2024
1 parent b420181 commit c1cf66e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
26 changes: 26 additions & 0 deletions src/__test__/utils.test-d.ts
Original file line number Diff line number Diff line change
@@ -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`>();
});
});
18 changes: 18 additions & 0 deletions src/__test__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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"
);
});
});
5 changes: 5 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*"],
"exclude": ["src/**/__test__"]
}
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"declaration": true,
"outDir": "dist",
"declarationMap": true,
"noUnusedLocals": true
"noUnusedLocals": true,
"types": [
"vitest/importMeta"
]
},
"include": ["src/**/*"]
}
2 changes: 1 addition & 1 deletion tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export default defineConfig({
target: ["es2018"],
sourcemap: true,
async onSuccess() {
execSync("tsc");
execSync("tsc --project tsconfig.build.json");
}
});
7 changes: 4 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
typecheck: {
enabled: true
}
}
enabled: true,
},
includeSource: ["src/**/*.ts"],
},
});

0 comments on commit c1cf66e

Please sign in to comment.