Skip to content

test: migrate Auth & Sessions tests to @oclif/test v4#3446

Merged
eablack merged 14 commits intoeb/upgrade-oclif-testfrom
eb/upgrade-oclif-test-auth
Jan 9, 2026
Merged

test: migrate Auth & Sessions tests to @oclif/test v4#3446
eablack merged 14 commits intoeb/upgrade-oclif-testfrom
eb/upgrade-oclif-test-auth

Conversation

@eablack
Copy link
Copy Markdown
Contributor

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

Summary

Migrates 11 test files in the Auth & Sessions category to be compatible with @oclif/test v4.1.15, including tests for authentication,
OAuth authorizations, and session management. This PR establishes the migration patterns used across all subsequent PRs.

Files Migrated (11 total)

  • test/unit/commands/auth/token.unit.test.ts (1 test)
  • test/unit/commands/auth/whoami.unit.test.ts (1 test)
  • test/unit/commands/authorizations/create.unit.test.ts (2 tests)
  • test/unit/commands/authorizations/index.unit.test.ts (2 tests)
  • test/unit/commands/authorizations/info.unit.test.ts (2 tests)
  • test/unit/commands/authorizations/revoke.unit.test.ts (2 tests)
  • test/unit/commands/authorizations/rotate.unit.test.ts (1 test)
  • test/unit/commands/authorizations/update.unit.test.ts (3 tests)
  • test/unit/commands/sessions/destroy.unit.test.ts (2 tests)
  • test/unit/commands/sessions/index.unit.test.ts (2 tests)
  • test/unit/lib/authorizations/authorizations.unit.test.ts (7 tests)

Total: 25 tests migrated ✅

Migration Changes

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

Before (v2):
test
.stdout()
.nock('https://api.heroku.com', api => {
api.get('/oauth/authorizations/f6e8d969-129f-42d2-854b-c2eca9d5a42e')
.reply(200, authorization)
})
.command(['authorizations:info', 'f6e8d969-129f-42d2-854b-c2eca9d5a42e'])
.it('shows authorization info', ctx => {
expect(ctx.stdout).to.contain('test@heroku.com')
})

After (v4):
it('shows authorization info', async () => {
nock('https://api.heroku.com')
.get('/oauth/authorizations/f6e8d969-129f-42d2-854b-c2eca9d5a42e')
.reply(200, authorization)

const {stdout} = await runCommand(['authorizations:info', 'f6e8d969-129f-42d2-854b-c2eca9d5a42e'])

expect(stdout).to.contain('test@heroku.com')

})

Key Pattern Changes

  1. API: Replaced chaining test API with runCommand() function
  2. Async: Converted callback-style tests to async/await
  3. Context: Destructured {stdout, stderr, error} from result instead of ctx parameter
  4. Error Handling: Check error property in result object instead of .catch() chaining
  5. Cleanup: Added afterEach(() => nock.cleanAll()) hooks
  6. Nock Setup: Moved nock setup inside each test for better isolation

Testing

  • ✅ All 25 migrated tests pass locally
  • ✅ Tests pass in CI
  • ✅ No regressions in other test suites
  • ✅ Build passes

Notes

This PR establishes the migration patterns and approach that will be used across all subsequent PRs in the migration plan. The patterns
have been validated to work with core authentication functionality.

Related

  • Part of the @oclif/test v2 → v4 migration plan outlined in OCLIF_TEST_UPGRADE_PR_PLAN.md
  • Follows foundation PR -- test: upgrade @oclif/test to v4 #3447 -- that upgrades the package version

@eablack eablack force-pushed the eb/upgrade-oclif-test-auth branch from 335bd19 to adc81ea Compare January 5, 2026 23:35
- Convert from v2 chaining API to v4 captureOutput API
- All 3 tests passing
@eablack eablack force-pushed the eb/upgrade-oclif-test-auth branch from 9fc744c to 8c22192 Compare January 6, 2026 01:14
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:14 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:14 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:14 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:14 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:22 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:22 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:22 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 6, 2026 01:22 — with GitHub Actions Inactive
@eablack eablack mentioned this pull request Jan 6, 2026
13 tasks
@eablack eablack changed the title chore: convert auth to oclif/test 4 test: convert auth to oclif/test 4 Jan 6, 2026
@eablack eablack changed the title test: convert auth to oclif/test 4 test: migrate Auth & Sessions tests to @oclif/test v4 Jan 6, 2026
@eablack eablack marked this pull request as ready for review January 7, 2026 22:54
@eablack eablack requested a review from a team as a code owner January 7, 2026 22:54
Copy link
Copy Markdown
Contributor

@sbosio sbosio left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@k80bowman k80bowman left a comment

Choose a reason for hiding this comment

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

This looks great, I really like the new test format. Just one suggestion, but it's not blocking. I've been defining the nock scope in a beforeEach and then using nock's done() function (along with cleanAll()) in an afterEach to ensure that nock is handling all the calls it's supposed to as part of the tests. There's an example in the applink repo, if that's something you'd be interested in adding.

@eablack
Copy link
Copy Markdown
Contributor Author

eablack commented Jan 9, 2026

This looks great, I really like the new test format. Just one suggestion, but it's not blocking. I've been defining the nock scope in a beforeEach and then using nock's done() function (along with cleanAll()) in an afterEach to ensure that nock is handling all the calls it's supposed to as part of the tests. There's an example in the applink repo, if that's something you'd be interested in adding.

agree, that looks like a good convention to apply. updated with that structure!

@eablack eablack temporarily deployed to AcceptanceTests January 9, 2026 22:20 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 9, 2026 22:20 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 9, 2026 22:20 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests January 9, 2026 22:20 — with GitHub Actions Inactive
@eablack eablack merged commit 0967e31 into eb/upgrade-oclif-test Jan 9, 2026
13 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.

3 participants