fix: reduce pbkdf iteration in tests to prevent timeout nad keep them fast

This commit is contained in:
ramvignesh-b
2026-04-30 05:25:55 +05:30
parent 2bb77d1bed
commit b6f45aa93c
3 changed files with 9 additions and 7 deletions
+5 -6
View File
@@ -1,12 +1,10 @@
import { lazy, Suspense, useEffect } from "react"; import { lazy, Suspense, useEffect, useRef } from "react";
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom"; import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import { ProtectedRoute, PublicRoute } from "./components/RouteGuards"; import { ProtectedRoute, PublicRoute } from "./components/RouteGuards";
import SplashScreen from "./components/SplashScreen"; import SplashScreen from "./components/SplashScreen";
import { ROUTES } from "./config/routes"; import { ROUTES } from "./config/routes";
import { useAuth } from "./hooks/useAuth"; import { useAuth } from "./hooks/useAuth";
let authInitialized = false;
const Activate = lazy(() => import("./pages/Activate")); const Activate = lazy(() => import("./pages/Activate"));
const Drawer = lazy(() => import("./pages/Drawer")); const Drawer = lazy(() => import("./pages/Drawer"));
const Editor = lazy(() => import("./pages/Editor")); const Editor = lazy(() => import("./pages/Editor"));
@@ -18,11 +16,12 @@ const VerifyEmail = lazy(() => import("./pages/VerifyEmail"));
export default function App() { export default function App() {
const { initialize, isInitializing } = useAuth(); const { initialize, isInitializing } = useAuth();
const authInitialized = useRef<boolean>(false);
useEffect(() => { useEffect(() => {
if (authInitialized) return; if (authInitialized.current) return;
authInitialized = true; authInitialized.current = true;
initialize(); initialize().then();
}, [initialize]); }, [initialize]);
if (isInitializing) { if (isInitializing) {
+2 -1
View File
@@ -26,7 +26,8 @@ interface SealedEnvelope {
// TODO: try refactoring into a pure function for consistency // TODO: try refactoring into a pure function for consistency
export class CryptoUtils { export class CryptoUtils {
private dek!: CryptoKey; private dek!: CryptoKey;
private static readonly PBKDF2_ITERATIONS = 600_000; private static readonly PBKDF2_ITERATIONS =
Number(import.meta.env.VITE_PBKDF2_ITERATIONS) || 600_000;
// NOTE: https://www.w3.org/TR/webcrypto/#aes-gcm // NOTE: https://www.w3.org/TR/webcrypto/#aes-gcm
private static readonly AES_ALGO = { name: "AES-GCM", length: 256 }; private static readonly AES_ALGO = { name: "AES-GCM", length: 256 };
private static readonly IV_BYTE_LENGTH = 12; private static readonly IV_BYTE_LENGTH = 12;
+2
View File
@@ -9,6 +9,8 @@ export default defineConfig({
env: { env: {
VITE_API_URL: "http://piku-server", VITE_API_URL: "http://piku-server",
TZ: "Asia/Kolkata", TZ: "Asia/Kolkata",
// using the actual 600_000 iterations causes timeout in tests
VITE_PBKDF2_ITERATIONS: "1",
}, },
include: ["**/*.test.ts", "**/*.test.tsx"], include: ["**/*.test.ts", "**/*.test.tsx"],
environment: "jsdom", environment: "jsdom",