Skip to content

[nightshift] test-gap: test coverage analysis #4

@Microck

Description

@Microck

Test Gap Analysis: micr-dev/projects

Summary

Analysis of test coverage for the Next.js 16 portfolio showcase application. The codebase has one test file (app/repo-paths.test.mjs) covering utility functions, while the main application logic remains untested.


Existing Tests

File Coverage
app/repo-paths.test.mjs ✅ Tests normalizeRepoSlugPath(), getRepoDisplayTitle(), getRepoSlugPath() — 3 test cases
All other source files ❌ No tests

P2 — repo-sections.ts has no tests (server-side data parsing)

File: app/repo-sections.ts
Severity: P2 (Medium)

getRepoSections() reads REPO.md, parses sections and items, and joins them with repoDescriptions and repoMetadata. If a repo key in REPO.md doesn't have a matching entry in either map, the function throws an Error. This is a critical data integrity check with no test coverage.

Recommendation: Add tests for:

  • Happy path: parse valid REPO.md → verify sections structure
  • Missing description: verify throw new Error('Missing repo description...')
  • Missing metadata: verify throw new Error('Missing repo metadata...')
  • hasRepoSlug(): verify slug lookup in sections

P2 — repo-metadata.ts has no data integrity tests

File: app/repo-metadata.ts
Severity: P2 (Medium)

The repoMetadata record maps 60+ display keys to repo metadata objects. Each entry must have repo, sourceUrl, livePreviewUrl, and isPrivate. No tests verify:

  • All keys have valid sourceUrl patterns
  • isPrivate is a boolean
  • repo strings follow org/repo format
  • No duplicate entries exist

Recommendation: Add a data integrity test suite:

test("all metadata entries have valid source URLs")
test("all metadata repo fields match org/repo pattern")  
test("no duplicate repo values in metadata")

P3 — repo-descriptions.ts / copy batches have no structure validation

Files: app/repo-descriptions.ts, app/repo-copy-batches/*.ts
Severity: P3 (Low)

Per DESCRIPTION.md, each description must have exactly 3 paragraphs and a languages array. The RepoDescription type enforces paragraphs: [string, string, string], but runtime validation is absent. A malformed batch file could ship with 0 or 1 paragraphs without failing type-check if the tuple constraint is bypassed.

Recommendation: Add a test that imports all batches and verifies:

  • Each entry has exactly 3 non-empty paragraphs
  • Each entry has a non-empty languages array
  • No duplicate keys across batches

P3 — portfolio-shell.tsx Spanish redirect logic untested

File: app/portfolio-shell.tsx
Severity: P3 (Low)

The handlePreloaderComplete callback implements browser language detection and localStorage-based redirect dismissal. This logic has branching for:

  • hostname === "proyectos.micr.dev" (skip on Spanish subdomain)
  • localStorage dismissal state
  • Browser language detection (navigator.language)
  • Timer-based delay (950ms)

This is client-side logic that's harder to unit test, but the redirect logic could be extracted into a testable utility.

Recommendation: Extract redirect decision logic into a pure function and test it:

export function shouldShowSpanishPrompt(hostname: string, storageValue: string | null, languages: string[]): boolean

P3 — smooth-scroll.tsx Lenis integration untested

File: app/smooth-scroll.tsx
Severity: P3 (Low)

The Lenis smooth scroll client component has proper cleanup (cancelAnimationFrame + lenis.destroy), but the RAF loop and configuration aren't tested. Low priority since it's a thin wrapper around a well-tested library.


Test Infrastructure

  • Framework: Node.js built-in node:test + node:assert/strict (no Jest/Vitest)
  • Test runner: Tests use .mjs extension and import .ts files directly (requires Node 22+ or tsx)
  • No CI test step: package.json scripts have no test script — only dev, build, start, lint

Recommendation: Add "test": "node --test app/repo-paths.test.mjs" to package.json scripts and expand from there.


Priority Order for Adding Tests

  1. High value: repo-sections.ts — data parsing with error paths
  2. High value: repo-metadata.ts — data integrity across 60+ entries
  3. Medium value: repo-descriptions.ts batch structure validation
  4. Low value: Extract and test Spanish redirect logic
  5. Low value: smooth-scroll.tsx Lenis wrapper

Overall Assessment: The codebase has a solid foundation with one well-written test file. The highest-value additions are server-side data integrity tests for the repo metadata and section parsing, which are the core logic of the application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions