Skip to content

Commit 439de0f

Browse files
committed
Update vitest and vitest coverage to 4.0.16
1 parent a3af570 commit 439de0f

File tree

5 files changed

+332
-376
lines changed

5 files changed

+332
-376
lines changed

CLAUDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ Comments explain what code does or why it exists:
2828
- Never mock behavior in end-to-end tests - use real data
2929
- Mock as little as possible in unit tests - try to use real data
3030
- Find root causes, not symptoms. Read error messages carefully before attempting fixes.
31+
- When mocking constructors (classes) with `vi.mocked(...).mockImplementation()`, use regular functions, not arrow functions. Arrow functions can't be called with `new`.
32+
```typescript
33+
// ✗ Wrong
34+
vi.mocked(SomeClass).mockImplementation(() => mock);
35+
// ✓ Correct
36+
vi.mocked(SomeClass).mockImplementation(function () { return mock; });
37+
```
3138

3239
## Version Control
3340

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
"@types/ws": "^8.18.1",
429429
"@typescript-eslint/eslint-plugin": "^8.49.0",
430430
"@typescript-eslint/parser": "^8.50.1",
431-
"@vitest/coverage-v8": "^3.2.4",
431+
"@vitest/coverage-v8": "^4.0.16",
432432
"@vscode/test-cli": "^0.0.12",
433433
"@vscode/test-electron": "^2.5.2",
434434
"@vscode/vsce": "^3.7.1",
@@ -452,7 +452,7 @@
452452
"ts-loader": "^9.5.4",
453453
"typescript": "^5.9.3",
454454
"utf-8-validate": "^6.0.6",
455-
"vitest": "^3.2.4",
455+
"vitest": "^4.0.16",
456456
"vscode-test": "^1.5.0",
457457
"webpack": "^5.104.1",
458458
"webpack-cli": "^6.0.1"

test/unit/api/coderApi.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ describe("CoderApi", () => {
342342

343343
it("falls back to SSE when WebSocket creation fails with 404", async () => {
344344
// Only 404 errors trigger SSE fallback - other errors are thrown
345-
vi.mocked(Ws).mockImplementation(() => {
345+
vi.mocked(Ws).mockImplementation(function () {
346346
throw new Error("Unexpected server response: 404");
347347
});
348348

@@ -380,7 +380,7 @@ describe("CoderApi", () => {
380380
});
381381

382382
it("throws non-404 errors without SSE fallback", async () => {
383-
vi.mocked(Ws).mockImplementation(() => {
383+
vi.mocked(Ws).mockImplementation(function () {
384384
throw new Error("Network error");
385385
});
386386

@@ -398,7 +398,7 @@ describe("CoderApi", () => {
398398
let wsAttempts = 0;
399399
const mockEventSources: MockEventSource[] = [];
400400

401-
vi.mocked(Ws).mockImplementation(() => {
401+
vi.mocked(Ws).mockImplementation(function () {
402402
wsAttempts++;
403403
const mockWs = createMockWebSocket("wss://test", {
404404
on: vi.fn((event: string, handler: (e: unknown) => void) => {
@@ -413,7 +413,7 @@ describe("CoderApi", () => {
413413
return mockWs as Ws;
414414
});
415415

416-
vi.mocked(EventSource).mockImplementation(() => {
416+
vi.mocked(EventSource).mockImplementation(function () {
417417
const es = createMockEventSource(`${CODER_URL}/api/v2/test`);
418418
mockEventSources.push(es);
419419
return es as unknown as EventSource;
@@ -436,7 +436,7 @@ describe("CoderApi", () => {
436436

437437
const setupAutoOpeningWebSocket = () => {
438438
const sockets: Array<Partial<Ws>> = [];
439-
vi.mocked(Ws).mockImplementation((url: string | URL) => {
439+
vi.mocked(Ws).mockImplementation(function (url: string | URL) {
440440
const mockWs = createMockWebSocket(String(url), {
441441
on: vi.fn((event, handler) => {
442442
if (event === "open") {
@@ -575,7 +575,7 @@ describe("CoderApi", () => {
575575
describe("dispose", () => {
576576
it("disposes all tracked reconnecting sockets", async () => {
577577
const sockets: Array<Partial<Ws>> = [];
578-
vi.mocked(Ws).mockImplementation((url: string | URL) => {
578+
vi.mocked(Ws).mockImplementation(function (url: string | URL) {
579579
const mockWs = createMockWebSocket(String(url), {
580580
on: vi.fn((event, handler) => {
581581
if (event === "open") {
@@ -701,9 +701,13 @@ function createMockEventSource(url: string): MockEventSource {
701701
}
702702

703703
function setupWebSocketMock(ws: Partial<Ws>): void {
704-
vi.mocked(Ws).mockImplementation(() => ws as Ws);
704+
vi.mocked(Ws).mockImplementation(function () {
705+
return ws as Ws;
706+
});
705707
}
706708

707709
function setupEventSourceMock(es: Partial<EventSource>): void {
708-
vi.mocked(EventSource).mockImplementation(() => es as EventSource);
710+
vi.mocked(EventSource).mockImplementation(function () {
711+
return es as EventSource;
712+
});
709713
}

test/unit/websocket/sseConnection.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ function createMockEventSource(
356356
}
357357

358358
function setupEventSourceMock(es: Partial<EventSource>): void {
359-
vi.mocked(EventSource).mockImplementation(() => es as EventSource);
359+
vi.mocked(EventSource).mockImplementation(function () {
360+
return es as EventSource;
361+
});
360362
}
361363

362364
function waitForNextTick(): Promise<void> {

0 commit comments

Comments
 (0)