Skip to content

Conversation

@panteliselef
Copy link
Member

@panteliselef panteliselef commented Oct 21, 2025

Description

fixes nightly e2e tests. This seems to be working due to turbopack now being utilized by default.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage to validate middleware placement across different Next.js versions, including version 16+.
    • Improved test assertions to properly handle version-specific behavior differences.

@panteliselef panteliselef requested review from a team October 21, 2025 21:42
@panteliselef panteliselef self-assigned this Oct 21, 2025
@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

⚠️ No Changeset found

Latest commit: 30274f5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Oct 24, 2025 6:19am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

Walkthrough

The test file introduces utility functions to detect Next.js version and dynamically adjust test execution. Tests conditionally skip or modify assertions based on Next.js major version, with specific handling for Next 16+ compatibility.

Changes

Cohort / File(s) Summary
Version-aware test utilities
integration/tests/middleware-placement.test.ts
Added parseSemverMajor() and detectNext() helper functions to parse semantic versions and detect Next.js version; imported path, stateFile, and fs modules to support detection logic. Integrated version detection into existing tests with conditional skip logic and version-specific test blocks for Next 16+ behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through versions with glee, 🐰
Testing Next's middleware, wild and free,
Sixteen and onward, the logic now sees,
Conditional skips make the tests all agree! ✨

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
Title Check ✅ Passed The pull request title "fix(e2e): Align middleware detection test cases for next@16" directly aligns with the main changes in the changeset. The raw summary shows that the primary modification is updating test logic in middleware-placement.test.ts to handle Next.js v16 differences, including introducing version detection helpers and conditionally adjusting test assertions based on the Next.js major version. The title clearly and specifically captures this intent using conventional commit format with the "fix(e2e)" prefix and specific scope. The language is concise, avoids vagueness, and provides sufficient context for a teammate to understand the primary change when scanning commit history.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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 elef/fix-nightly-tests

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

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: 1

🧹 Nitpick comments (2)
integration/tests/middleware-placement.test.ts (2)

10-16: Consider adding JSDoc and potentially more robust semver parsing.

While the current regex /\d+/ works for common cases, it's quite simplistic. For a test helper, this is acceptable, but consider:

  1. Adding a JSDoc comment to clarify the function's purpose and limitations.
  2. If you need more robust semver parsing in the future, consider using a dedicated library like semver.

The current implementation is sufficient for detecting major versions from typical npm version ranges.


91-93: Optional: Consider extracting version detection to reduce duplication.

Both tests in this describe block call detectNext(app) and parse the major version. You could extract this to a variable in the beforeAll hook for slight optimization and DRY principle:

let nextMajorVersion: number;

test.beforeAll(async () => {
  // ... existing setup ...
  const { version } = await detectNext(app);
  nextMajorVersion = parseSemverMajor(version) ?? 0;
});

However, the current approach is more explicit and easier to read in test code, so this is purely optional.

Also applies to: 103-110

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 911ccbb and 220ed8c.

📒 Files selected for processing (1)
  • integration/tests/middleware-placement.test.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • integration/tests/middleware-placement.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • integration/tests/middleware-placement.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • integration/tests/middleware-placement.test.ts
integration/**

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

Framework integration templates and E2E tests should be placed under the integration/ directory

Files:

  • integration/tests/middleware-placement.test.ts
integration/**/*

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

End-to-end tests and integration templates must be located in the 'integration/' directory.

Files:

  • integration/tests/middleware-placement.test.ts
integration/**/*.{test,spec}.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Integration tests should use Playwright.

Files:

  • integration/tests/middleware-placement.test.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • integration/tests/middleware-placement.test.ts
🧬 Code graph analysis (1)
integration/tests/middleware-placement.test.ts (3)
integration/models/application.ts (1)
  • Application (7-7)
integration/models/stateFile.ts (1)
  • stateFile (103-103)
integration/testUtils/index.ts (1)
  • createTestUtils (24-86)
⏰ 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). (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
integration/tests/middleware-placement.test.ts (3)

2-2: LGTM!

The new imports are necessary for the Next.js version detection helpers.

Also applies to: 5-5, 7-7


91-93: Good approach to version-specific test skipping.

The conditional skip logic correctly handles Next.js version differences. The ?? 0 fallback ensures that if the version cannot be detected, the test runs (assumes pre-16 behavior).


103-110: LGTM! Complementary test case for Next 16+ behavior.

This test correctly validates that Next.js 16+ does not show the misplaced middleware error, complementing the pre-16 test above. The conditional skip and assertion logic are sound.

Comment on lines +18 to +32
async function detectNext(app: Application): Promise<{ isNext: boolean; version?: string }> {
// app.appDir exists for normal Application; for long-running apps, read it from the state file by serverUrl
const appDir =
(app as any).appDir ||
Object.values(stateFile.getLongRunningApps() || {}).find(a => a.serverUrl === app.serverUrl)?.appDir;

if (!appDir) {
return { isNext: false };
}

const pkg = await fs.readJSON(path.join(appDir, 'package.json'));
const nextRange: string | undefined = pkg.dependencies?.next || pkg.devDependencies?.next;

return { isNext: Boolean(nextRange), version: nextRange };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add error handling and avoid any type cast.

The function has two concerns:

  1. Line 21: Using (app as any).appDir violates the coding guideline to avoid any types. Consider:

    • Adding appDir to the Application type if it's a valid property
    • Using a type guard or checking if the property exists with proper typing
    • Using as unknown as { appDir?: string } as a safer intermediate cast
  2. Line 28: fs.readJSON() has no error handling. If package.json is missing or malformed, the test will fail with an unclear error. Consider wrapping in try-catch and returning { isNext: false } on error.

Apply this diff to improve error handling:

 async function detectNext(app: Application): Promise<{ isNext: boolean; version?: string }> {
   // app.appDir exists for normal Application; for long-running apps, read it from the state file by serverUrl
   const appDir =
     (app as any).appDir ||
     Object.values(stateFile.getLongRunningApps() || {}).find(a => a.serverUrl === app.serverUrl)?.appDir;
 
   if (!appDir) {
     return { isNext: false };
   }
 
+  try {
     const pkg = await fs.readJSON(path.join(appDir, 'package.json'));
     const nextRange: string | undefined = pkg.dependencies?.next || pkg.devDependencies?.next;
 
     return { isNext: Boolean(nextRange), version: nextRange };
+  } catch {
+    return { isNext: false };
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async function detectNext(app: Application): Promise<{ isNext: boolean; version?: string }> {
// app.appDir exists for normal Application; for long-running apps, read it from the state file by serverUrl
const appDir =
(app as any).appDir ||
Object.values(stateFile.getLongRunningApps() || {}).find(a => a.serverUrl === app.serverUrl)?.appDir;
if (!appDir) {
return { isNext: false };
}
const pkg = await fs.readJSON(path.join(appDir, 'package.json'));
const nextRange: string | undefined = pkg.dependencies?.next || pkg.devDependencies?.next;
return { isNext: Boolean(nextRange), version: nextRange };
}
async function detectNext(app: Application): Promise<{ isNext: boolean; version?: string }> {
// app.appDir exists for normal Application; for long-running apps, read it from the state file by serverUrl
const appDir =
(app as any).appDir ||
Object.values(stateFile.getLongRunningApps() || {}).find(a => a.serverUrl === app.serverUrl)?.appDir;
if (!appDir) {
return { isNext: false };
}
try {
const pkg = await fs.readJSON(path.join(appDir, 'package.json'));
const nextRange: string | undefined = pkg.dependencies?.next || pkg.devDependencies?.next;
return { isNext: Boolean(nextRange), version: nextRange };
} catch {
return { isNext: false };
}
}
🤖 Prompt for AI Agents
In integration/tests/middleware-placement.test.ts around lines 18 to 32, avoid
the unsafe (app as any).appDir cast and add error handling for fs.readJSON():
replace the any cast by either extending the Application type to include
optional appDir or use a narrow type-guard/safer intermediate cast (e.g. as
unknown as { appDir?: string }) before reading appDir, then wrap the
fs.readJSON(path.join(appDir, 'package.json')) call in a try-catch and return {
isNext: false } if reading/parsing fails so missing or malformed package.json
doesn’t crash the test.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 22, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7047

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7047

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7047

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7047

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7047

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7047

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@7047

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@7047

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7047

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7047

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7047

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7047

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7047

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7047

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@7047

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7047

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@7047

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7047

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7047

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7047

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@7047

@clerk/types

npm i https://pkg.pr.new/@clerk/types@7047

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7047

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7047

commit: 30274f5

@panteliselef panteliselef merged commit d1a186c into main Oct 24, 2025
45 checks passed
@panteliselef panteliselef deleted the elef/fix-nightly-tests branch October 24, 2025 14:57
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.

4 participants