diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd16d757..f7e697fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,9 @@ jobs: - name: Run Biome Check run: npx @biomejs/biome ci . + - name: Run TypeScript Typecheck + run: npm run typecheck + - name: Run Tests run: npm test diff --git a/AGENTS.md b/AGENTS.md index f1be53b9..1afbb187 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,6 +19,7 @@ Run the ones for the areas you touched. CI runs the check column; use the fix co |---|---|---| | Biome lint & format | `npm run check` | `npm run check:fix` | | Pre-dev auto-format | — | `npm run predev` | +| TypeScript typecheck | `npm run typecheck` | — | | Unit tests | `npm run test` | — | | Web production build | `npm run build` | — | | Electron development | `npm run electron-dev` | — | @@ -73,4 +74,4 @@ Contribution workflow Definition of done ## Definition of done -A change is not finished until the relevant checks pass locally. At minimum, run `npm run check` and `npm run test`. If you changed the web application or production build configuration, also run `npm run build`. If you touched input drivers, gestures, or WebRTC signaling, test end-to-end via QR code scan on a mobile device or VM. +A change is not finished until the relevant checks pass locally. At minimum, run `npm run check`, `npm run typecheck` and `npm run test`. If you changed the web application or production build configuration, also run `npm run build`. If you touched input drivers, gestures, or WebRTC signaling, test end-to-end via QR code scan on a mobile device or VM. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e87cc67a..cc2a78df 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -133,6 +133,9 @@ We use Vitest for testing and Biome for formatting/linting: # Run tests npm run test +# Type-check (tsc --noEmit) +npm run typecheck + # Format & Lint code npm run check @@ -178,6 +181,7 @@ git push origin feature/your-feature-name ### Before Submitting - [ ] Your code follows the project's style guidelines (`npm run check`) +- [ ] Your code type-checks (`npm run typecheck`) - [ ] You've tested your changes thoroughly (`npm run test`) - [ ] You've updated relevant documentation - [ ] Your commits are clean and well-organized diff --git a/package.json b/package.json index 9f665b57..ed29b51b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "preview": "vite preview", "test": "vitest run", "check": "biome check .", - "check:fix": "biome check . --write" + "check:fix": "biome check . --write", + "typecheck": "tsc --noEmit" }, "dependencies": { "@imxade/inject": "^0.1.1", diff --git a/src/server/signalling/handlers/sessionStore.test.ts b/src/server/signalling/handlers/sessionStore.test.ts index e292ec4e..535632d7 100644 --- a/src/server/signalling/handlers/sessionStore.test.ts +++ b/src/server/signalling/handlers/sessionStore.test.ts @@ -141,7 +141,7 @@ describe("sessionStore lifecycle and SSE delivery", () => { const response = new FakeResponse() client.sessionSseRes = response as unknown as ServerResponse const onTimeout = vi.fn() - client.disconnectTimer = setTimeout(onTimeout, 1000) + client.disconnectTimer = setTimeout(() => onTimeout(), 1000) const clients = new Map([["session-1", client]]) cleanupSession(clients, "session-1") diff --git a/tests/server/clipboard.test.ts b/tests/server/clipboard.test.ts index cc28666c..9f3e0597 100644 --- a/tests/server/clipboard.test.ts +++ b/tests/server/clipboard.test.ts @@ -1,10 +1,11 @@ -import { EventEmitter } from "node:events" -import { spawn } from "node:child_process" +import { ChildProcess, spawn } from "node:child_process" import os from "node:os" +import { PassThrough } from "node:stream" import { afterEach, beforeEach, describe, expect, it, vi } from "vitest" import { getSystemClipboard, setSystemClipboard } from "@/server/clipboard.ts" -vi.mock("node:child_process", () => ({ +vi.mock("node:child_process", async (importOriginal) => ({ + ...(await importOriginal()), spawn: vi.fn(), })) @@ -14,12 +15,13 @@ vi.mock("node:os", () => ({ }, })) -interface MockChildProcess extends EventEmitter { - stdout: EventEmitter - stdin: { - on: ReturnType - end: ReturnType - } +/** + * A real ChildProcess (so every member is typed by Node's own declarations) + * with the streams clipboard.ts uses replaced by non-null PassThrough streams. + */ +class MockChildProcess extends ChildProcess { + override stdout = new PassThrough() + override stdin = new PassThrough() } function createMockProcess(options: { @@ -28,12 +30,8 @@ function createMockProcess(options: { failError?: Error | null }) { const { stdoutData = "", exitCode = 0, failError = null } = options - const proc = new EventEmitter() as unknown as MockChildProcess - proc.stdout = new EventEmitter() - proc.stdin = { - on: vi.fn(), - end: vi.fn(), - } + const proc = new MockChildProcess() + vi.spyOn(proc.stdin, "end") setTimeout(() => { if (failError) {