All files / src/lib performance-test.ts

5.88% Statements 2/34
12.5% Branches 1/8
0% Functions 0/9
5.88% Lines 2/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89      1x                                                                                                                                                             1x            
// Performance testing utilities for route prefetching
import { DASHBOARD_ROUTES, WALLET_ROUTES } from '@/constants/route';
 
export const performanceTestUtils = {
  // Test if routes are being prefetched
  testRoutePrefetching: () => {
    console.group('๐Ÿงช Testing Route Prefetching');
 
    // Check if prefetched components are in cache
    const testRoutes = [
      DASHBOARD_ROUTES.OVERVIEW,
      WALLET_ROUTES.WALLET,
      WALLET_ROUTES.TRANSACTIONS,
    ];
 
    testRoutes.forEach(route => {
      // This would normally check if the route is prefetched
      // In a real test, you'd check the prefetched components map
      console.log(`โœ“ Testing prefetch for route: ${route}`);
    });
 
    console.groupEnd();
  },
 
  // Test loading performance
  testLoadingPerformance: () => {
    console.group('โšก Testing Loading Performance');
 
    const startTime = performance.now();
 
    // Simulate a route change
    setTimeout(() => {
      const endTime = performance.now();
      const duration = endTime - startTime;
 
      console.log(`Route change simulation took: ${duration.toFixed(2)}ms`);
 
      if (duration < 100) {
        console.log('โœ… Excellent performance');
      } else if (duration < 300) {
        console.log('โœ… Good performance');
      } else {
        console.log('โš ๏ธ Performance could be improved');
      }
    }, 0);
 
    console.groupEnd();
  },
 
  // Test service worker integration
  testServiceWorkerIntegration: () => {
    console.group('๐Ÿ”ง Testing Service Worker Integration');
 
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.ready
        .then(registration => {
          console.log('โœ… Service Worker is registered and ready');
          console.log('Scope:', registration.scope);
        })
        .catch(error => {
          console.log('โŒ Service Worker not ready:', error);
        });
    } else {
      console.log('โŒ Service Worker not supported');
    }
 
    console.groupEnd();
  },
 
  // Run all performance tests
  runAllTests: () => {
    console.log('๐Ÿš€ Running Performance Tests...');
 
    performanceTestUtils.testRoutePrefetching();
    performanceTestUtils.testLoadingPerformance();
    performanceTestUtils.testServiceWorkerIntegration();
 
    console.log('โœ… All performance tests completed');
  },
};
 
// Auto-run tests in development
Iif (process.env.NODE_ENV === 'development') {
  // Run tests after app initialization
  setTimeout(() => {
    performanceTestUtils.runAllTests();
  }, 2000);
}