Skip to content

Commit

Permalink
🐛 Fixed typescript configuration (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadkebab authored Sep 27, 2024
1 parent 6feaa15 commit e2f784f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dev": "bun run src/index.ts",
"build": "bun run build:bun && bun run build:emitDeclarations",
"build:bun": "bun build ./src/index.ts --outdir dist --target bun --minify --sourcemap=external",
"build:emitDeclarations": "tsc --emitDeclarationOnly --project tsconfig.json --tsBuildInfoFile './dist/.tsbuildinfo'",
"build:emitDeclarations": "tsc --emitDeclarationOnly --project tsconfig.build.json --tsBuildInfoFile './dist/.tsbuildinfo'",
"sandbox": "bun run ./sandbox/index.ts",
"test": "bun test --coverage",
"lint": "bunx biome lint --write ./src ./tests",
Expand All @@ -41,4 +41,4 @@
"testing",
"unit-testing"
]
}
}
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const makeResponse = (
status,
statusText: status,
url,
headers: response?.headers ?? headers,
headers: new Headers(response?.headers ?? headers),
text: () => Promise.resolve(body),
json: () => Promise.resolve(body),
redirected: false,
Expand Down
8 changes: 6 additions & 2 deletions tests/mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ describe("Mock", () => {
},
};
expect(mock(request, options)).toBe(true);
expect(mock(request, options)).toBe(undefined);

// for some reason the expect function fails to infer the return type correctly and only infers
// it as boolean so we specify the type of expect explicitly as the return type of the function
expect<ReturnType<typeof mock>>(mock(request, options)).toBe(undefined);
await fetch(`${API_URL}/users`);
});

Expand Down Expand Up @@ -192,7 +195,8 @@ describe("Mock", () => {
const response = await fetch(`${API_URL}/users`, {
headers: { "x-foo-bar": "baz" },
});
expect(response.headers).toEqual({ "x-baz-qux": "quux" });

expect(response.headers).toEqual(new Headers({ "x-baz-qux": "quux" }));
});

test("mock: should not mock a request if it is not registered", async () => {
Expand Down
22 changes: 22 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"moduleDetection": "force",
"noEmit": false,
"declaration": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types" // add Bun global
]
}
}
9 changes: 9 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "sandbox", "tests"]
}
30 changes: 6 additions & 24 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"moduleDetection": "force",
"outDir": "dist",
"rootDir": "src",
"noEmit": false,
"declaration": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types" // add Bun global
]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "tests", "sandbox"]
"extends": "./tsconfig.base.json",
"compilerOptions": {
"rootDirs": ["src", "tests"]
},
"include": ["src/**/*.ts", "tests/**/*.ts"],
"exclude": ["node_modules", "dist", "sandbox"]
}

0 comments on commit e2f784f

Please sign in to comment.