Skip to content

fix(test): unblock nuxt-env setupNuxt hang via session fixture#91

Open
imrim12 wants to merge 1 commit into
mainfrom
fix/nuxt-test-setupnuxt-hang
Open

fix(test): unblock nuxt-env setupNuxt hang via session fixture#91
imrim12 wants to merge 1 commit into
mainfrom
fix/nuxt-test-setupnuxt-hang

Conversation

@imrim12

@imrim12 imrim12 commented Jun 29, 2026

Copy link
Copy Markdown
Member

Problem

CI has been red across many commits. Two failures, in sequence:

  1. TypecheckteardownTimeout placed inside a per-project test config (only valid at the top-level test config). (Already addressed in 635775a.)
  2. Tests (the real blocker) — all 4 nuxt-env test files (cookie-consent, sidebar-search, notifications-bell, support-modal) hung in the beforeAll setupNuxt() hook and timed out at 120s.

Root cause

Regression introduced by c54f2f8 (better-auth → @thecodeorigin/auth module swap), exactly when CI went red.

setupNuxt() boots the real Nuxt app and runs all plugins + initial route resolution. The module's global middleware auth.global.js redirects unauthenticated users to an external sign-in URL. With no session in the test env, the boot navigation //dashboard triggered navigateTo(signIn, { external: true }), which never resolves under @nuxt/test-utils → the hook hung for the full timeout. Verified: even a no-op nuxt-env test and an isolated single file hang past 600s, while the build itself completes.

Fix

Register a logged-in /api/_auth/session fixture as a setup file for the nuxt vitest project. The auth boot plugin resolves to an authenticated admin, so the middleware lets navigation through and the app boots in ~14s. Guarded to skip files that opt into // @vitest-environment happy-dom (no test-utils runtime app).

Verification (local)

  • pnpm test24 files / 126 tests passed (was 4 hanging + 5 skipped)
  • pnpm lint → clean
  • pnpm typecheck → clean

🤖 Generated with Claude Code

The @thecodeorigin/auth module ships a global route middleware that
redirects unauthenticated users to an external sign-in URL. During
`setupNuxt()` the app's boot navigation (`/` -> `/dashboard`) triggered
that external redirect, which never resolves in the @nuxt/test-utils
runtime env and hung the beforeAll hook for the full timeout. Every
nuxt-env test file (cookie-consent, sidebar-search, notifications-bell,
support-modal) timed out at 120s.

Register a logged-in `/api/_auth/session` fixture for the nuxt project so
the auth boot plugin resolves to an authenticated admin and the middleware
lets navigation through. The app now boots in ~14s. Guarded so files that
opt into `happy-dom` (no test-utils runtime app) skip registration.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant