Improve test coverage to ~100% for @azure/core-rest-pipeline#38180
Merged
deyaaeldeen merged 40 commits intomainfrom Apr 24, 2026
Merged
Improve test coverage to ~100% for @azure/core-rest-pipeline#38180deyaaeldeen merged 40 commits intomainfrom
deyaaeldeen merged 40 commits intomainfrom
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SharedArrayBuffer is available in Node >=8.10 and all modern browsers. The minimum supported Node version is 20. 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>
…en tests 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 adds and extends Vitest coverage for @azure/core-rest-pipeline with the goal of reaching ~100% coverage, primarily by exercising previously untested branches across pipeline policies and internal utilities.
Changes:
- Adds new internal tests for
tokenCycler,file,createPipelineFromOptions, Node policy factories, and user-agent helpers (Node + browser where applicable). - Extends existing tests to cover additional branches in multiple pipeline policies (auth, tracing, request-id, NDJSON, user-agent platform).
- Introduces additional mocking to exercise error/edge paths (e.g., tracing client creation failure, non-recording spans, CAE challenge branches).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/core/core-rest-pipeline/test/public/tracingPolicy.spec.ts | Adds additional tracingPolicy branch tests (client creation failure, non-recording span, response header attribute, error processing paths, user-agent branch). |
| sdk/core/core-rest-pipeline/test/public/setClientRequestIdPolicy.spec.ts | Adds coverage for not overwriting an existing x-ms-client-request-id. |
| sdk/core/core-rest-pipeline/test/public/ndJsonPolicy.spec.ts | Adds pass-through coverage for non-array / non-string-body cases. |
| sdk/core/core-rest-pipeline/test/internal/tokenCycler.spec.ts | Adds new tests covering token refresh failure and retry loop behavior with fake timers. |
| sdk/core/core-rest-pipeline/test/internal/node/userAgentPolicy.spec.ts | Adds Node-only tests for User-Agent header overwrite behavior. |
| sdk/core/core-rest-pipeline/test/internal/node/userAgentPlatform.spec.ts | Improves mocking and expands runtime-detection branch coverage (Bun/Deno/Node/unknown). |
| sdk/core/core-rest-pipeline/test/internal/node/userAgent.spec.ts | Adds internal tests for user-agent string formatting/prefix handling and platform-data formatting edge cases. |
| sdk/core/core-rest-pipeline/test/internal/node/policyFactories.spec.ts | Adds tests for Node policy factory functions and proxy env parsing behavior. |
| sdk/core/core-rest-pipeline/test/internal/node/file.spec.ts | Adds Node tests for file utilities including stream behavior and raw content helpers. |
| sdk/core/core-rest-pipeline/test/internal/node/createPipelineFromOptions.spec.ts | Adds Node tests ensuring agent/tls policies are wired in via options. |
| sdk/core/core-rest-pipeline/test/internal/browser/file.spec.ts | Adds browser tests for file utilities including File constructor and stream factory behavior. |
| sdk/core/core-rest-pipeline/test/internal/browser/createPipelineFromOptions.spec.ts | Adds browser tests ensuring Node-only policies are excluded/ignored. |
| sdk/core/core-rest-pipeline/test/internal/bearerTokenAuthenticationPolicy.spec.ts | Refactors request creation helper and adds many new CAE/custom-challenge edge-path tests. |
| sdk/core/core-rest-pipeline/test/internal/auxiliaryAuthenticationHeaderPolicy.spec.ts | Refactors request creation helper and adds tests for empty/undefined credentials behavior. |
- createPipelineFromOptions.spec.ts: use proper Agent/TlsSettings types - policyFactories.spec.ts: remove unused PipelineResponse, fix Agent/TlsSettings - userAgentPlatform.spec.ts: add default property to mock type parameters - Format all test files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Guard SharedArrayBuffer test with it.runIf for browser environments - Fix typo 'retriving' -> 'retrieving' in bearerTokenAuth test comment - Merge duplicate describe blocks (tracingPolicy, setClientRequestIdPolicy, ndJsonPolicy) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-pipeline-test-coverage
- agentPolicy: verify request.agent is set and not overridden - proxyPolicy: verify proxy agent is set on request, not overridden - tlsPolicy: verify request.tlsSettings is set and not overridden - Keep retry policy smoke tests as-is (well-tested elsewhere) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix weak assertions: replace .resolves; with .resolves.toBeDefined() - Fix reversed assert.equal arguments in bearerTokenAuthenticationPolicy test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ient test 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>
Replace try/catch + assert.fail() with rejects.toThrow/toMatchObject and assert.throws() for cleaner, more idiomatic test code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…peline tests 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>
Replace manual boolean tracking with vi.fn() mock functions and expect().toHaveBeenCalled() assertions for cleaner test patterns. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace inline 'as' type casts with:
- Typed vi.importActual<typeof import(...)> for mock factories
- Helper functions (toIncomingMessage, createMockWritableRequest, getMultipartParts, readBodyAsArrayBuffer) to isolate necessary casts
- Proper typed objects for Agent and TlsSettings instead of empty object casts
- assert.instanceOf for runtime type narrowing (ReadableStream)
- Typed vi.fn<TokenCredential["getToken"]>() instead of 'as any'
- Runtime type guards instead of inline casts
- satisfies operator for browser test stubs
- createHttpHeaders() instead of {} as HttpHeaders
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>
- Replace BodyInit with ConstructorParameters<typeof Response>[0] - Fix signalLike type annotation to be compatible with AbortSignalLike - Spread actual module instead of actual.default for node:https/http mocks 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>
- Replace if/assert.fail type guard with assert.instanceOf for Uint8Array - Replace if/assert.fail type guard with assert.isString for http.url attribute Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Convert try/catch + error capture to expect().rejects.toThrow() in auxiliaryAuthenticationHeaderPolicy and bearerTokenAuthenticationPolicyChallenge - Replace any-typed vi.fn params with Buffer/BufferEncoding types in nodeHttpClient Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jeremymeng
reviewed
Apr 23, 2026
Member
jeremymeng
left a comment
There was a problem hiding this comment.
Looks good overall! I added some comments
- Remove unnecessary IIFE for httpRequestChecker (revert to plain object) - Rename duplicate test suite to 'with fake timers' for clarity - Strengthen onDownloadProgress assertions to verify ev.loadedBytes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
BufferEncoding is narrower than what Writable.write passes, causing TS2345 in CI. Also removes unnecessary IIFE for httpRequestChecker. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jeremymeng
approved these changes
Apr 24, 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