Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/setup/nuxt-auth-session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { registerEndpoint } from '@nuxt/test-utils/runtime'

// The @thecodeorigin/auth module ships an async boot plugin (`0.session`) that
// fetches `/api/_auth/session`, plus a global route middleware that redirects
// unauthenticated users to the (external) sign-in URL. During `setupNuxt()` the
// app's initial navigation (`/` → `/dashboard`) would trigger that external
// redirect, which never resolves in the test env and hangs the setup hook.
//
// Registering a logged-in session here makes the boot plugin resolve to an
// authenticated admin, so the middleware lets navigation through and the app
// boots cleanly. `systemRole: 'admin'` grants `manage all` via the ability
// plugin, so ability-gated components/pages render in tests.
//
// Some files in the nuxt project opt out via `// @vitest-environment happy-dom`,
// where the test-utils runtime app (`window.__app`) is absent — skip there.
if (typeof window !== 'undefined' && '__app' in window) {
registerEndpoint('/api/_auth/session', () => ({
user: {
id: 'test-user',
email: 'test@example.com',
name: 'Test User',
},
systemRole: 'admin',
abilities: [],
impersonator: null,
organizations: [],
}))
}
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default defineConfig({
},
},
hookTimeout: 120000,
setupFiles: ['./test/setup/nuxt-auth-session.ts'],
},
}),
],
Expand Down
Loading