forked from cardosofelipe/pragma-stack
Refactor to enforce AuthContext usage over useAuthStore and improve test stability
- Replaced `useAuthStore` with `useAuth` from `AuthContext` across frontend components and tests to ensure dependency injection compliance. - Enhanced E2E test stability by delaying navigation until the auth context is fully initialized. - Updated Playwright configuration to use a single worker to prevent mock conflicts. - Refactored test setup to consistently inject `AuthProvider` for improved isolation and mocking. - Adjusted comments and documentation to clarify dependency injection and testability patterns.
This commit is contained in:
@@ -24,6 +24,21 @@ const eslintConfig = [
|
||||
"**/*.gen.tsx",
|
||||
],
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
// Enforce Dependency Injection pattern for auth store
|
||||
// Components/hooks must use useAuth() from AuthContext, not useAuthStore directly
|
||||
// This ensures testability via DI (E2E mocks, unit test props)
|
||||
// Exception: Non-React contexts (client.ts) use dynamic import + __TEST_AUTH_STORE__ check
|
||||
"no-restricted-imports": ["error", {
|
||||
"patterns": [{
|
||||
"group": ["**/stores/authStore"],
|
||||
"importNames": ["useAuthStore"],
|
||||
"message": "Import useAuth from '@/lib/auth/AuthContext' instead. Direct authStore imports bypass dependency injection and break test mocking."
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export default eslintConfig;
|
||||
|
||||
Reference in New Issue
Block a user