Skip to content

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Nov 16, 2025

  • add more tests for optional params to explicit and verify their behavior
  • add simple tests for "route masks" processing and matching to ensure they function like the regular tree

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for route matching and mask processing capabilities.
    • Added test cases for dynamic parameter matching, index route handling, and various route configurations including static, dynamic, and optional routes with trailing slashes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2025

Walkthrough

This PR expands test coverage for router-core's route matching utilities by adding two new public exports (findFlatMatch, processRouteMasks) and introducing comprehensive test suites covering static, dynamic, optional route matching, index routes with trailing slashes, and route mask processing validation.

Changes

Cohort / File(s) Summary
Route matching test utilities
packages/router-core/tests/new-process-route-tree.test.ts
Added public exports for findFlatMatch and processRouteMasks utilities. Expanded test suite with comprehensive cases for flat-match validation (static, dynamic, optional, wildcard routes), route mask processing via processRouteMasks, and index route handling across route type and trailing slash combinations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify new exports are appropriately scoped and documented
  • Validate test cases follow existing patterns and cover intended route matching scenarios
  • Ensure route mask processing tests correctly validate tree structure (staticInsensitive, dynamic, optional branches)

Possibly related PRs

Suggested labels

package: router-core

Suggested reviewers

  • schiller-manuel

Poem

🐰 Hoppy routes now fully tested bright,
Static, dynamic, masks—all just right!
Flat matching hops through every case,
Trail slashes handled with swift grace!

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 title clearly summarizes the main change: adding missing unit tests to the new processRouteTree functionality in router-core.
✨ 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 test-router-core-more-process-tree-tests

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

@nx-cloud
Copy link

nx-cloud bot commented Nov 16, 2025

View your CI Pipeline Execution ↗ for commit 2d61d96

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 9m 47s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 28s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-16 08:38:01 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 16, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5879

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5879

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5879

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5879

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5879

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5879

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5879

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5879

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5879

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5879

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5879

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5879

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5879

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5879

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5879

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5879

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5879

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5879

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5879

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5879

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5879

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5879

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5879

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5879

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5879

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5879

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5879

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5879

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5879

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5879

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5879

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5879

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5879

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5879

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5879

commit: 2d61d96

Copy link
Contributor

@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

🧹 Nitpick comments (1)
packages/router-core/tests/new-process-route-tree.test.ts (1)

792-833: Consider restructuring with beforeAll for better test maintainability.

While the sequential tests correctly validate the route masks processing workflow, the current structure has tests 2-5 depending on the side effects of test 1. This makes tests brittle if run in isolation or if new tests are inserted.

Consider this refactor:

 describe('processRouteMasks', { sequential: true }, () => {
   const routeTree = {
     id: '__root__',
     isRoot: true,
     fullPath: '/',
   } as AnyRoute
-  const { processedTree } = processRouteTree(routeTree)
+  let processedTree: ReturnType<typeof processRouteTree>['processedTree']
+
+  beforeAll(() => {
+    const result = processRouteTree(routeTree)
+    processedTree = result.processedTree
+    
+    const routeMasks: Array<RouteMask<AnyRoute>> = [
+      { from: '/a/b/c', routeTree },
+      { from: '/a/b/d', routeTree },
+      { from: '/a/$param/d', routeTree },
+      { from: '/a/{-$optional}/d', routeTree },
+      { from: '/a/b/{$}.txt', routeTree },
+    ]
+    processRouteMasks(routeMasks, processedTree)
+  })
+
   it('processes a route masks list into a segment tree', () => {
-    const routeMasks: Array<RouteMask<AnyRoute>> = [
-      { from: '/a/b/c', routeTree },
-      { from: '/a/b/d', routeTree },
-      { from: '/a/$param/d', routeTree },
-      { from: '/a/{-$optional}/d', routeTree },
-      { from: '/a/b/{$}.txt', routeTree },
-    ]
-    processRouteMasks(routeMasks, processedTree)
     const aBranch = processedTree.masksTree?.staticInsensitive?.get('a')
     expect(aBranch).toBeDefined()
     expect(aBranch?.staticInsensitive?.get('b')).toBeDefined()
     expect(aBranch?.dynamic).toHaveLength(1)
     expect(aBranch?.optional).toHaveLength(1)
   })

This separates setup from assertions and makes each test independently understandable.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdd2de3 and 2d61d96.

📒 Files selected for processing (1)
  • packages/router-core/tests/new-process-route-tree.test.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: nlynzaad
Repo: TanStack/router PR: 5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.
Learnt from: FatahChan
Repo: TanStack/router PR: 5475
File: e2e/react-start/basic-prerendering/src/routes/redirect/$target/via-beforeLoad.tsx:8-0
Timestamp: 2025-10-14T18:59:33.990Z
Learning: In TanStack Router e2e test files, when a route parameter is validated at the route level (e.g., using zod in validateSearch or param validation), switch statements on that parameter do not require a default case, as the validation ensures only expected values will reach the switch.
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad
Repo: TanStack/router PR: 5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.

Applied to files:

  • packages/router-core/tests/new-process-route-tree.test.ts
📚 Learning: 2025-10-14T18:59:33.990Z
Learnt from: FatahChan
Repo: TanStack/router PR: 5475
File: e2e/react-start/basic-prerendering/src/routes/redirect/$target/via-beforeLoad.tsx:8-0
Timestamp: 2025-10-14T18:59:33.990Z
Learning: In TanStack Router e2e test files, when a route parameter is validated at the route level (e.g., using zod in validateSearch or param validation), switch statements on that parameter do not require a default case, as the validation ensures only expected values will reach the switch.

Applied to files:

  • packages/router-core/tests/new-process-route-tree.test.ts
📚 Learning: 2025-09-28T21:41:45.233Z
Learnt from: nlynzaad
Repo: TanStack/router PR: 5284
File: e2e/react-start/basic/server.js:50-0
Timestamp: 2025-09-28T21:41:45.233Z
Learning: In Express v5, catch-all routes must use named wildcards. Use `/*splat` to match everything except root path, or `/{*splat}` (with braces) to match including root path. The old `*` syntax is not allowed and will cause "Missing parameter name" errors. This breaking change requires explicit naming of wildcard parameters.

Applied to files:

  • packages/router-core/tests/new-process-route-tree.test.ts
🧬 Code graph analysis (1)
packages/router-core/tests/new-process-route-tree.test.ts (1)
packages/router-core/src/new-process-route-tree.ts (4)
  • findRouteMatch (606-623)
  • processRouteTree (634-691)
  • processRouteMasks (545-562)
  • findFlatMatch (567-579)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview
🔇 Additional comments (3)
packages/router-core/tests/new-process-route-tree.test.ts (3)

2-7: LGTM! New imports are appropriate.

The new imports for findFlatMatch and processRouteMasks are correctly added to support the expanded test coverage.


200-225: Excellent edge case coverage for optional param matching.

These tests thoroughly verify the priority rules when optional params compete with dynamic params, ensuring that dynamic params are properly favored. The nested structure for testing optional params as standalone routes is clear and well-organized.


229-284: Comprehensive and well-structured trailing slash tests.

The systematic coverage of index route behavior across static, dynamic, and optional routes is excellent. The parallel structure across the three describe blocks makes the test suite easy to understand and maintain.

@Sheraff Sheraff merged commit 8994fc1 into main Nov 16, 2025
6 checks passed
@Sheraff Sheraff deleted the test-router-core-more-process-tree-tests branch November 16, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants