feat(@inquirerer/test): add createTestFixture for CLI testing#45
Merged
pyramation merged 1 commit intomainfrom Dec 27, 2025
Merged
feat(@inquirerer/test): add createTestFixture for CLI testing#45pyramation merged 1 commit intomainfrom
pyramation merged 1 commit intomainfrom
Conversation
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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
createTestFixture()function to@inquirerer/testthat provides a complete test harness for testing inquirerer-based CLI applications. This consolidates the duplicatedTestFixtureclass pattern found in bothpackages/cliandpgpm/cliin the constructive repo.The fixture handles:
createTestEnvironment()Inquirererprompter with the mock streams internallyUsage:
Review & Testing Checklist for Human
fixture.ts- The test suite passes with--passWithNoTests. Consider whether tests should be added before merging, or if integration testing via constructive is sufficient.commandsfunction signature matches constructive's CLIs - The expected signature is(argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions) => Promise<TResult>. Check that bothpackages/cliandpgpm/clicommands match this.TestEnvironmentis created once when the fixture is instantiated. IfrunCmdis called multiple times,writeResults/transformResultswill accumulate. Verify this is the intended behavior.Test plan: After publishing this package, update constructive to use
createTestFixtureand 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)