Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docs/plans/2026-03-08-coverage-99-plus-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Coverage 99+ Design

**Goal:** Raise unit-test coverage from the current post-fix level to 99%+ without changing production behavior.

**Context:** The recent `preserveMarkup` work added substantial new logic under `src/Truncate/engines/markup.tsx` and `src/Truncate/markup/render.tsx`. CI focused on browser E2E coverage, so Codecov correctly reported a project-level drop. A first recovery pass already moved local coverage to `98.41%`, leaving only a handful of defensive branches uncovered.

**Recommended Approach:** Add focused unit tests only, centered in `test/Markup.spec.tsx`, and avoid any production refactor. This keeps the fix surgical, preserves behavior, and directly addresses the Codecov signal instead of muting it.

## Options Considered

### Option A: Add focused helper and engine tests
- Keep all changes in tests
- Target the remaining uncovered branches directly
- Fastest path to 99%+

**Trade-off:** A few tests will exercise fairly defensive branches, so they are slightly more synthetic than top-level component tests.

### Option B: Refactor helper internals for easier direct testing
- Could make each branch easier to target
- Might reduce test setup complexity

**Trade-off:** Changes production code purely for coverage, which is unnecessary for this CI repair.

### Option C: Relax or reshape coverage rules
- Fast to make CI green

**Trade-off:** Hides a real test gap and weakens the project signal. Rejected.

## Design

### Scope
- Modify only `test/Markup.spec.tsx`
- Do not modify `src/**` unless a genuine bug is discovered
- Keep existing E2E coverage unchanged

### Test strategy
- Cover the remaining helper branches in `render.tsx`
- Cover the remaining defensive cleanup branches in `markup.tsx`
- Reuse the current measurement sandbox so tests stay close to the real `preserveMarkup` execution path

### Success criteria
- `pnpm vitest run test/Markup.spec.tsx` passes
- `pnpm coverage` reports total coverage at `99%+`
- No production behavior changes
71 changes: 71 additions & 0 deletions docs/plans/2026-03-08-coverage-99-plus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Coverage 99+ Implementation Plan

> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

**Goal:** Raise project unit-test coverage to 99%+ by adding focused tests for the remaining uncovered `preserveMarkup` helper branches.

**Architecture:** Keep production code unchanged and extend the existing focused spec `test/Markup.spec.tsx`. Use narrowly scoped assertions that target the remaining uncovered defensive branches in the snapshot/render helpers and markup truncation engine, then verify with the existing `vitest` coverage workflow.

**Tech Stack:** React, TypeScript, Vitest, Testing Library, Sinon, Happy DOM

---

### Task 1: Cover remaining render helper branches

**Files:**
- Modify: `test/Markup.spec.tsx`
- Reference: `src/Truncate/markup/render.tsx`

**Step 1: Write the failing tests**
- Add tests for `sliceSnapshotNodes` with zero or fractional remaining width.
- Add tests for `trimLeadingWhitespace` when the first node is a line break.
- Add tests for any still-uncovered whitespace handling branches.

**Step 2: Run test to verify it fails or expands coverage needfully**
Run: `pnpm vitest run test/Markup.spec.tsx`
Expected: Existing suite stays green or a new assertion fails for the uncovered branch.

**Step 3: Write minimal test-only implementation**
- Adjust only test fixtures/assertions until the branch is exercised correctly.

**Step 4: Run test to verify it passes**
Run: `pnpm vitest run test/Markup.spec.tsx`
Expected: PASS

### Task 2: Cover remaining markup engine defensive branches

**Files:**
- Modify: `test/Markup.spec.tsx`
- Reference: `src/Truncate/engines/markup.tsx`

**Step 1: Write the failing tests**
- Add a test that forces recursive cleanup of whitespace-only text and empty elements.
- Add a test that exercises unsupported child-node cleanup in the truncation clone path.

**Step 2: Run test to verify it fails or expands coverage needfully**
Run: `pnpm vitest run test/Markup.spec.tsx`
Expected: Targeted assertions prove the branch is now reached.

**Step 3: Write minimal test-only implementation**
- Keep the change isolated to fixture setup and expectations in `test/Markup.spec.tsx`.

**Step 4: Run test to verify it passes**
Run: `pnpm vitest run test/Markup.spec.tsx`
Expected: PASS

### Task 3: Verify project coverage

**Files:**
- Verify: `test/Markup.spec.tsx`

**Step 1: Run focused tests**
Run: `pnpm vitest run test/Markup.spec.tsx`
Expected: PASS

**Step 2: Run full coverage**
Run: `pnpm coverage`
Expected: Total coverage reaches at least `99%`

**Step 3: Review result**
- Confirm no production files changed.
- Confirm only test/docs plan files were touched.
Loading