Skip to content

Conversation

@pyramation
Copy link
Contributor

Summary

Adds a new createTestFixture() function to @inquirerer/test that provides a complete test harness for testing inquirerer-based CLI applications. This consolidates the duplicated TestFixture class pattern found in both packages/cli and pgpm/cli in the constructive repo.

The fixture handles:

  • Creating temporary directories for test isolation
  • Optionally copying fixture files from a source directory
  • Setting up mock stdin/stdout streams via createTestEnvironment()
  • Creating an Inquirerer prompter with the mock streams internally
  • Running CLI commands with the test environment
  • Cleanup of temporary directories

Usage:

import { createTestFixture } from '@inquirerer/test';
import { commands } from '../src/commands';

const fixture = createTestFixture({
  commands,
  fixtureRoot: FIXTURES_PATH,
  tmpPrefix: 'my-cli-test-',
  cliOptions: { version: '1.0.0' },
  argvTransform: (argv) => withDefaults(argv)  // optional
});

const { result, writeResults } = await fixture.runCmd({ _: ['init'] });
fixture.cleanup();

Review & Testing Checklist for Human

  • No unit tests exist for the new fixture.ts - The test suite passes with --passWithNoTests. Consider whether tests should be added before merging, or if integration testing via constructive is sufficient.
  • Verify the commands function signature matches constructive's CLIs - The expected signature is (argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions) => Promise<TResult>. Check that both packages/cli and pgpm/cli commands match this.
  • Single environment per fixture - The TestEnvironment is created once when the fixture is instantiated. If runCmd is called multiple times, writeResults/transformResults will accumulate. Verify this is the intended behavior.

Test plan: After publishing this package, update constructive to use createTestFixture and verify existing tests still pass.

Notes

This is part of an ongoing effort to de-duplicate CLI test utilities between constructive's packages. A follow-up PR will update constructive to use this new fixture.

Link to Devin run: https://app.devin.ai/sessions/e5018850caff45ce8a126331548d69bc
Requested by: Dan Lynch (@pyramation)

Adds a new createTestFixture() function that provides a complete test harness
for testing inquirerer-based CLI applications. The fixture handles:

- Creating temporary directories for test isolation
- Optionally copying fixture files from a source directory
- Setting up mock stdin/stdout streams via createTestEnvironment()
- Creating an Inquirerer prompter with the mock streams
- Running CLI commands with the test environment
- Cleanup of temporary directories

API:
```typescript
import { createTestFixture } from '@inquirerer/test';
import { commands } from '../src/commands';

const fixture = createTestFixture({
  commands,
  fixtureRoot: FIXTURES_PATH,
  tmpPrefix: 'my-cli-test-',
  cliOptions: { version: '1.0.0' },
  argvTransform: (argv) => withDefaults(argv)  // optional
});

const { result, writeResults } = await fixture.runCmd({ _: ['init'] });
fixture.cleanup();
```
@devin-ai-integration
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 63b39bb into main Dec 27, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants