Improve test coverage to ~100% for @azure/core-amqp#38174
Merged
deyaaeldeen merged 33 commits intomainfrom Apr 23, 2026
Merged
Conversation
0c75c05 to
50411da
Compare
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>
50411da to
cfdb9d1
Compare
- 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>
Contributor
There was a problem hiding this comment.
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-pipelineby usingcreateHttpHeaders()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. |
- 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>
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>
Member
|
Looks good overall! I added some comments. There are some more un-commented
They can be addressed in follow-up if we want to maintain consistency |
jeremymeng
reviewed
Apr 23, 2026
- 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>
jeremymeng
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes
New test files
Expanded existing tests
Test quality improvements