Duplicate Code Opportunity
Summary
- Pattern: A 10-line
mockStdout + mockProcess construction block is copy-pasted 4 times in src/logs/log-streamer.test.ts. Each occurrence creates an identical empty Readable stream and a mock process object, then calls mockedExeca.mockReturnValue(mockProcess as never).
- Locations:
src/logs/log-streamer.test.ts lines ~47–60, 86–99, 120–133, 222–235
- Impact: ~40 lines of repeated setup; a change to
streamLogs's process interface (e.g. adding a stderr field) must be applied in all 4 places
Evidence
Block at lines 86–99 (repeated at lines 47, 120, 222 with identical content):
const mockStdout = new Readable({
read() {
this.push(null);
},
});
const mockProcess = {
stdout: mockStdout,
kill: jest.fn(),
};
mockedExeca.mockReturnValue(mockProcess as never);
Suggested Refactoring
Extract a makeMockExecaProcess helper at the top of the test file:
function makeMockExecaProcess(): { stdout: Readable; kill: jest.Mock } {
const stdout = new Readable({ read() { this.push(null); } });
return { stdout, kill: jest.fn() };
}
Each test then becomes:
const mockProcess = makeMockExecaProcess();
mockedExeca.mockReturnValue(mockProcess as never);
This matches the pattern already used in several other test files in the codebase.
Affected Files
src/logs/log-streamer.test.ts — lines ~47–60, 86–99, 120–133, 222–235
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-05-20
Generated by Duplicate Code Detector · ● 20.3M · ◷
Duplicate Code Opportunity
Summary
mockStdout+mockProcessconstruction block is copy-pasted 4 times insrc/logs/log-streamer.test.ts. Each occurrence creates an identical emptyReadablestream and a mock process object, then callsmockedExeca.mockReturnValue(mockProcess as never).src/logs/log-streamer.test.tslines ~47–60, 86–99, 120–133, 222–235streamLogs's process interface (e.g. adding astderrfield) must be applied in all 4 placesEvidence
Block at lines 86–99 (repeated at lines 47, 120, 222 with identical content):
Suggested Refactoring
Extract a
makeMockExecaProcesshelper at the top of the test file:Each test then becomes:
This matches the pattern already used in several other test files in the codebase.
Affected Files
src/logs/log-streamer.test.ts— lines ~47–60, 86–99, 120–133, 222–235Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-05-20