Skip to content

Conversation

@eablack
Copy link
Contributor

@eablack eablack commented Jan 8, 2026

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 PR 9 of 11 in the incremental migration plan.

Description

Migrates 7 test files in the Pipelines Part 1 category to be compatible with @oclif/test v4.1.15, including tests for pipeline CRUD operations (create, destroy, list, info, open, remove, rename).

Files Migrated (7 total)

  • test/unit/commands/pipelines/create.unit.test.ts (2 tests)
  • test/unit/commands/pipelines/destroy.unit.test.ts (1 test)
  • test/unit/commands/pipelines/index.unit.test.ts (2 tests)
  • test/unit/commands/pipelines/info.unit.test.ts (6 tests)
  • test/unit/commands/pipelines/open.unit.test.ts (1 test)
  • test/unit/commands/pipelines/remove.unit.test.ts (1 test)
  • test/unit/commands/pipelines/rename.unit.test.ts (1 test)

Total: 14 tests migrated ✅

Migration Changes

All tests were updated to use the new @oclif/test v4 API:

Before (v2):

test
  .stdout()
  .stderr()
  .nock('https://api.heroku.com', api => {
    api.get('/pipelines')
      .reply(200, [
        {id: '0123', name: 'Betelgeuse'},
        {id: '9876', name: 'Sirius'},
      ])
  })
  .command(['pipelines'])
  .it('shows a list of pipelines', ctx => {
    expect(ctx.stdout).to.contain('My Pipelines')
    expect(ctx.stdout).to.contain('Betelgeuse')
  })

After (v4):

it('shows a list of pipelines', async function () {
  nock('https://api.heroku.com')
    .get('/pipelines')
    .reply(200, [
      {id: '0123', name: 'Betelgeuse'},
      {id: '9876', name: 'Sirius'},
    ])

  const {stdout} = await runCommand(['pipelines'])

  expect(stdout).to.contain('My Pipelines')
  expect(stdout).to.contain('Betelgeuse')
})

Key Pattern Changes

  • API: Replaced chaining test API with runCommand() function
  • Async: Converted callback-style tests to async/await
  • Context: Destructured {stdout, stderr} from result instead of ctx parameter
  • Cleanup: Added afterEach(() => nock.cleanAll()) hooks for nock tests
  • Nock Setup: Moved nock setup inside each test for better isolation
  • Helper Functions: Converted helper functions to accept stdout/stderr directly instead of context objects
  • Custom Helper: Used runCommandHelper for tests with sinon stubs (pipelines/open)

Special Cases

Tests with Sinon Stubs

The pipelines/open test required the custom runCommandHelper instead of @oclif/test v4's runCommand because it uses sinon stubs for childProcess.spawn:

const spawnStub = sinon.stub(childProcess, 'spawn').returns({
  on(event: string, cb: CallableFunction) {
    if (event === 'exit') { cb() }
  }, unref() {},
} as any)

await runCommandHelper(OpenCommand, [pipeline.name])

Helper Function Updates

The pipelines/info test file had helper functions that needed to be updated to work with the new pattern:

Before (v2):

function itShowsPipelineApps(ctx: TestContext) {
  expect(ctx.stdout).to.include('=== example')
  // ...
}

After (v4):

function itShowsPipelineApps(stdout: string) {
  expect(stdout).to.include('=== example')
  // ...
}

Whitespace Handling

Some tests in pipelines/info used removeAllWhitespace helper to handle spacing differences in table output across environments.

Testing

✅ All 14 migrated tests pass locally
✅ No regressions in other test suites
✅ Build passes

Test Results:

  • pipelines/create: 2 passing
  • pipelines/destroy: 1 passing
  • pipelines/index: 2 passing
  • pipelines/info: 6 passing
  • pipelines/open: 1 passing
  • pipelines/remove: 1 passing
  • pipelines/rename: 1 passing

Related

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.

1 participant