Skip to content

Conversation

@eablack
Copy link
Contributor

@eablack eablack commented Jan 7, 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 7 of 11 in the incremental migration plan.

Description

Migrates 9 test files in the Clients & Misc category to be compatible with @oclif/test v4.1.15, including tests for OAuth client management, lab features, platform regions, and URL validation utilities.

Files Migrated (9 total)

  • test/unit/commands/clients/create.unit.test.ts (2 tests)
  • test/unit/commands/clients/destroy.unit.test.ts (1 test)
  • test/unit/commands/clients/index.unit.test.ts (3 tests)
  • test/unit/commands/clients/info.unit.test.ts (3 tests)
  • test/unit/commands/clients/rotate.unit.test.ts (3 tests)
  • test/unit/commands/clients/update.unit.test.ts (3 tests)
  • test/unit/commands/labs/info.unit.test.ts (3 tests)
  • test/unit/commands/regions.unit.test.ts (4 tests)
  • test/unit/lib/clients/clients.unit.test.ts (17 tests)

Total: 39 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:443', api => {
    api.post('/oauth/clients', {
      name: 'awesome',
      redirect_uri: 'https://myapp.com',
    })
    .reply(201, createResponse)
  })
  .command(['clients:create', 'awesome', 'https://myapp.com'])
  .it('creates the client and outputs id and secret', ctx => {
    expect(ctx.stdout).to.equal('HEROKU_OAUTH_ID=f6e8d969-129f-42d2-854b-c2eca9d5a42e\n...')
    expect(ctx.stderr).to.contain('Creating awesome... done\n')
  })

After (v4):

it('creates the client and outputs id and secret', async function () {
  nock('https://api.heroku.com:443')
    .post('/oauth/clients', {
      name: 'awesome',
      redirect_uri: 'https://myapp.com',
    })
    .reply(201, createResponse)

  const {stdout, stderr} = await runCommand(['clients:create', 'awesome', 'https://myapp.com'])

  expect(stdout).to.equal('HEROKU_OAUTH_ID=f6e8d969-129f-42d2-854b-c2eca9d5a42e\n...')
  expect(stderr).to.contain('Creating awesome... done\n')
})

Key Pattern Changes

  • API: Replaced chaining test API with runCommand() function
  • Async: Converted callback-style tests to async/await
  • Context: Destructured {stdout, stderr, error} from result instead of ctx parameter
  • Cleanup: Added afterEach(() => nock.cleanAll()) hooks
  • Nock Setup: Moved nock setup inside each test for better isolation
  • Error Handling: Use error object from return value for expected errors instead of .catch()

Error Handling Pattern

For tests expecting errors:

Before (v2):

test
  .command(['clients:update', 'id'])
  .catch(error => expect(error.message).to.equal('No changes provided.'))
  .it('errors with no changes provided')

After (v4):

it('errors with no changes provided', async function () {
  const {error} = await runCommand(['clients:update', 'id'])
  
  expect(error?.message).to.equal('No changes provided.')
})

Testing

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

Test Results:

  • Clients tests: 15 passing
  • Labs/info tests: 3 passing
  • Regions tests: 4 passing
  • URL validation tests: 17 passing

Related

@eablack eablack requested a review from a team as a code owner January 7, 2026 21:58
@eablack eablack mentioned this pull request Jan 7, 2026
12 tasks
Copy link
Contributor

@michaelmalave michaelmalave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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