Skip to content

Conversation

@csikb
Copy link
Contributor

@csikb csikb commented Oct 26, 2025

Summary by CodeRabbit

  • Tests

    • Enforced 100% statement coverage and added coverage reporters.
    • Enabled automatic mock cleanup and restoration for more reliable tests.
    • Consolidated and relocated many tests to a narrower discovery scope; added new middleware tests and removed legacy duplicates.
  • Chores

    • Narrowed TypeScript test compilation to exclude runtime test files and streamlined test-related config for faster, more isolated runs.

@coderabbitai
Copy link

coderabbitai bot commented Oct 26, 2025

Walkthrough

Tests were relocated into src/, test imports were rewritten to local relative paths, several middleware tests were added in src/middleware/, legacy tests/ equivalents were removed, TypeScript test compilation excludes were added, and Vitest test discovery and coverage/config options were updated.

Changes

Cohort / File(s) Summary
Test import path updates (src)
src/config.defaults.test.ts, src/config.overwrite.test.ts, src/database/index.test.ts, src/database/postgres.test.ts, src/index.test.ts, src/middleware/bodyparser.test.ts, src/middleware/postgraphile.test.ts, src/router/health.test.ts, src/router/index.test.ts
Updated test imports/mocks to use local relative paths (e.g., ./module.js or ../module.js) instead of project-root relative paths (e.g., ../../src/...). Minor test setup relocation in src/index.test.ts (added beforeEach console mock).
New middleware tests (src)
src/middleware/compress.test.ts, src/middleware/helmet.test.ts, src/middleware/index.test.ts
Added unit tests that mock upstream middleware (koa-compress, koa-helmet, etc.), dynamically import the local middleware modules, and assert delegation and exported values match mocked results.
Removed legacy tests (tests/)
tests/middleware/compress.test.ts, tests/middleware/helmet.test.ts, tests/middleware/index.test.ts
Deleted tests from the separate tests/ directory (functionality appears recreated under src/middleware/).
TypeScript config — exclude tests
tsconfig.json
Added an exclude pattern to omit src/**/*.test.ts from TypeScript compilation.
TypeScript test config — include simplification
tsconfig.test.json
Simplified include to focus on integration tests and Vitest config files (removed earlier tests and global-setup entries).
Vitest configuration changes
vitest.config.ts
Switched test include from tests/**/*... to src/**/*..., enabled clearMocks, added unstubEnvs, unstubGlobals, restoreMocks, enabled coverage (provider v8), added reporters (text, lcov, json-summary), narrowed coverage include, and set statement coverage threshold to 100%.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to:
    • vitest.config.ts — high-impact coverage settings and changed include pattern.
    • tsconfig.json/tsconfig.test.json — ensure build and test discovery remain compatible.
    • New src/middleware/* tests — verify mocks and dynamic imports correctly target the intended modules.
    • src/index.test.ts — moved console spy into beforeEach; ensure no test-order dependencies.

Poem

🐰 In burrows of code the tests now dwell,
Snug beside functions they know so well,
Paths trimmed short, mocks hopped in line,
I nibble assertions, one test at a time,
Hopping home — coverage tastes like thyme.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix: merge src and tests" directly describes the primary structural change throughout the changeset. The pull request consolidates test files from a separate tests/ directory into the src/ directory alongside source code, updates import paths accordingly, and modifies configuration files to reflect this new structure. The title is concise, clear, and specific enough that someone reviewing the git history would immediately understand the main change without needing to examine the details.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch merge-src-and-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fb81703) to head (b1da389).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #283   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines           23        23           
  Branches         4         4           
=========================================
  Hits            23        23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/config.defaults.test.ts (1)

25-25: Fix incorrect dynamic import path.

The dynamic import path ../src/config.js is incorrect for a test file located at src/config.defaults.test.ts. This would try to resolve to a path outside the repository structure.

Apply this diff:

-    const { default: actual } = await import('../src/config.js')
+    const { default: actual } = await import('./config.js')
src/middleware/postgraphile.test.ts (1)

3-4: Fix incorrect import and mock paths.

The import and mock paths still reference ../../src/, which is incorrect for a test file now located at src/middleware/postgraphile.test.ts. These paths would resolve outside the repository structure.

Apply this diff to fix all the incorrect paths:

-import config from '../../src/config.js'
-import { postgres } from '../../src/database/index.js'
+import config from '../config.js'
+import { postgres } from '../database/index.js'
-vi.mock('../../src/config.js', () => ({
+vi.mock('../config.js', () => ({
   default: {
     schema: 'schema',
     postGraphile: vi.fn().mockName('config.postGraphile'),
   },
 }))
-vi.mock('../../src/database/index.js', () => ({
+vi.mock('../database/index.js', () => ({
   postgres: vi.fn().mockName('postgres'),
 }))

Also applies to: 6-6, 15-15

src/config.overwrite.test.ts (1)

30-30: Fix incorrect dynamic import path.

The dynamic import path ../src/config.js is incorrect for a test file located at src/config.overwrite.test.ts. This would try to resolve to a path outside the repository structure.

Apply this diff:

-    const { default: actual } = await import('../src/config.js')
+    const { default: actual } = await import('./config.js')
🧹 Nitpick comments (1)
vitest.config.ts (1)

12-14: Consider whether 100% statement coverage is realistic.

A 100% statement coverage threshold is quite strict and may block legitimate changes. Consider whether a slightly lower threshold (e.g., 90-95%) would be more pragmatic while still maintaining high code quality.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb81703 and e4c839d.

📒 Files selected for processing (18)
  • src/config.defaults.test.ts (1 hunks)
  • src/config.overwrite.test.ts (1 hunks)
  • src/database/index.test.ts (2 hunks)
  • src/database/postgres.test.ts (3 hunks)
  • src/index.test.ts (2 hunks)
  • src/middleware/bodyparser.test.ts (1 hunks)
  • src/middleware/compress.test.ts (1 hunks)
  • src/middleware/helmet.test.ts (1 hunks)
  • src/middleware/index.test.ts (1 hunks)
  • src/middleware/postgraphile.test.ts (1 hunks)
  • src/router/health.test.ts (1 hunks)
  • src/router/index.test.ts (2 hunks)
  • tests/middleware/compress.test.ts (0 hunks)
  • tests/middleware/helmet.test.ts (0 hunks)
  • tests/middleware/index.test.ts (0 hunks)
  • tsconfig.json (1 hunks)
  • tsconfig.test.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • tests/middleware/compress.test.ts
  • tests/middleware/helmet.test.ts
  • tests/middleware/index.test.ts
🔇 Additional comments (17)
tsconfig.json (1)

10-11: LGTM!

Excluding test files from compilation is appropriate when co-locating tests with source code. This ensures test files don't end up in the production build.

tsconfig.test.json (1)

6-6: LGTM!

Narrowing the include pattern correctly reflects that unit tests now live in src/ and are discovered through vitest configuration, while integration tests remain in testsInt/.

vitest.config.ts (2)

5-5: LGTM!

The test include pattern correctly points to the new test location in src/, aligning with the co-location strategy.


6-18: Good test hygiene improvements.

The new test options (clearMocks, unstubEnvs, unstubGlobals, restoreMocks) and coverage configuration improve test isolation and visibility.

src/database/index.test.ts (1)

2-14: LGTM!

Import paths correctly use relative paths from the test's new location in src/database/.

src/database/postgres.test.ts (1)

3-25: LGTM!

All import and mock paths correctly adjusted for the test's location in src/database/.

src/config.defaults.test.ts (1)

3-3: LGTM!

The type import correctly uses a relative path from the test's location in src/.

src/middleware/postgraphile.test.ts (1)

28-28: LGTM!

The dynamic import correctly uses a relative path for the co-located middleware module.

src/config.overwrite.test.ts (1)

3-3: LGTM!

The type import correctly uses a relative path from the test's location in src/.

src/router/health.test.ts (1)

4-5: LGTM! Import paths correctly updated.

The imports and mock paths have been correctly updated to use relative paths that reflect the new test location.

Also applies to: 7-7

src/middleware/helmet.test.ts (1)

1-15: LGTM! Test structure is sound.

The test correctly validates helmet middleware initialization and export using dynamic imports and mocking.

src/middleware/bodyparser.test.ts (1)

11-11: LGTM! Import path correctly updated.

The relative import path correctly reflects the new co-located test location.

src/middleware/index.test.ts (1)

1-35: LGTM! Comprehensive middleware index test.

The test properly validates that all middlewares are exported with correct structure and order, using well-named mocks for debugging clarity.

src/router/index.test.ts (1)

2-2: LGTM! Import paths correctly updated.

All import and mock paths have been correctly updated to relative paths for the co-located test location.

Also applies to: 4-4, 14-14

src/middleware/compress.test.ts (1)

1-16: LGTM! Compress middleware test is thorough.

The test correctly validates that compress is invoked with the expected threshold: 0 option and that the export matches the mocked result.

src/index.test.ts (2)

3-3: LGTM! Import paths correctly updated.

All import and mock paths have been correctly updated to use relative paths for the new test location.

Also applies to: 9-10, 22-22, 27-27, 33-33, 48-48


41-43: Good practice: console.log mocked in beforeEach.

Moving the console.log mock setup to beforeEach ensures a fresh mock for each test, which is a testing best practice.

@csikb csikb added this pull request to the merge queue Oct 26, 2025
@csikb csikb removed this pull request from the merge queue due to a manual request Oct 26, 2025
@csikb csikb changed the title Merge src and tests fix: merge src and tests Oct 26, 2025
@csikb csikb added this pull request to the merge queue Oct 26, 2025
Merged via the queue into main with commit d9eefc0 Oct 26, 2025
17 checks passed
@csikb csikb deleted the merge-src-and-tests branch October 26, 2025 07:33
@bsstudio-pr-release
Copy link

🎉 This PR is included in version 2.0.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants