test: migrate pipelines tests (Part 2 of 2) to @oclif/test v4 #3460
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.
This PR is part of a series migrating test files from @oclif/test v2 to v4 following the package upgrade in the foundation PR. This is the second part of the Pipelines tests migration.
Summary
Migrates 7 test files in the Pipelines category (Part 2) to be compatible with @oclif/test v4.1.15, completing the pipelines test migration. This PR handles more complex test scenarios including tests with multiple stubs, interactive prompts, and error conditions.
Files Migrated (7 total)
Total: 32 tests migrated ✅
Migration Changes
Tests with stubs required a different pattern using the custom runCommandHelper:
Before (v2):
After (v4) - Standard tests:
After (v4) - Tests with stubs:
Key Pattern Changes
runCommand()for simple tests; customrunCommandHelper()for tests with sinon stubs (inquirer.prompt, hux.prompt, hux.confirm){stdout, stderr, error}from runCommand, orstdout.output/stderr.outputwith runCommandHelperexpect.fail()for error tests with custom helpersrc/commands/pipelines/setup.tsto make theopen()function stubbable by addingstatic open = openBrowserand callingSetup.open()instead ofopen()afterEach(() => { nock.cleanAll(); sinon.restore() })hooks for proper test isolationTesting
Notes
This PR completes the pipelines tests migration. The key learning was establishing the two-pattern approach: using @oclif/test v4's
runCommand()for straightforward tests, and falling back to the customrunCommandHelperwhen tests require sinon stubs for external dependencies like inquirer or hux prompts. This pattern ensures test compatibility while maintaining the ability to stub dependencies.The source code modification to
pipelines/setup.tsdemonstrates the approach for making functions stubbable in ES modules when needed for testing.Related