Skip to content

Improve test coverage to ~100% for @azure/core-amqp#38174

Merged
deyaaeldeen merged 33 commits intomainfrom
deyaaeldeen/core-amqp-test-coverage
Apr 23, 2026
Merged

Improve test coverage to ~100% for @azure/core-amqp#38174
deyaaeldeen merged 33 commits intomainfrom
deyaaeldeen/core-amqp-test-coverage

Conversation

@deyaaeldeen
Copy link
Copy Markdown
Member

@deyaaeldeen deyaaeldeen commented Apr 16, 2026

Changes

New test files

  • checkNetworkConnection.spec.ts (browser)
  • checkNetworkMocked.spec.ts (node, mocked network)
  • errors.spec.ts (browser)
  • hmacSha256.spec.ts (browser)
  • retryNetworkDown.spec.ts (node)
  • runtimeInfo.spec.ts (browser)
  • typeGuards.spec.ts
  • utils.spec.ts

Expanded existing tests

  • cbs.spec.ts: connection error paths, session close errors
  • context.spec.ts: extracted properties/webSocketOptions into typed consts
  • errors.spec.ts: translate edge cases, mapping coverage
  • lock.spec.ts: timeout and release paths
  • message.spec.ts: header/properties encoding edge cases
  • pipeline.spec.ts: policy ordering
  • requestResponse.spec.ts: retry, timeout, cleanup callbacks
  • retry.spec.ts: all retry modes and error paths
  • tokenProvider.spec.ts: token refresh edge cases

Test quality improvements

  • Replaced hand-rolled counters with vi.fn() + toHaveBeenCalledTimes()
  • Replaced boolean tracking flags with vi.fn() + toHaveBeenCalled()
  • Replaced try/catch + assert.fail with rejects.toThrow()
  • Removed unnecessary as any casts
  • Extracted non-null assertions into typed consts

@deyaaeldeen deyaaeldeen force-pushed the deyaaeldeen/core-amqp-test-coverage branch from 0c75c05 to 50411da Compare April 18, 2026 03:55
Deyaaeldeen Almahallawi and others added 10 commits April 18, 2026 05:41
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use plain type instead of Class & {...} intersection for private access
  (private fields cause 'never' type in intersection)
- Remove unused imports (expect, MessagingError) and unused variables
- Add body to mock RheaMessage, fix statusCode type assertion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
randomNumberFromInterval, executePromisesSequentially,
isIotHubConnectionString, and Timeout were removed in #38149.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove redundant dynamic imports where top-level import suffices
- Rename dynamic imports to avoid shadowing (check → alias)
- Rename local connectionString to emulatorConnectionString

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen force-pushed the deyaaeldeen/core-amqp-test-coverage branch from 50411da to cfdb9d1 Compare April 18, 2026 05:41
Deyaaeldeen Almahallawi and others added 9 commits April 18, 2026 07:41
- tokenProvider: isTrue(x < 2) → isBelow(x, 2)
- context: isTrue(calls.length > 0) → isAbove(calls.length, 0)
- retryNetworkDown: isTrue(calls.length > 0) → isAbove(calls.length, 0)
- lock, requestResponse: remove line number references from test names

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- requestResponse: isTrue(instanceof) → instanceOf, equal(x,true) → isTrue
- errors: equal(retryable, false) → isFalse
- message: remove redundant isDefined before equal

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ontext and message tests

- Extract properties/webSocketOptions into local consts after asserting defined
- Extract date values into consts to avoid non-null assertions on optional fields

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rest tests

Replace try/catch + assert.fail() with rejects.toThrow(), hand-rolled
boolean flags with vi.fn(), and assert.equal(x, undefined) with
assert.isUndefined(x).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace hand-rolled callCount with vi.fn() and try/catch + assert.fail()
with rejects.toThrow() for cleaner test code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen marked this pull request as ready for review April 20, 2026 16:32
Copilot AI review requested due to automatic review settings April 20, 2026 16:32
@deyaaeldeen deyaaeldeen requested review from a team and xirzec as code owners April 20, 2026 16:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on bringing @azure/core-amqp’s unit test coverage close to 100% by adding new tests and expanding existing suites across Node and browser runtimes, plus a small typing improvement in a related core package test.

Changes:

  • Added multiple new Node- and browser-specific test suites to cover previously untested branches (network checks, crypto signing, runtime info, type guards, utilities).
  • Expanded and refactored existing tests to cover additional error paths and edge cases (CBS, retry, message encoding, locks, request/response behavior).
  • Minor test typing cleanup in @azure/core-rest-pipeline by using createHttpHeaders() rather than casting.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/core/core-rest-pipeline/test/public/pipeline.spec.ts Uses createHttpHeaders() in a response-shape test to avoid manual header casting.
sdk/core/core-amqp/test/utils/createConnectionStub.ts Adds a “full” connection/session/sender/receiver stub to support more link lifecycle tests.
sdk/core/core-amqp/test/public/tokenProvider.spec.ts Adds additional SasTokenProvider behavior tests and tightens assertions.
sdk/core/core-amqp/test/public/retry.spec.ts Refactors retry tests to use vi.fn/expect assertions and adds more default/edge-path tests.
sdk/core/core-amqp/test/public/message.spec.ts Improves message TTL/expiry test clarity and removes non-null assertions via typed locals.
sdk/core/core-amqp/test/public/context.spec.ts Refactors setup constants and adds coverage for maxListeners behavior on the connection.
sdk/core/core-amqp/test/public/cbs.spec.ts Adds CBS close/remove/isOpen and error-handler coverage using the new full stub.
sdk/core/core-amqp/test/internal/utils.spec.ts Adds unit tests for internal utils helpers (isString, isNumber, delay, getGlobalProperty).
sdk/core/core-amqp/test/internal/typeGuards.spec.ts Adds tests for isSasTokenProvider including real provider instances.
sdk/core/core-amqp/test/internal/requestResponse.spec.ts Adds additional RequestResponseLink lifecycle/error-path tests beyond the existing skipped browser suite.
sdk/core/core-amqp/test/internal/node/retryNetworkDown.spec.ts Adds Node-specific test that mocks network check to validate retry behavior when network is down.
sdk/core/core-amqp/test/internal/node/checkNetworkMocked.spec.ts Adds Node DNS-mocking tests for checkNetworkConnection.
sdk/core/core-amqp/test/internal/lock.spec.ts Expands lock tests for timeouts/empty-queue/private-path coverage.
sdk/core/core-amqp/test/internal/errors.spec.ts Adds more translate/mapping edge-case tests and removes unnecessary casts.
sdk/core/core-amqp/test/internal/browser/runtimeInfo.spec.ts Adds browser runtime info tests (getPlatformInfo, getFrameworkInfo).
sdk/core/core-amqp/test/internal/browser/hmacSha256.spec.ts Adds browser Web Crypto signing tests for signString.
sdk/core/core-amqp/test/internal/browser/errors.spec.ts Adds browser websocket error translation tests.
sdk/core/core-amqp/test/internal/browser/checkNetworkConnection.spec.ts Adds browser test validating navigator-based network check behavior.

Comment thread sdk/core/core-amqp/test/internal/requestResponse.spec.ts Outdated
Comment thread sdk/core/core-amqp/test/public/context.spec.ts Outdated
Comment thread sdk/core/core-amqp/test/internal/utils.spec.ts Outdated
Deyaaeldeen Almahallawi and others added 2 commits April 20, 2026 17:09
- Create typed mock helpers (createMockSession, createMockSender, createMockReceiver,
  mockCreateSession) in createConnectionStub.ts to replace inline `as any` session mocks
- Update createFullConnectionStub to use the new mock helpers
- Create accessor helpers (getCbsLink, getResponsesMap, lockPrivate) to consolidate
  private member access casts into single locations
- Replace `isError(err) + (err as Error)` patterns with `assert.instanceOf(err, Error)`
  which narrows types automatically via vitest's assertion type guards
- Replace `translate(x) as MessagingError` with `translate(x) + assert.instanceOf`
- Replace `as Date` casts with `assert.instanceOf(x, Date)` in message.spec.ts
- Replace `let req: any = {}` with `let req: RheaMessage = { body: undefined }`
- Remove unused `isError` imports from @azure/core-util

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaaeldeen Almahallawi and others added 9 commits April 20, 2026 18:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…test name

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ec.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jeremymeng
Copy link
Copy Markdown
Member

Looks good overall! I added some comments. There are some more un-commented

  • callCount verification could be replaced with spy
  • try-catch verification of error could be replaced with expect().rejects

They can be addressed in follow-up if we want to maintain consistency

Comment thread sdk/core/core-amqp/test/internal/browser/hmacSha256.spec.ts Outdated
Comment thread sdk/core/core-amqp/test/internal/browser/hmacSha256.spec.ts Outdated
Comment thread sdk/core/core-amqp/test/internal/node/requestResponse.spec.ts
Comment thread sdk/core/core-amqp/test/internal/node/retryNetworkDown.spec.ts Outdated
Comment thread sdk/core/core-amqp/test/internal/node/retryNetworkDown.spec.ts Outdated
Comment thread sdk/core/core-amqp/test/internal/requestResponse.spec.ts Outdated
Comment thread sdk/core/core-amqp/test/internal/requestResponse.spec.ts
Deyaaeldeen Almahallawi and others added 3 commits April 23, 2026 21:36
- Verify exact HMAC-SHA256 signature value instead of isOk/isString
- Remove duplicate hmacSha256 describe block
- Add abort listener removal verification via spy
- Replace manual callCount with vi.fn() spy in retry test
- Convert 3 try/catch + assert.fail patterns to expect().rejects

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Convert all try/catch + TEST_FAILURE sentinel patterns to expect().rejects
  in requestResponse.spec.ts (6 instances), cbs.spec.ts (7 instances),
  lock.spec.ts (1 instance)
- Remove unused TEST_FAILURE constants
- Add expect import where needed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify removeEventListener was called specifically with 'abort' event
type and a function, not just that it was called at all.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen merged commit 49bc828 into main Apr 23, 2026
32 checks passed
@deyaaeldeen deyaaeldeen deleted the deyaaeldeen/core-amqp-test-coverage branch April 23, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants