Skip to content

Commit a37c8af

Browse files
committed
refactor: downgrade unnecessary stubs to fakes in tests
Replace vi.fn() with plain functions for collaborators that are only injected for construction and never asserted on.
1 parent 9a0ea68 commit a37c8af

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

packages/extension/src/Observers/ObserverFactory.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PHPUnitXML, type TestDefinition } from '@vscode-phpunit/phpunit';
2-
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { beforeEach, describe, expect, it } from 'vitest';
33
import type { OutputChannel, TestItem, TestRun } from 'vscode';
44
import type { Configuration } from '../Configuration';
55
import type { TestCollection } from '../TestCollection/TestCollection';
@@ -14,23 +14,23 @@ describe('ObserverFactory', () => {
1414

1515
beforeEach(() => {
1616
const testCollection = {
17-
getTestDefinition: vi.fn(),
18-
resolveDatasetChild: vi.fn(),
17+
getTestDefinition: () => undefined,
18+
resolveDatasetChild: () => undefined,
1919
} as unknown as TestCollection;
2020
outputChannel = {
21-
append: vi.fn(),
22-
appendLine: vi.fn(),
23-
clear: vi.fn(),
24-
show: vi.fn(),
21+
append: () => {},
22+
appendLine: () => {},
23+
clear: () => {},
24+
show: () => {},
2525
} as unknown as OutputChannel;
26-
const configuration = { get: vi.fn() } as unknown as Configuration;
26+
const configuration = { get: () => undefined } as unknown as Configuration;
2727
const phpUnitXML = new PHPUnitXML();
2828
factory = new ObserverFactory(testCollection, outputChannel, configuration, phpUnitXML);
2929
});
3030

3131
it('should create observers including DatasetObserver, TestResultObserver, and PrinterObserver', () => {
3232
const queue = new Map<TestDefinition, TestItem>();
33-
const testRun = { enqueued: vi.fn() } as unknown as TestRun;
33+
const testRun = { enqueued: () => {} } as unknown as TestRun;
3434
const observers = factory.create(queue, testRun);
3535

3636
expect(observers.length).toBe(5);
@@ -41,7 +41,7 @@ describe('ObserverFactory', () => {
4141

4242
it('should create new instances for each call', () => {
4343
const queue = new Map<TestDefinition, TestItem>();
44-
const testRun = { enqueued: vi.fn() } as unknown as TestRun;
44+
const testRun = { enqueued: () => {} } as unknown as TestRun;
4545
const observers1 = factory.create(queue, testRun);
4646
const observers2 = factory.create(queue, testRun);
4747

packages/extension/src/Observers/PrinterObserver.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const writers = [
2222
writerName: 'OutputChannelWriter',
2323
createWriter: () => {
2424
const spy = vi.fn();
25-
const outputChannel = { append: spy, appendLine: vi.fn() };
25+
const outputChannel = { append: spy, appendLine: () => {} };
2626
return { writer: new OutputChannelWriter(outputChannel), spy };
2727
},
2828
},
@@ -199,7 +199,7 @@ describe.each(writers)('PrinterObserver with $writerName', ({ createWriter }) =>
199199
describe('PrinterObserver passes location and testId to writer', () => {
200200
it('testFinished passes file line 1 as location', () => {
201201
const appendSpy = vi.fn();
202-
const writer: OutputWriter = { append: appendSpy, appendLine: vi.fn() };
202+
const writer: OutputWriter = { append: appendSpy, appendLine: () => {} };
203203
const printer = new Printer(new PHPUnitXML(), PRESET_PROGRESS);
204204
const observer = new PrinterObserver(writer, printer);
205205

@@ -233,7 +233,7 @@ describe('PrinterObserver passes location and testId to writer', () => {
233233

234234
it('testFailed passes detail location when available', () => {
235235
const appendSpy = vi.fn();
236-
const writer: OutputWriter = { append: appendSpy, appendLine: vi.fn() };
236+
const writer: OutputWriter = { append: appendSpy, appendLine: () => {} };
237237
const printer = new Printer(new PHPUnitXML(), PRESET_PROGRESS);
238238
const observer = new PrinterObserver(writer, printer);
239239

@@ -272,7 +272,7 @@ describe('PrinterObserver passes location and testId to writer', () => {
272272

273273
it('testIgnored passes file line 1 as location', () => {
274274
const appendSpy = vi.fn();
275-
const writer: OutputWriter = { append: appendSpy, appendLine: vi.fn() };
275+
const writer: OutputWriter = { append: appendSpy, appendLine: () => {} };
276276
const printer = new Printer(new PHPUnitXML(), PRESET_PROGRESS);
277277
const observer = new PrinterObserver(writer, printer);
278278

0 commit comments

Comments
 (0)