Skip to content

feat : configure vitest test coverage#139

Merged
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:fix/vitest-coverage
Jun 28, 2026
Merged

feat : configure vitest test coverage#139
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:fix/vitest-coverage

Conversation

@YasserYG8

@YasserYG8 YasserYG8 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements test coverage reporting using Vitest's v8 provider both locally and within the GitHub Actions
CI pipeline, resolving issue #64.

Changes Made:

  1. Added Dependency: Installed @vitest/coverage-v8 as a development dependency.
  2. Configured Vitest: Updated vitest.config.ts to define the coverage block with:
    • v8 as the provider.
    • Outputs in text , json , and html formats.
    • Included all source code files while excluding test files and type definitions.
  3. New Scripts: Added test:coverage to package.json to easily run test coverage checks.
  4. CI Integration: Updated the GitHub Actions build pipeline ci.yml to execute pnpm test:coverage instead
    of pnpm test , ensuring coverage summaries are printed during checks.

How to test locally

  1. Run pnpm install to update your dependencies.
  2. Run pnpm test:coverage to execute the tests and print the coverage report table in your terminal.
  3. View the detailed HTML report by opening coverage/index.html in your browser.

Summary by CodeRabbit

  • Tests

    • Added coverage reporting to the test workflow and configured it to generate text, JSON, and HTML reports.
    • Introduced a coverage-enabled test command for local and CI use.
  • Chores

    • Updated workspace settings to allow required build steps for a dependency used in the project.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a coverage-enabled Vitest script and configuration, updates CI to run coverage, and enables core-js builds in the workspace.

Changes

Coverage execution changes

Layer / File(s) Summary
Coverage script and dependency
package.json
Adds a test:coverage script and the @vitest/coverage-v8 dev dependency.
Vitest coverage settings
vitest.config.ts
Sets the V8 coverage provider, coverage reporters, and coverage include/exclude globs.
CI coverage run
.github/workflows/ci.yml, pnpm-workspace.yaml
Runs pnpm test:coverage in CI and changes the workspace build permission for core-js.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • DataDave-Dev/weftmap#134: Also changes the CI workflow and pnpm setup, with related pnpm action handling in the same build path.

Poem

I twitched my nose at the build-path gleam,
And sprinkled coverage through the stream.
Vitest hopped in v8 moonlight,
Core-js bounded on just right,
Now the reports make a cozy team.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change and testing, but it does not follow the required template sections or checklist. Rewrite it using the template headings: Qué hace, Tipo, and Checklist; include the required checkbox items and a brief change summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: configuring Vitest coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpm-workspace.yaml`:
- Line 2: The build-script allowlist currently includes core-js unnecessarily;
remove core-js from the allowlist in the workspace config so only packages with
a justified install failure are kept. Update the pnpm workspace allowlist entry
directly, and leave `@vitest/coverage-v8` out since it does not need lifecycle
scripts and core-js postinstall is unrelated.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 36a1b3ad-c6ab-4a4f-86b2-49485fffaf01

📥 Commits

Reviewing files that changed from the base of the PR and between 656cd67 and 08d43a9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • .github/workflows/ci.yml
  • package.json
  • pnpm-workspace.yaml
  • vitest.config.ts

Comment thread pnpm-workspace.yaml
@@ -1,5 +1,5 @@
allowBuilds:
core-js: false
core-js: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Does the current core-jspackage execute a lifecycle or postinstall script during installation, and is enabling pnpm build scripts forcore-jsnormally required when adding Vitest coverage with@vitest/coverage-v8?

💡 Result:

Yes, the core-js package executes a postinstall script [1][2]. This script, located in the package as postinstall.js, is primarily used to display a message to users about the project [1][3][4]. Regarding your second question, enabling pnpm build scripts for core-js is not normally required specifically for adding Vitest coverage with @vitest/coverage-v8. Vitest with the @vitest/coverage-v8 provider performs code coverage collection at runtime by instructing the V8 engine, which does not require your dependencies to undergo custom build or instrumentation steps during the installation process [5]. While pnpm may restrict package lifecycle scripts (such as postinstall) by default for security, this restriction is independent of the functional requirements of Vitest coverage [2][6]. If your environment or pnpm configuration blocks the core-js postinstall script, you may need to explicitly approve it to ensure the package is installed as intended, but this is a package management configuration, not a requirement for enabling Vitest coverage itself [2][6].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== pnpm-workspace.yaml ==\n'
cat -n pnpm-workspace.yaml

printf '\n== core-js mentions in repo ==\n'
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/.git/**' '\bcore-js\b' .

printf '\n== package.json files mentioning vitest or coverage-v8 ==\n'
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/.git/**' '"`@vitest/coverage-v8`"|vitest|coverage-v8' --glob 'package.json' .

printf '\n== package.json files mentioning core-js ==\n'
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/.git/**' '"core-js"' --glob 'package.json' .

Repository: DataDave-Dev/weftmap

Length of output: 851


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
import pathlib, re, json
p = pathlib.Path('pnpm-workspace.yaml')
print(p.read_text())
PY

Repository: DataDave-Dev/weftmap

Length of output: 242


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== pnpm-workspace.yaml ==\n'
cat -n pnpm-workspace.yaml

printf '\n== core-js mentions in repo ==\n'
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/.git/**' '\bcore-js\b' .

printf '\n== package.json files mentioning vitest or coverage-v8 ==\n'
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/.git/**' '"`@vitest/coverage-v8`"|vitest|coverage-v8' --glob 'package.json' .

printf '\n== package.json files mentioning core-js ==\n'
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/.git/**' '"core-js"' --glob 'package.json' .

Repository: DataDave-Dev/weftmap

Length of output: 851


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
import pathlib
print(pathlib.Path('pnpm-workspace.yaml').read_text())
PY

Repository: DataDave-Dev/weftmap

Length of output: 242


Keep core-js off the build-script allowlist unless there’s a separate install failure to justify it. @vitest/coverage-v8 doesn’t need lifecycle scripts, and core-js’s postinstall is unrelated to coverage. pnpm-workspace.yaml:2

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm-workspace.yaml` at line 2, The build-script allowlist currently includes
core-js unnecessarily; remove core-js from the allowlist in the workspace config
so only packages with a justified install failure are kept. Update the pnpm
workspace allowlist entry directly, and leave `@vitest/coverage-v8` out since it
does not need lifecycle scripts and core-js postinstall is unrelated.

@YasserYG8

Copy link
Copy Markdown
Contributor Author

Vitest Code Coverage Analysis Report

This document provides a comprehensive breakdown and strategic analysis of the code coverage report generated for the weftmap repository.


📈 Executive Summary

  • Overall Core Health: The core parser engine (AST treesitter bindings, registries, and TS/JS analyzers) is in an excellent state with high-to-perfect coverage.
  • Key Area of Concern: The Python analyzer has the lowest coverage among all active parsers, followed by the SQL analyzer's branches.
  • UI & Routing (Normal behavior): UI files and layout routes are at 0% coverage under Vitest. This is expected because they are verified using Playwright (E2E) rather than unit tests.

🔍 Detailed Coverage Breakdown

🟢 1. High Coverage Modules (Well-Tested)

These files represent the strongest parts of the test suite. No immediate actions are needed here.

File Statements % Branches % Lines % Notes
src/lib/analysis/registry.ts 100% 100% 100% Analyzer registration behaves as expected.
src/lib/analysis/treesitter.ts 100% 100% 100% Tree-sitter WASM initializing logic is robust.
src/lib/analysis/analyzers/typescript.ts 100% 100% 100% TS parsing and class/interface mapping is fully covered.
src/lib/analysis/analyzers/javascript.ts 100% 100% 100% JS parser functions match 100% test scenarios.
src/lib/analysis/analyzers/shared.ts 95.39% 80.3% 97.67% Base traversal class utility has only minor missing lines (45, 115, 199).
src/app/api/analyze/route.ts 97.72% 90.32% 100% API route parses multi-file requests securely.

🟡 2. Partially Covered Modules (Actions Needed)

These modules require additional unit test scenarios to cover missed lines and conditional branches.

🐍 Python Analyzer (src/lib/analysis/analyzers/python.ts)

  • Statement Coverage: 46.15%
  • Branch Coverage: 20.83%
  • Target Lines: 14-16, 31-35, 45-53
  • Analysis: The tests are only checking the happy path. They are missing error scenarios, conditional edge cases in syntax checking, or specific node lookup steps.

🕸️ JS-Like Analyzer (src/lib/analysis/analyzers/jslike.ts)

  • Statement Coverage: 72.5%
  • Branch Coverage: 53.84%
  • Target Lines: 19-20, 27, 50-53
  • Analysis: Traversal hooks for generic JS AST structures are partially covered; branch paths corresponding to unusual variable declarations or export patterns are missed.

🛢️ SQL Analyzer (src/lib/analysis/analyzers/sql.ts)

  • Statement Coverage: 78%
  • Branch Coverage: 56.36%
  • Target Lines: 206-207, 270-274
  • Analysis: Complex SQL query configurations and multi-statement schemas missed some AST branch checks.

🐹 Go and Rust Analyzers

  • Go (go.ts): 75% Statement coverage (missing line 17).
  • Rust (rust.ts): 75% Statement coverage (missing line 18).

🔴 3. Uncovered Modules (0% Coverage)

These directories represent code not tested by Vitest:

  • src/components/layout/
  • src/components/sections/
  • src/components/ui/
  • src/db/
  • src/app/[lang]/

Important

Do not write unit tests for these. Unit testing Next.js layouts, visual diagram nodes, and page loads in Node.js environments is fragile and slow. They are already tested inside the E2E framework (playwright.config.ts).


🎯 Action Plan to Reach 100% Core Coverage

To maximize your testing score on the analysis engines, implement the following test additions in analyzers.test.ts:

A. Python Target

Create a mock Python code block containing:

  1. Inner function definitions (to hit nested scoping).
  2. Class declarations with multiple inheritance structures.
  3. Complex module exports.

B. SQL Target

Create a mock SQL migration query containing:

  1. CREATE TABLE statements with foreign keys.
  2. ALTER TABLE operations.
  3. Nested comments or CTEs (WITH clauses).

@DataDave-Dev DataDave-Dev merged commit 2a2b890 into DataDave-Dev:main Jun 28, 2026
3 checks passed
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.

2 participants