The Azure SDK monorepo upgrade (storage-blob 12.26→12.31, identity
4.5→4.9) adds "type": "module" to package.json, making jest.mock()
unable to intercept imports from production code.
- AzureBlobStorageUrlReader: accept createContainerClient as an
optional dependency, letting tests pass a mock directly instead
of trying to mock the @azure/storage-blob module
- AzureUrlReader: provide PAT credentials in all test cases so
DefaultAzureCredential is never instantiated — the Bearer auth
flow is already covered by the integration package's own tests
- DefaultAzureDevOpsCredentialsProvider: use expect.any() for
mock instance comparison instead of new DefaultAzureCredential()
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Validate the parsed Retry-After value is a finite positive number before
using it as a delay, falling back to exponential backoff otherwise. This
prevents a near-zero delay tight retry loop when the header contains an
HTTP-date or unexpected value.
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Capturing globalThis.fetch as a value at construction time meant the
GitLabUrlReader tests bypassed the MSW fetch interceptor and hit the
real gitlab.com (returning 401). Wrapping the call resolves fetch at
invocation time so the patched fetch is used.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Each catch path now decides for itself whether to rethrow or sleep and
continue, so the loop body has a definite Response after the try/catch
and there is no shared `error: unknown` slot that could in principle be
thrown unset. Pulls the exponential delay into a tiny local helper to
share between the two retry paths.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Flip the order of the response/error check so TypeScript narrows the
types itself rather than relying on `response!` to assert what the code
already guarantees by construction.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
- Cancel discarded response bodies before retrying so the underlying
connection can be returned to the pool instead of being held open
until the response is garbage collected.
- Stop asserting on the rejected error message in the network-error
retry test; track rejection via a flag so the test isn't tied to
fetch/MSW error strings.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Removes a misplaced `mode: 'same-origin'` option that would have rejected
cross-origin requests when the integration is used from a browser, and
extends the retry wrapper so transient network errors are retried using
the configured `maxRetries`. Caller-initiated aborts still propagate
immediately.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Remove `export` from five internal helper functions that are not part of
the published API and are only used within their own files. The `sleep`
function in GitLabIntegration is kept exported for test access but marked
as `@internal`.
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
Removed the test-only `registerMswTestHooks` function from `helpers.ts`
and replaced it with the shared version from `@backstage/backend-test-utils`.
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
Move jest from dependencies to peer dependencies, allowing users to
choose between Jest 29 and Jest 30.
The CLI now detects the Jest version at runtime and uses the
appropriate environment:
- Jest 29: Uses standard jest-environment-jsdom
- Jest 30: Uses a custom environment based on @jest/environment-jsdom-abstract
with fixes for Web API globals (fetch, streams, Error, etc.)
The cross-fetch polyfill is only injected for Jest 29, as with Jest 30+
our patched Jest environment is used. The network request blocker is made
MSW-compatible by checking if fetch was wrapped before blocking.
Jest 30 (with jsdom v27) fixes `Could not parse CSS stylesheet`
warnings/errors when testing components from @backstage/ui or other
packages using CSS `@layer` declarations.
New peer dependencies (install based on your Jest version):
- jest (required, ^29 or ^30)
- Jest 29 requires: jest-environment-jsdom
- Jest 30 requires: @jest/environment-jsdom-abstract, jsdom
Production code changes for jsdom 27 testability:
- AppIdentityProxy: extract navigateToUrl method for spying
- LiveReloadAddon: export utils.reloadPage for spying
- collect.ts: export internal.resolvePackagePath for mocking
MockFetchApi: evaluate global.fetch at call time instead of construction
time, allowing MSW to patch fetch after MockFetchApi is constructed.
Test adaptations for jsdom 27:
- Use RGB values instead of named colors in CSS assertions
- Update error format expectations (hyphenated type names, SyntaxError
instead of FetchError for JSON parse errors)
- Simplify URL error assertions for cross-version compatibility
- Fix accessible name whitespace handling for external links
- Use history.replaceState for location mocking (non-configurable)
- Use fireEvent.blur for contentEditable elements
- Move async assertions inside waitFor for race conditions
- Remove Blob.prototype.text polyfill (now native)
- Remove test case using credentials in plugin:// URLs
Test adaptations for Jest 30:
- Replace `expect.objectContaining([...])` with direct array equality
- Replace `expect.objectContaining({ length: N })` with
`expect.any(Array)` + separate `toHaveLength()` assertions
- Use child process for native Node.js module resolution in
collect.test.ts to work around Jest 30's resolver behavior
- Update snapshot headers for new Jest format
Also removes the jest-haste-map patch which is no longer needed.
Signed-off-by: Johan Persson <johanopersson@gmail.com>