Skip to content

[Duplicate Code] Repeated mockStdout/mockProcess construction block duplicated 4 times in log-streamer.test.ts #3473

@github-actions

Description

@github-actions

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 ·

  • expires on Jun 19, 2026, 10:16 PM UTC

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions