Skip to content

feature: raise unit test coverage to ~98% with Vitest#31

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1780500231-increase-coverage
Open

feature: raise unit test coverage to ~98% with Vitest#31
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1780500231-increase-coverage

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 3, 2026

Copy link
Copy Markdown

Summary

Adds Vitest unit tests for the ~24 previously-untested source files (interceptors, pipes, the auth directive, layout/shared components, all feature components, and the article/editor/home/profile/settings pages), plus retry/unavailable-state coverage for UserService. No production code was changed.

Coverage (before → after)

Measured with the same vitest.config.ts (all: true over src/**/*.ts, excluding specs, models, routes, app.config.ts, main.ts, test helpers), so the numbers are apples-to-apples.

Metric Before After
Statements 18.36% 98.45%
Lines 17.32% 99.5%
Functions 32.66% 98.66%
Branches 5% 89.16%

Tests: 180 → 291 (all passing; no existing tests modified or weakened).

What was tested

  • Interceptors: api (url prefixing), token (auth header), error (401 purge, /user special-case, error normalization)
  • Pipes: default-image, markdown
  • Directive: if-authenticated (view create/clear on auth state)
  • Layout/shared: app, header, footer, list-errors
  • Article feature: favorite-button, article-meta, article-preview, article-comment, article-list, and the article, editor, home pages
  • Profile feature: follow-button, profile-articles, profile-favorites, and the profile page
  • Settings: settings page
  • UserService: added 5XX retry/backoff + unavailable state + retry-cancel tests (70.9% → 98.18%)

Notes / mechanics

  • Added @vitest/coverage-v8 and zone.js dev deps (required for v8 coverage + Angular TestBed in jsdom).
  • New shared helper src/testing/setup-test-bed.ts initializes the Angular TestBed once per file (imports @angular/compiler first to avoid JIT errors on PlatformLocation). Excluded from coverage.
  • vitest.config.ts: enabled all: true so untested files count toward overall coverage, added json-summary reporter, and excluded non-executable declaration/config files (models, routes, app.config.ts).
  • Components are tested by injecting them via TestBed with mocked services (RxJS of/throwError/BehaviorSubject); HTTP-level service tests keep using HttpClientTestingModule.
  • Ran bun run format; format:check is clean. e2e/Playwright tests untouched.

Link to Devin session: https://app.devin.ai/sessions/54747daa1bc44e1187c3da73f91a8489
Requested by: @bnob-git


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)

Add unit tests for previously untested interceptors, pipes, directive,
layout, shared, feature components and pages, plus retry/unavailable
coverage for UserService. Configure v8 coverage (all source files) and
add a shared TestBed init helper.

Overall line coverage: 17.32% -> 99.5%, statements 18.36% -> 98.45%.

Co-Authored-By: Bobby Nobakht <bobby.nobakht@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Author

CI note: test (Playwright e2e) failure is pre-existing and unrelated to this PR

This PR only adds unit tests + Vitest coverage config/deps; it changes no production code. The test CI job runs bun run test:e2e (Playwright), not the unit tests — unit tests aren't run in CI.

The 6 failures are all in e2e/settings.spec.ts ("Settings - Profile Updates"), where the settings update API returns 422 in the no-API mode the repo runs e2e under (so the page stays on /settings instead of redirecting to /profile/...).

I reproduced this on a clean checkout of the base branch (main, f39866e):

$ bun run test:e2e -- e2e/settings.spec.ts   # on origin/main
  6 failed
  1 passed (2.0m)

Identical 6 failures → these are pre-existing on main, independent of this PR. format and security-tests checks pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants