Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Consolidate test harness helpers and replace global stdout/stderr patching

Open
#737 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
nodejs, typescript
Domain
testing

Research direction

Start with the duplicated helpers the issue lists: test/es/helpers/bulk-ingest.test.ts, watch.test.ts, scroll-search.test.ts and msearch.test.ts, plus test/factory.test.ts and test/config/text-output.test.ts. Run rg -n 'process\.(stdout|stderr)\.write = ' test to confirm the baseline. Done means one shared capture and transport helper under test/helpers/ that uses t.mock.method, with the grep returning 0 and npm test passing. The helper signatures differ between files, so decide on a shared signature with the maintainers before migrating.

Written by the indexing model from the issue text.

Description

Problem

Tests patch global streams by hand and copy the same harness helpers between files.

  1. Global stream patching. rg -n 'process\.(stdout|stderr)\.write = ' test finds 82 assignments in 19 files (rg -l ... | wc -l). Examples: test/config/text-output.test.ts, test/config/loader.test.ts, test/docs/chat.test.ts:138-158. If a test skips its restore, runner output is lost and later tests see the stub.
  2. Duplicated helpers (rg -n 'function <name>\b|const <name>\b' test):
    • mockTransport: 4 files (test/es/helpers/{bulk-ingest,scroll-search,watch,msearch}.test.ts)
    • makeDeps: 5 files (the four above plus test/es/handler.test.ts:40)
    • runCommand: 4; captureOutput: 4 in 3 files; captureStdout: 2 (test/factory.test.ts:2059,2364,4188, test/es/search-schema.test.ts:33, test/es/helpers/watch.test.ts:49)
    • makeClient: 4 in 2 files (test/lib/es-client.test.ts, test/lib/kibana-client.test.ts)
    • mkdtemp: 24 files. ELASTIC_CLI_CONFIG_FILE used: 9 files.

The copies have different signatures:

  • bulk-ingest.test.ts:18 mockTransport(responses: Array<{ errors: boolean, items: ... }>) vs watch.test.ts:32 mockTransport(responses: MockResponse[])
  • factory.test.ts:2059 captureOutput(fn: () => Promise<void>) vs watch.test.ts:49 captureOutput() (takes no arguments and returns a sink)

Note: test/docs/chat.test.ts patches process.stderr.write on purpose. The test checks that the chat loop never writes to the real stderr (assert.deepEqual(realWrites, [])). It does not show a bypass in src/docs/*.

Proposal

Add test/helpers/{capture,transport,tmp-config}.ts. capture(t) uses t.mock.method(process.stdout, 'write', ...), which node:test restores automatically. Migrate in small PRs: the four test/es/helpers tests first, then factory.test.ts. Keep the chat.test.ts guard, but switch it to t.mock.method.

Acceptance criteria

  • rg 'process\.(stdout|stderr)\.write = ' test returns 0 matches
  • Only one mockTransport / captureOutput definition exists, in test/helpers/
  • Temporary config setup (mkdtemp + ELASTIC_CLI_CONFIG_FILE) goes through one helper with automatic cleanup
  • npm test passes on all supported Node versions

Related: #733 (DI for _test* seams).


authored by Pi Coding Agent (Claude Opus 5.5)

Dominant language
TypeScript
Stars
47
Forks
27
Avg merge
2d 6h
Merged PRs (30d)
52

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from elastic/cli

All issues in elastic/cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.