test(frontend): route four specs through HttpClientTestingModule#5183
Closed
Yicong-Huang wants to merge 2 commits into
Closed
test(frontend): route four specs through HttpClientTestingModule#5183Yicong-Huang wants to merge 2 commits into
Yicong-Huang wants to merge 2 commits into
Conversation
`operator-reuse-cache-status.service.spec.ts`, `operator-menu.service.spec.ts`,
`execute-workflow.service.spec.ts`, and `user-computing-unit.component.spec.ts`
each wired the real Angular `HttpClient` rather than the testing variant —
either by importing `HttpClientModule`, providing `HttpClient` directly, or
hand-rolling a `StubHttpClient` that returns `of("a")` for every `post`. That
left the specs one missing mock away from a real network call in CI and drifted
from the convention in `frontend/TESTING.md`.
Swap each over to `HttpClientTestingModule`:
- The two `HttpClientModule` cases become a one-line import swap.
- `execute-workflow.service.spec.ts` drops the in-file `StubHttpClient`
entirely and the now-unused `Observable` import; the testing module supplies
`HttpClient` directly.
- `user-computing-unit.component.spec.ts` moves `HttpClient` out of `providers`
and pulls `HttpClientTestingModule` into `imports`.
All four specs (20 tests) continue to pass.
Closes apache#5182
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5183 +/- ##
=========================================
Coverage 43.71% 43.71%
Complexity 2218 2218
=========================================
Files 1049 1049
Lines 40578 40578
Branches 4327 4327
=========================================
Hits 17739 17739
Misses 21733 21733
Partials 1106 1106
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add an `*.spec.ts` override to `frontend/.eslintrc.json` so the anti-pattern that apache#5183 just swept the repo of can't grow back: - `no-restricted-imports` blocks `HttpClientModule` from `@angular/common/http` in specs. HttpClientTestingModule is the only legitimate way to wire HttpClient into a unit test. - `no-restricted-syntax` flags `HttpClient` listed as a bare provider inside a `providers: [...]` array. HttpClientTestingModule (in `imports`) already supplies HttpClient; layering the real one on top of that overrides the testing backend. The rule fires on five more specs that apache#5183 missed — each one had either redundant `HttpClientModule` imports or a stale `HttpClient` provider sitting next to a working `HttpClientTestingModule`. Clean those up so `yarn lint` stays green: - `user-avatar.component.spec.ts` — drop the redundant `HttpClientModule` from imports. - `user-workflow.component.spec.ts`, `coeditor-user-icon.component.spec.ts`, `coeditor-presence.service.spec.ts` — drop the bare `HttpClient` provider and the now-unused import. - `operator-metadata.service.spec.ts` — drop the bare `HttpClient` provider. The import stays because the spec injects HttpClient via `TestBed.inject(HttpClient)` to talk to HttpTestingController. All nine touched specs (37 tests) continue to pass. Closes apache#5184
Contributor
Author
|
Consolidated into #5185 — the lint guardrail and the extra spec cleanups it surfaced live in the same branch as this PR's data fix, so reviewing the whole anti-pattern (cleanup + prevention) in one place is simpler. |
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.
What changes were proposed in this PR?
Four specs wired the real Angular
HttpClientrather than the testing variant — either by importingHttpClientModule, providingHttpClientdirectly, or hand-rolling aStubHttpClientthat returnedof("a")for everypost. That left the specs one missing mock away from a real network call in CI and drifted from the convention infrontend/TESTING.md.Each spec is now routed through
HttpClientTestingModule:operator-reuse-cache-status.service.spec.ts/operator-menu.service.spec.ts— one-line import swap from@angular/common/http(HttpClientModule) to@angular/common/http/testing(HttpClientTestingModule).execute-workflow.service.spec.ts— drops the in-fileStubHttpClientand itsObservableimport; the testing module now suppliesHttpClient.user-computing-unit.component.spec.ts— movesHttpClientout ofprovidersand pullsHttpClientTestingModuleintoimports.Any related issues, documentation, discussions?
Closes #5182. The rule itself is documented in
frontend/TESTING.md(introduced in #5170).How was this PR tested?
yarn ng test --watch=false --include=…against the four affected specs locally: 4 files, 20 tests, all pass.yarn format:ciclean.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7