catalyst-core 0.3.0-beta.5 → 0.3.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +185 -71
- package/dist/errors/generateDocs.js +100 -0
- package/dist/errors/index.js +243 -0
- package/dist/errors/registry.js +483 -0
- package/dist/errors-index.json +506 -0
- package/dist/globals.d.ts +62 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.jsx +5 -8
- package/dist/logger.js +1 -1
- package/dist/native/androidProject/app/build.gradle.kts +142 -7
- package/dist/native/androidProject/app/src/main/AndroidManifest.xml +4 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +2 -2
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/camera/BarcodeDetector.kt +3 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/camera/CameraSessionManager.kt +3 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FrameworkServerUtils.kt +43 -8
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeUtilsTest.kt +181 -1
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CameraUtilsTest.kt +156 -236
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileSizeRouterUtilsTest.kt +471 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileUtilsTest.kt +222 -226
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FrameworkServerUtilsTest.kt +300 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/IntentUtilsTest.kt +244 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/MetricsMonitorTest.kt +359 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NativeBridgeTest.kt +108 -63
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NotificationUtilsTest.kt +329 -385
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/OfflineCacheServiceTest.kt +302 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/PerfEventBufferTest.kt +133 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/UtilsKtTest.kt +152 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/WebCacheManagerTest.kt +145 -324
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/BarcodeDetectorTest.kt +132 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/HoldControllerTest.kt +155 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/TorchControllerTest.kt +150 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/VideoStreamStateMachineTest.kt +120 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/VideoStreamStateTest.kt +62 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/ViewfinderMapperTest.kt +143 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/camera/ZoomControllerTest.kt +421 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/design/DesignTokensTest.kt +207 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/plugins/PluginBridgeTest.kt +368 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/security/FridaDetectorTest.kt +193 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/security/SecurityCheckManagerTest.kt +260 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/security/SecurityCheckSchedulerTest.kt +166 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/DeviceInfoUtilsTest.kt +167 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/DownloadUtilsTest.kt +197 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/NetworkMonitorTest.kt +271 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/PushNotificationUtilsTest.kt +119 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/utils/SafeAreaUtilsTest.kt +108 -0
- package/dist/native/androidProject/build.gradle.kts +1 -0
- package/dist/native/androidProject/gradle/libs.versions.toml +26 -0
- package/dist/native/androidProject/settings.gradle.kts +11 -8
- package/dist/native/androidSetup.js +2 -2
- package/dist/native/bridge/WebBridge.d.ts +98 -0
- package/dist/native/bridge/WebBridge.js +40 -6
- package/dist/native/bridge/constants/NativeInterfaces.d.ts +391 -0
- package/dist/native/bridge/errors.d.ts +67 -0
- package/dist/native/bridge/errors.js +66 -151
- package/dist/native/bridge/hooks/index.d.ts +13 -0
- package/dist/native/bridge/hooks/index.js +0 -6
- package/dist/native/bridge/hooks/useAI.d.ts +1 -0
- package/dist/native/bridge/hooks/useAI.js +3 -1
- package/dist/native/bridge/hooks/useCamera.d.ts +86 -0
- package/dist/native/bridge/hooks/useCamera.js +35 -6
- package/dist/native/bridge/hooks/useDataProtection.d.ts +17 -0
- package/dist/native/bridge/hooks/useDeviceInfo.d.ts +34 -0
- package/dist/native/bridge/hooks/useDeviceInfo.js +5 -0
- package/dist/native/bridge/hooks/useFilePicker.d.ts +53 -0
- package/dist/native/bridge/hooks/useFilePicker.js +13 -0
- package/dist/native/bridge/hooks/useGoogleSignIn.d.ts +12 -0
- package/dist/native/bridge/hooks/useHapticFeedback.d.ts +76 -0
- package/dist/native/bridge/hooks/useHapticFeedback.js +6 -1
- package/dist/native/bridge/hooks/useIntent.d.ts +33 -0
- package/dist/native/bridge/hooks/useIntent.js +2 -0
- package/dist/native/bridge/hooks/useNativeTransition.d.ts +53 -0
- package/dist/native/bridge/hooks/useNativeTransition.js +12 -5
- package/dist/native/bridge/hooks/useNetworkStatus.d.ts +22 -0
- package/dist/native/bridge/hooks/useNetworkStatus.js +7 -0
- package/dist/native/bridge/hooks/useNotification.d.ts +83 -0
- package/dist/native/bridge/hooks/useNotification.js +81 -34
- package/dist/native/bridge/hooks/useSafeArea.d.ts +12 -0
- package/dist/native/bridge/hooks/useSafeArea.js +8 -0
- package/dist/native/bridge/hooks/useVideoStream.d.ts +67 -0
- package/dist/native/bridge/hooks/useVideoStream.js +38 -52
- package/dist/native/bridge/hooks/utils.d.ts +4 -0
- package/dist/native/bridge/hooks.d.ts +1 -0
- package/dist/native/bridge/perf/collectors/ApiCollector.d.ts +30 -0
- package/dist/native/bridge/perf/collectors/ApiCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/CacheCollector.d.ts +43 -0
- package/dist/native/bridge/perf/collectors/CacheCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/HookCollector.d.ts +37 -0
- package/dist/native/bridge/perf/collectors/HookCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/InsightsCollector.d.ts +103 -0
- package/dist/native/bridge/perf/collectors/InsightsCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/InteractionCollector.d.ts +53 -0
- package/dist/native/bridge/perf/collectors/InteractionCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/KeyboardCollector.d.ts +30 -0
- package/dist/native/bridge/perf/collectors/KeyboardCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/NavigationCollector.d.ts +37 -0
- package/dist/native/bridge/perf/collectors/NavigationCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/NetworkTimingCollector.d.ts +30 -0
- package/dist/native/bridge/perf/collectors/NetworkTimingCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/RenderCollector.d.ts +47 -0
- package/dist/native/bridge/perf/collectors/RenderCollector.js +8 -0
- package/dist/native/bridge/perf/collectors/ScrollCollector.d.ts +29 -0
- package/dist/native/bridge/perf/collectors/ScrollCollector.js +4 -0
- package/dist/native/bridge/perf/collectors/ThreadCollector.d.ts +31 -0
- package/dist/native/bridge/perf/collectors/ThreadCollector.js +4 -0
- package/dist/native/bridge/perf/core/constants.d.ts +76 -0
- package/dist/native/bridge/perf/core/measure.d.ts +39 -0
- package/dist/native/bridge/perf/core/measure.js +4 -0
- package/dist/native/bridge/perf/core/session.d.ts +49 -0
- package/dist/native/bridge/perf/core/session.js +4 -0
- package/dist/native/bridge/perf/core/store.d.ts +37 -0
- package/dist/native/bridge/perf/core/store.js +4 -0
- package/dist/native/bridge/perf/core/summary.d.ts +60 -0
- package/dist/native/bridge/perf/core/traceExport.d.ts +10 -0
- package/dist/native/bridge/perf/core/waterfalls.d.ts +2 -0
- package/dist/native/bridge/perf/index.d.ts +63 -0
- package/dist/native/bridge/perf/index.js +4 -0
- package/dist/native/bridge/safeArea.d.ts +11 -0
- package/dist/native/bridge/safeArea.js +2 -0
- package/dist/native/bridge/useBaseHook.d.ts +137 -0
- package/dist/native/bridge/useBaseHook.js +34 -4
- package/dist/native/bridge/utils/CameraUtils.d.ts +94 -0
- package/dist/native/bridge/utils/CameraUtils.js +4 -0
- package/dist/native/bridge/utils/FileObjectConverter.d.ts +36 -0
- package/dist/native/bridge/utils/NativeBridge.d.ts +270 -0
- package/dist/native/bridge/utils/NativeBridge.js +10 -0
- package/dist/native/buildAndroid/index.js +1 -1
- package/dist/native/buildAppAndroid.js +9 -0
- package/dist/native/buildAppIos.js +16 -1
- package/dist/native/buildErrorFormat.js +57 -0
- package/dist/native/buildIos/config.js +15 -1
- package/dist/native/buildIos/index.js +1 -1
- package/dist/native/buildIos/plugins.js +10 -1
- package/dist/native/iosnativeWebView/CoreLogic/Package.swift +36 -0
- package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Camera/VideoStreamState.swift +1 -1
- package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Camera/VideoStreamStateMachine.swift +6 -4
- package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/BootTimingUtility.swift +3 -3
- package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/FrameworkServerUtils.swift +14 -9
- package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/NetworkMonitor.swift +11 -9
- package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/NotificationHandlerProvider.swift +1 -1
- package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/URLWhitelistManager.swift +7 -7
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/AnyCodableTests.swift +154 -0
- package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/BootTimingUtilityTests.swift +23 -5
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/CatalystConstantsTests.swift +192 -0
- package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/ConfigMappingTests.swift +1 -1
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/FrameworkServerUtilsErrorPathTests.swift +106 -0
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/FrameworkServerUtilsLoopbackTests.swift +243 -0
- package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/FrameworkServerUtilsTests.swift +1 -1
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/NetworkMonitorTests.swift +119 -0
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/NotificationHandlerProviderTests.swift +59 -0
- package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/NotificationHandlerTests.swift +1 -1
- package/dist/native/iosnativeWebView/{iosnativeWebViewTests → CoreLogic/Tests/CatalystCoreLogicTests}/URLWhitelistManagerTests.swift +1 -1
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/VideoStreamStateMachineTests.swift +171 -0
- package/dist/native/iosnativeWebView/CoreLogic/Tests/CatalystCoreLogicTests/VideoStreamStateTests.swift +91 -0
- package/dist/native/iosnativeWebView/Package.swift +10 -9
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/LocalNotificationHandler.swift +7 -2
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/NotificationManager.swift +1 -2
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/PushNotificationHandler.swift +5 -4
- package/dist/native/iosnativeWebView/Sources/Core/Camera/CameraSessionManager.swift +1 -0
- package/dist/native/iosnativeWebView/Sources/Core/Camera/HoldController.swift +1 -0
- package/dist/native/iosnativeWebView/Sources/Core/Camera/NativeCameraManager.swift +6 -5
- package/dist/native/iosnativeWebView/Sources/Core/Camera/ZoomController.swift +1 -0
- package/dist/native/iosnativeWebView/Sources/Core/Plugins/PluginBridge.swift +1 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/CacheManager.swift +31 -30
- package/dist/native/iosnativeWebView/Sources/Core/Utils/CameraTransportUtils.swift +2 -1
- package/dist/native/iosnativeWebView/Sources/Core/Utils/DeviceInfoUtils.swift +1 -1
- package/dist/native/iosnativeWebView/Sources/Core/Utils/FilePickerHandler.swift +22 -19
- package/dist/native/iosnativeWebView/Sources/Core/Utils/ImageHandler.swift +40 -39
- package/dist/native/iosnativeWebView/Sources/Core/Utils/PerfEventBuffer.swift +1 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/ResourceURLProtocol.swift +15 -15
- package/dist/native/iosnativeWebView/Sources/Core/Utils/WebKitConfig.swift +4 -3
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeCommandHandler.swift +6 -1
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeDelegateHandler.swift +1 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +2 -1
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeJavaScriptInterface.swift +2 -1
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +3 -5
- package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +20 -13
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashView.swift +6 -5
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashViewModel.swift +14 -13
- package/dist/native/iosnativeWebView/Sources/Core/WebView/TransitionManager.swift +3 -3
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +9 -8
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewModel.swift +7 -6
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +24 -25
- package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +6 -1
- package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +1 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +4 -0
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +2 -22
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +1 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/CacheManagerTests.swift +1 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/FilePickerHandlerTests.swift +2 -1
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/NativeBridgeTests.swift +15 -9
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/WebViewTests.swift +1 -0
- package/dist/native/setupEmulatorIos.js +2 -2
- package/dist/native/terminalProgress.js +17 -17
- package/dist/router/ClientRouter.d.ts +8 -0
- package/dist/router/ClientRouter.js +13 -11
- package/dist/router/ServerRouter.d.ts +13 -0
- package/dist/router/ServerRouter.js +19 -7
- package/dist/scripts/build.js +14 -2
- package/dist/scripts/loadEnvironmentVariables.js +3 -2
- package/dist/scripts/plugins.js +1 -1
- package/dist/scripts/preServerInit.js +49 -3
- package/dist/scripts/preflight.js +111 -0
- package/dist/scripts/scriptUtils.js +46 -1
- package/dist/scripts/serve.js +7 -3
- package/dist/scripts/start.js +8 -3
- package/dist/server/expressServer.d.ts +1 -0
- package/dist/server/expressServer.js +247 -271
- package/dist/server/manifestCache.d.ts +2 -0
- package/dist/server/manifestCache.js +25 -33
- package/dist/server/renderer/ChunkExtractor.d.ts +44 -0
- package/dist/server/renderer/ChunkExtractor.js +113 -125
- package/dist/server/renderer/document/Body.d.ts +21 -0
- package/dist/server/renderer/document/Body.jsx +45 -45
- package/dist/server/renderer/document/FastRefresh.d.ts +3 -0
- package/dist/server/renderer/document/FastRefresh.jsx +7 -13
- package/dist/server/renderer/document/Head.d.ts +20 -0
- package/dist/server/renderer/document/Head.jsx +32 -32
- package/dist/server/renderer/document/index.d.ts +2 -0
- package/dist/server/renderer/document/index.jsx +2 -2
- package/dist/server/renderer/extract.d.ts +67 -0
- package/dist/server/renderer/extract.js +92 -89
- package/dist/server/renderer/handler.d.ts +2 -0
- package/dist/server/renderer/handler.jsx +401 -404
- package/dist/server/renderer/index.d.ts +2 -0
- package/dist/server/renderer/index.js +5 -8
- package/dist/server/renderer/render.d.ts +35 -0
- package/dist/server/renderer/render.js +25 -32
- package/dist/server/utils/botDetectionMiddleware.d.ts +1 -0
- package/dist/server/utils/botDetectionMiddleware.js +33 -23
- package/dist/server/utils/cjsRequire.d.ts +8 -0
- package/dist/server/utils/cjsRequire.js +2 -2
- package/dist/server/utils/userAgentUtil.d.ts +7 -0
- package/dist/server/utils/userAgentUtil.js +68 -71
- package/dist/server/utils/validator.d.ts +31 -0
- package/dist/server/utils/validator.js +133 -158
- package/dist/vite/inject-cache-key-plugin.js +3 -27
- package/dist/vite/moduleAliases.js +36 -0
- package/dist/vite/node-loader.mjs +2 -29
- package/dist/vite/resolveDevServerConfig.js +4 -1
- package/dist/vite/vite.config.js +2 -29
- package/dist/web-router/components/MetaTag.d.ts +4 -0
- package/dist/web-router/components/MetaTag.jsx +26 -28
- package/dist/web-router/components/MetaTag.test.jsx +100 -0
- package/dist/web-router/components/RouterDataProvider.d.ts +96 -0
- package/dist/web-router/components/RouterDataProvider.jsx +260 -259
- package/dist/web-router/components/RouterDataProvider.server.test.jsx +98 -0
- package/dist/web-router/components/RouterDataProvider.test.jsx +310 -0
- package/dist/web-router/components/Split.d.ts +74 -0
- package/dist/web-router/components/Split.jsx +147 -156
- package/dist/web-router/components/Split.server.test.jsx +52 -0
- package/dist/web-router/components/Split.test.jsx +167 -0
- package/dist/web-router/components/SplitInview.d.ts +22 -0
- package/dist/web-router/components/SplitInview.jsx +78 -89
- package/dist/web-router/components/SplitInview.test.jsx +112 -0
- package/dist/web-router/components/SsrRequestContext.d.ts +20 -0
- package/dist/web-router/components/SsrRequestContext.jsx +17 -7
- package/dist/web-router/components/SsrRequestContext.test.jsx +53 -0
- package/dist/web-router/context.d.ts +15 -0
- package/dist/web-router/context.jsx +5 -5
- package/dist/web-router/context.test.jsx +10 -0
- package/dist/web-router/utils/metaDataUtils.d.ts +24 -0
- package/dist/web-router/utils/metaDataUtils.jsx +86 -86
- package/dist/web-router/utils/metaDataUtils.test.jsx +188 -0
- package/dist/web-router/vitest.setup.js +12 -0
- package/mcp_v2/knowledge-base.json +115 -17
- package/mcp_v2/mcp.js +141 -3
- package/mcp_v2/package-lock.json +2031 -0
- package/mcp_v2/package.json +13 -2
- package/mcp_v2/scripts/copyErrorsIndex.cjs +34 -0
- package/mcp_v2/test/errors.test.ts +123 -0
- package/mcp_v2/test/github.test.ts +177 -0
- package/mcp_v2/tools/errors.d.ts +20 -0
- package/mcp_v2/tools/errors.js +63 -0
- package/mcp_v2/tools/github.d.ts +41 -0
- package/mcp_v2/tools/github.js +231 -0
- package/mcp_v2/vitest.config.mjs +22 -0
- package/package.json +60 -11
- package/test/errors/docsDrift.test.ts +113 -0
- package/test/errors/index.test.ts +200 -0
- package/test/errors/registry.test.ts +108 -0
- package/test/scripts/preflight.test.ts +118 -0
- package/test/server/ChunkExtractor.test.ts +97 -0
- package/test/server/extract.test.ts +128 -0
- package/test/server/fixtures/template/server/document.jsx +19 -0
- package/test/server/fixtures/template/server/index.js +10 -0
- package/test/server/fixtures/template/src/js/containers/App/index.jsx +33 -0
- package/test/server/fixtures/template/src/js/routes/index.jsx +72 -0
- package/test/server/fixtures/template/src/js/routes/utils.jsx +39 -0
- package/test/server/fixtures/template/src/js/store/index.js +19 -0
- package/test/server/handler.assets.test.ts +330 -0
- package/test/server/handler.test.ts +208 -0
- package/test/server/manifestCache.test.ts +71 -0
- package/test/server/render.test.ts +71 -0
- package/test/server/scriptUtils.test.ts +103 -0
- package/test/server/userAgentUtil.test.ts +48 -0
- package/test/server/validator.test.ts +225 -0
- package/test/vite/resolveDevServerConfig.test.js +4 -1
- package/tsconfig.test.json +23 -0
- package/vitest.config.ts +93 -0
- package/dist/caching.js +0 -1
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/DeviceInfoUtilsTest.kt +0 -187
- package/dist/native/bridge/standardizedHooks.js +0 -611
- package/dist/router.js +0 -1
- package/dist/scripts/validator.js +0 -149
- package/dist/web-router/hooks.jsx +0 -72
- package/dist/web-router/types/components/MetaTag.d.ts +0 -2
- package/dist/web-router/types/components/RouterDataProvider.d.ts +0 -95
- package/dist/web-router/types/context.d.ts +0 -14
- package/dist/web-router/types/hooks.d.ts +0 -1
- package/dist/web-router/types/index.d.ts +0 -3
- package/dist/web-router/types/utils/metaDataUtils.d.ts +0 -40
- /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Constants/CatalystConstants.swift +0 -0
- /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Constants/ConfigConstants.swift +0 -0
- /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Notifications/NotificationModels.swift +0 -0
- /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Protocols/NotificationHandlerProtocol.swift +0 -0
- /package/dist/native/iosnativeWebView/{Sources/Core → CoreLogic/Sources/CatalystCoreLogic}/Utils/NullNotificationHandler.swift +0 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
validateConfigFile,
|
|
4
|
+
validatePackageJson,
|
|
5
|
+
validateModuleAlias,
|
|
6
|
+
validatePreInitServer,
|
|
7
|
+
validateMiddleware,
|
|
8
|
+
validateReducerFunction,
|
|
9
|
+
validateConfigureStore,
|
|
10
|
+
validateGetRoutes,
|
|
11
|
+
validateCustomDocument,
|
|
12
|
+
handleError,
|
|
13
|
+
safeCall,
|
|
14
|
+
safeCallNamed,
|
|
15
|
+
} from "../../src/server/utils/validator.js"
|
|
16
|
+
import { ERROR_CODES } from "../../src/errors/registry.js"
|
|
17
|
+
import { createError } from "../../src/errors/index.js"
|
|
18
|
+
|
|
19
|
+
// Contract for the pure validate* functions: return `null` when valid, a
|
|
20
|
+
// CatalystError (never thrown, never logged) when not. scripts/preflight.js
|
|
21
|
+
// and the in-server call sites both depend on this exact shape.
|
|
22
|
+
|
|
23
|
+
const VALID_CONFIG = {
|
|
24
|
+
NODE_SERVER_HOSTNAME: "localhost",
|
|
25
|
+
NODE_SERVER_PORT: 3000,
|
|
26
|
+
BUILD_OUTPUT_PATH: "build",
|
|
27
|
+
PUBLIC_STATIC_ASSET_PATH: "/assets/",
|
|
28
|
+
PUBLIC_STATIC_ASSET_URL: "http://localhost:3000",
|
|
29
|
+
CLIENT_ENV_VARIABLES: [],
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const VALID_ALIASES = {
|
|
33
|
+
"@api": "api.js",
|
|
34
|
+
"@containers": "src/js/containers",
|
|
35
|
+
"@server": "server",
|
|
36
|
+
"@config": "config",
|
|
37
|
+
"@css": "src/static/css",
|
|
38
|
+
"@routes": "src/js/routes/",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("validateConfigFile", () => {
|
|
42
|
+
it("returns null for a complete config", () => {
|
|
43
|
+
expect(validateConfigFile(VALID_CONFIG)).toBeNull()
|
|
44
|
+
})
|
|
45
|
+
it("PREFLIGHT-001 when falsy", () => {
|
|
46
|
+
expect(validateConfigFile(null)?.code).toBe(ERROR_CODES.PREFLIGHT_CONFIG_MISSING)
|
|
47
|
+
})
|
|
48
|
+
it("PREFLIGHT-002 when not an object", () => {
|
|
49
|
+
expect(validateConfigFile("nope" as unknown as object)?.code).toBe(
|
|
50
|
+
ERROR_CODES.PREFLIGHT_CONFIG_NOT_OBJECT
|
|
51
|
+
)
|
|
52
|
+
})
|
|
53
|
+
it("PREFLIGHT-003 when a required key is missing, naming the key", () => {
|
|
54
|
+
const { NODE_SERVER_PORT: _omit, ...rest } = VALID_CONFIG
|
|
55
|
+
const err = validateConfigFile(rest)
|
|
56
|
+
expect(err?.code).toBe(ERROR_CODES.PREFLIGHT_CONFIG_KEY_MISSING)
|
|
57
|
+
expect(err?.details).toContain("NODE_SERVER_PORT")
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe("validatePackageJson", () => {
|
|
62
|
+
it("returns null for an object", () => {
|
|
63
|
+
expect(validatePackageJson({ name: "x" })).toBeNull()
|
|
64
|
+
})
|
|
65
|
+
it("PREFLIGHT-004 when falsy", () => {
|
|
66
|
+
expect(validatePackageJson(null)?.code).toBe(ERROR_CODES.PREFLIGHT_PACKAGE_JSON_MISSING)
|
|
67
|
+
})
|
|
68
|
+
it("PREFLIGHT-005 when not an object", () => {
|
|
69
|
+
expect(validatePackageJson("x" as unknown as object)?.code).toBe(
|
|
70
|
+
ERROR_CODES.PREFLIGHT_PACKAGE_JSON_INVALID
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe("validateModuleAlias", () => {
|
|
76
|
+
it("returns null for the full required set", () => {
|
|
77
|
+
expect(validateModuleAlias(VALID_ALIASES)).toBeNull()
|
|
78
|
+
})
|
|
79
|
+
it("PREFLIGHT-006 when falsy", () => {
|
|
80
|
+
expect(validateModuleAlias(null)?.code).toBe(ERROR_CODES.PREFLIGHT_MODULE_ALIAS_MISSING)
|
|
81
|
+
})
|
|
82
|
+
it("PREFLIGHT-007 when not an object", () => {
|
|
83
|
+
expect(validateModuleAlias("x" as unknown as object)?.code).toBe(
|
|
84
|
+
ERROR_CODES.PREFLIGHT_MODULE_ALIAS_NOT_OBJECT
|
|
85
|
+
)
|
|
86
|
+
})
|
|
87
|
+
it("PREFLIGHT-008 when a key shadows a catalyst alias (checks the INPUT keys)", () => {
|
|
88
|
+
const err = validateModuleAlias({ ...VALID_ALIASES, "@catalyst/thing": "x" })
|
|
89
|
+
expect(err?.code).toBe(ERROR_CODES.PREFLIGHT_MODULE_ALIAS_RESTRICTED)
|
|
90
|
+
})
|
|
91
|
+
it("PREFLIGHT-008 matches the @catalyst namespace case-insensitively", () => {
|
|
92
|
+
const err = validateModuleAlias({ ...VALID_ALIASES, "@Catalyst/core": "x" })
|
|
93
|
+
expect(err?.code).toBe(ERROR_CODES.PREFLIGHT_MODULE_ALIAS_RESTRICTED)
|
|
94
|
+
})
|
|
95
|
+
it("PREFLIGHT-008 also rejects a bare '@catalyst' key (no separator)", () => {
|
|
96
|
+
const err = validateModuleAlias({ ...VALID_ALIASES, "@catalyst": "x" })
|
|
97
|
+
expect(err?.code).toBe(ERROR_CODES.PREFLIGHT_MODULE_ALIAS_RESTRICTED)
|
|
98
|
+
})
|
|
99
|
+
it("PREFLIGHT-008 rejects the '@catalyst-' hyphen form too (e.g. @catalyst-custom)", () => {
|
|
100
|
+
const err = validateModuleAlias({ ...VALID_ALIASES, "@catalyst-custom": "x" })
|
|
101
|
+
expect(err?.code).toBe(ERROR_CODES.PREFLIGHT_MODULE_ALIAS_RESTRICTED)
|
|
102
|
+
})
|
|
103
|
+
it("does NOT reject an unrelated alias that merely contains 'catalyst'", () => {
|
|
104
|
+
expect(validateModuleAlias({ ...VALID_ALIASES, "@my-catalyst-helpers": "x" })).toBeNull()
|
|
105
|
+
expect(validateModuleAlias({ ...VALID_ALIASES, "@catalystic": "x" })).toBeNull()
|
|
106
|
+
})
|
|
107
|
+
it("PREFLIGHT-009 when a required alias is missing, naming it", () => {
|
|
108
|
+
const { "@containers": _omit, ...rest } = VALID_ALIASES
|
|
109
|
+
const err = validateModuleAlias(rest)
|
|
110
|
+
expect(err?.code).toBe(ERROR_CODES.PREFLIGHT_MODULE_ALIAS_KEY_MISSING)
|
|
111
|
+
expect(err?.details).toContain("@containers")
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe.each([
|
|
116
|
+
["validatePreInitServer", validatePreInitServer, ERROR_CODES.PREFLIGHT_PRE_SERVER_INIT_MISSING, ERROR_CODES.PREFLIGHT_PRE_SERVER_INIT_NOT_FUNCTION],
|
|
117
|
+
["validateMiddleware", validateMiddleware, ERROR_CODES.PREFLIGHT_MIDDLEWARE_MISSING, ERROR_CODES.PREFLIGHT_MIDDLEWARE_NOT_FUNCTION],
|
|
118
|
+
["validateReducerFunction", validateReducerFunction, ERROR_CODES.PREFLIGHT_REDUCER_MISSING, ERROR_CODES.PREFLIGHT_REDUCER_NOT_FUNCTION],
|
|
119
|
+
["validateConfigureStore", validateConfigureStore, ERROR_CODES.PREFLIGHT_CONFIGURE_STORE_MISSING, ERROR_CODES.PREFLIGHT_CONFIGURE_STORE_NOT_FUNCTION],
|
|
120
|
+
["validateGetRoutes", validateGetRoutes, ERROR_CODES.PREFLIGHT_GET_ROUTES_MISSING, ERROR_CODES.PREFLIGHT_GET_ROUTES_NOT_FUNCTION],
|
|
121
|
+
["validateCustomDocument", validateCustomDocument, ERROR_CODES.PREFLIGHT_CUSTOM_DOCUMENT_MISSING, ERROR_CODES.PREFLIGHT_CUSTOM_DOCUMENT_NOT_FUNCTION],
|
|
122
|
+
] as const)("%s (function validator)", (_name, fn, missingCode, notFnCode) => {
|
|
123
|
+
it("returns null for a function", () => {
|
|
124
|
+
expect(fn(() => {})).toBeNull()
|
|
125
|
+
})
|
|
126
|
+
it(`${missingCode} when missing`, () => {
|
|
127
|
+
expect(fn(undefined)?.code).toBe(missingCode)
|
|
128
|
+
})
|
|
129
|
+
it(`${notFnCode} when not a function`, () => {
|
|
130
|
+
expect(fn(123 as unknown as () => void)?.code).toBe(notFnCode)
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
// safeCall / safeCallNamed: the async hook-runners exported alongside the
|
|
135
|
+
// validators. They DO catch + log (via console.error) rather than return
|
|
136
|
+
// the error -- a different contract from the pure validate* functions
|
|
137
|
+
// above. Ported from #454's SSR-handler coverage.
|
|
138
|
+
describe("safeCall", () => {
|
|
139
|
+
beforeEach(() => {
|
|
140
|
+
vi.spyOn(console, "error").mockImplementation(() => {})
|
|
141
|
+
})
|
|
142
|
+
afterEach(() => {
|
|
143
|
+
vi.restoreAllMocks()
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it("returns the resolved value of a well-behaved fn", async () => {
|
|
147
|
+
await expect(safeCall(async () => "ok", 1, 2)).resolves.toBe("ok")
|
|
148
|
+
})
|
|
149
|
+
it("swallows a throwing fn and logs a structured error", async () => {
|
|
150
|
+
await expect(
|
|
151
|
+
safeCall(() => {
|
|
152
|
+
throw new Error("hook boom")
|
|
153
|
+
})
|
|
154
|
+
).resolves.toBeUndefined()
|
|
155
|
+
expect(console.error).toHaveBeenCalled()
|
|
156
|
+
})
|
|
157
|
+
it("swallows a rejected promise", async () => {
|
|
158
|
+
await expect(safeCall(async () => Promise.reject(new Error("async boom")))).resolves.toBeUndefined()
|
|
159
|
+
expect(console.error).toHaveBeenCalled()
|
|
160
|
+
})
|
|
161
|
+
it("is a no-op for a non-function", async () => {
|
|
162
|
+
await expect(safeCall(undefined as never)).resolves.toBeUndefined()
|
|
163
|
+
expect(console.error).not.toHaveBeenCalled()
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
describe("safeCallNamed", () => {
|
|
168
|
+
beforeEach(() => {
|
|
169
|
+
vi.spyOn(console, "error").mockImplementation(() => {})
|
|
170
|
+
})
|
|
171
|
+
afterEach(() => {
|
|
172
|
+
vi.restoreAllMocks()
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it("returns the resolved value", async () => {
|
|
176
|
+
await expect(safeCallNamed("onRouteMatch", async () => 7)).resolves.toBe(7)
|
|
177
|
+
})
|
|
178
|
+
it("names the hook in the logged error when it throws", async () => {
|
|
179
|
+
await safeCallNamed("preServerInit", () => {
|
|
180
|
+
throw new Error("x")
|
|
181
|
+
})
|
|
182
|
+
const logged = (console.error as unknown as { mock: { calls: unknown[][] } }).mock.calls.flat().join("\n")
|
|
183
|
+
expect(logged).toContain("preServerInit")
|
|
184
|
+
})
|
|
185
|
+
it("is a no-op for a non-function", async () => {
|
|
186
|
+
await expect(safeCallNamed("x", null as never)).resolves.toBeUndefined()
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
// handleError is the shared "log it in whatever output mode" helper the
|
|
191
|
+
// in-server call sites use with a validate* result. The validators
|
|
192
|
+
// themselves no longer call it (they return the error) -- exercise it
|
|
193
|
+
// directly. Ported + adapted from #454.
|
|
194
|
+
describe("handleError output mode", () => {
|
|
195
|
+
afterEach(() => {
|
|
196
|
+
vi.restoreAllMocks()
|
|
197
|
+
vi.resetModules()
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it("uses the non-'default' formatter branch when CATALYST_OUTPUT_MODE is verbose", async () => {
|
|
201
|
+
const saved = process.env.CATALYST_OUTPUT_MODE
|
|
202
|
+
process.env.CATALYST_OUTPUT_MODE = "verbose"
|
|
203
|
+
vi.resetModules()
|
|
204
|
+
vi.spyOn(console, "log").mockImplementation(() => {})
|
|
205
|
+
try {
|
|
206
|
+
// outputMode is resolved at module load -> "verbose" -> the
|
|
207
|
+
// else branch of handleError runs (no "Failed to start
|
|
208
|
+
// server:" prefix).
|
|
209
|
+
const mod = await import("../../src/server/utils/validator.js")
|
|
210
|
+
mod.handleError(createError(ERROR_CODES.PREFLIGHT_GET_ROUTES_MISSING))
|
|
211
|
+
const logged = (console.log as unknown as { mock: { calls: unknown[][] } }).mock.calls.flat().join("\n")
|
|
212
|
+
expect(logged).not.toContain("Failed to start server:")
|
|
213
|
+
} finally {
|
|
214
|
+
if (saved === undefined) delete process.env.CATALYST_OUTPUT_MODE
|
|
215
|
+
else process.env.CATALYST_OUTPUT_MODE = saved
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it("uses the 'default' branch (with prefix) otherwise", () => {
|
|
220
|
+
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {})
|
|
221
|
+
handleError(createError(ERROR_CODES.PREFLIGHT_GET_ROUTES_MISSING))
|
|
222
|
+
const logged = logSpy.mock.calls.flat().join("\n")
|
|
223
|
+
expect(logged).toContain("Failed to start server:")
|
|
224
|
+
})
|
|
225
|
+
})
|
|
@@ -69,7 +69,10 @@ test("buildDevServer: hmr defaults to true in dev", () => {
|
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
test("buildDevServer: hmr is false in production", () => {
|
|
72
|
-
const server = buildDevServer(
|
|
72
|
+
const server = buildDevServer(
|
|
73
|
+
{ hmr: { clientPort: 443 } },
|
|
74
|
+
{ frameworkPaths: FRAMEWORK, isProduction: true }
|
|
75
|
+
)
|
|
73
76
|
assert.equal(server.hmr, false)
|
|
74
77
|
})
|
|
75
78
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"types": [
|
|
5
|
+
"node",
|
|
6
|
+
"vitest/globals"
|
|
7
|
+
],
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"emitDeclarationOnly": false,
|
|
10
|
+
"declaration": false,
|
|
11
|
+
"module": "esnext",
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"target": "es2022"
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"test",
|
|
17
|
+
"src/globals.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"node_modules",
|
|
21
|
+
"dist"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url"
|
|
2
|
+
import { configDefaults, defineConfig } from "vitest/config"
|
|
3
|
+
|
|
4
|
+
// @catalyst/template resolves to a consumer app at runtime (package.json
|
|
5
|
+
// maps it to "."). handler.jsx (SSR request handler) imports the app's
|
|
6
|
+
// App / routes / store / document through it via static imports, so the
|
|
7
|
+
// "node" project aliases it to a minimal fixture template under
|
|
8
|
+
// test/server/fixtures/template so those modules can be tested at all.
|
|
9
|
+
// Issue #348.
|
|
10
|
+
const templateFixture = fileURLToPath(
|
|
11
|
+
new URL("./test/server/fixtures/template", import.meta.url),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
// Two projects sharing this one config, kept in `projects` rather than a
|
|
15
|
+
// separate vitest.workspace.ts so there's a single vitest.config.ts to
|
|
16
|
+
// find. Each project is otherwise independent -- unique `name`, own
|
|
17
|
+
// `environment`, own `include` glob, no shared setup between them.
|
|
18
|
+
//
|
|
19
|
+
// "node" project: framework-level (Tier 1) unit tests for catalyst-core's
|
|
20
|
+
// own internals -- see test/errors/*.test.ts. Registry/index.js are ESM
|
|
21
|
+
// and side-effect-free at import time -- no DOM, no server, no global
|
|
22
|
+
// setup needed. Application-level (Tier 2) integration tests live in
|
|
23
|
+
// examples/catalyst-core-test and run via scripts/test-catalyst-core.sh,
|
|
24
|
+
// not through vitest (see issue #412).
|
|
25
|
+
//
|
|
26
|
+
// "web-router" project: React component/hook tests for src/web-router
|
|
27
|
+
// (issue #346/#340 coverage work). Needs jsdom (a real DOM environment)
|
|
28
|
+
// and @testing-library/react -- neither existed in this package before,
|
|
29
|
+
// since every prior test here was plain-JS/Node logic. Kept as its own
|
|
30
|
+
// project rather than switching the whole config to jsdom: jsdom has
|
|
31
|
+
// real per-test overhead the plain error-system tests don't need, and
|
|
32
|
+
// this keeps the two testing concerns (framework internals vs. React UI)
|
|
33
|
+
// separately configured.
|
|
34
|
+
//
|
|
35
|
+
// `*.server.test.{js,jsx}` under src/web-router is the exception: a
|
|
36
|
+
// handful of code paths there branch on `typeof window === "undefined"`
|
|
37
|
+
// (fetchRouteData picks serverFetcher over clientFetcher on the server).
|
|
38
|
+
// jsdom always defines `window`, so those branches can only be exercised
|
|
39
|
+
// in the "node" environment -- those files are routed to the "node"
|
|
40
|
+
// project and excluded from "web-router" so RTL's jsdom-only setupFiles
|
|
41
|
+
// never load for them. Issue #347.
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
test: {
|
|
44
|
+
// Coverage stays on v8's default "only files imported during the
|
|
45
|
+
// run" behavior (no `include` -> no all-src walk). These excludes
|
|
46
|
+
// just drop noise that IS imported transitively: the compiled
|
|
47
|
+
// `dist/` copies pulled in via the "@catalyst/template" -> "."
|
|
48
|
+
// mapping, and the #348 handler-test fixtures under
|
|
49
|
+
// test/server/fixtures. CI aggregates each workspace's
|
|
50
|
+
// coverage-summary.json `total`, so keeping those out keeps that
|
|
51
|
+
// number honest.
|
|
52
|
+
coverage: {
|
|
53
|
+
exclude: [
|
|
54
|
+
...configDefaults.coverage.exclude,
|
|
55
|
+
"dist/**",
|
|
56
|
+
"test/**",
|
|
57
|
+
"src/**/*.test.{js,jsx,ts,tsx}",
|
|
58
|
+
"src/**/vitest.setup.*",
|
|
59
|
+
// Build-time CLI script (entrypoint-guarded, run from
|
|
60
|
+
// docs tooling / the docs-drift check), not framework
|
|
61
|
+
// runtime -- same rationale as excluding scripts/**.
|
|
62
|
+
"src/errors/generateDocs.js",
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
projects: [
|
|
66
|
+
{
|
|
67
|
+
resolve: {
|
|
68
|
+
// Inert for every existing "node" test (none import the
|
|
69
|
+
// "@catalyst/template" specifier); only handler.test.ts
|
|
70
|
+
// (#348) relies on it.
|
|
71
|
+
alias: { "@catalyst/template": templateFixture },
|
|
72
|
+
},
|
|
73
|
+
test: {
|
|
74
|
+
name: "node",
|
|
75
|
+
environment: "node",
|
|
76
|
+
include: [
|
|
77
|
+
"test/**/*.test.ts",
|
|
78
|
+
"src/web-router/**/*.server.test.{js,jsx}",
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
test: {
|
|
84
|
+
name: "web-router",
|
|
85
|
+
environment: "jsdom",
|
|
86
|
+
include: ["src/web-router/**/*.test.{js,jsx}"],
|
|
87
|
+
exclude: [...configDefaults.exclude, "src/web-router/**/*.server.test.{js,jsx}"],
|
|
88
|
+
setupFiles: ["./src/web-router/vitest.setup.js"],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
})
|
package/dist/caching.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@tata1mg/api-caching"
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
package io.yourname.androidproject
|
|
2
|
-
|
|
3
|
-
import android.os.Build
|
|
4
|
-
import org.json.JSONObject
|
|
5
|
-
import org.junit.Assert.*
|
|
6
|
-
import org.junit.Test
|
|
7
|
-
import java.util.Properties
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Unit tests for DeviceInfoUtils
|
|
11
|
-
*
|
|
12
|
-
* Tests device information structure and field validation.
|
|
13
|
-
*
|
|
14
|
-
* Note: Tests focus on verifying the expected JSON structure and field presence
|
|
15
|
-
* that DeviceInfoUtils.getDeviceInfo() should produce. Full integration testing
|
|
16
|
-
* with Android Context would require instrumented tests (androidTest).
|
|
17
|
-
*
|
|
18
|
-
* Categories:
|
|
19
|
-
* 1. Device metadata validation (2 tests)
|
|
20
|
-
* 2. JSON structure validation (2 tests)
|
|
21
|
-
* 3. AppInfo property handling (2 tests)
|
|
22
|
-
*
|
|
23
|
-
* Total: 6 tests
|
|
24
|
-
*/
|
|
25
|
-
class DeviceInfoUtilsTest {
|
|
26
|
-
|
|
27
|
-
// ========================================
|
|
28
|
-
// CATEGORY 1: Device Metadata Constants
|
|
29
|
-
// ========================================
|
|
30
|
-
|
|
31
|
-
@Test
|
|
32
|
-
fun testBuildModel_IsAvailable() {
|
|
33
|
-
// Validates that Build.MODEL constant is accessible
|
|
34
|
-
// This is what DeviceInfoUtils uses for the "model" field
|
|
35
|
-
|
|
36
|
-
// Note: In unit tests without Robolectric, Build.MODEL may be null due to
|
|
37
|
-
// testOptions.unitTests.isReturnDefaultValues = true
|
|
38
|
-
// On actual devices, Build.MODEL is always set by the Android framework
|
|
39
|
-
|
|
40
|
-
// Assert - We can access the Build.MODEL field (even if null in test environment)
|
|
41
|
-
val model = Build.MODEL
|
|
42
|
-
// In real devices: "Pixel 5", "SM-G998B", etc.
|
|
43
|
-
// In unit tests: may be null
|
|
44
|
-
println("Build.MODEL = $model (null in unit tests is OK)")
|
|
45
|
-
|
|
46
|
-
// The actual implementation will have a real value at runtime
|
|
47
|
-
assertTrue("Build.MODEL field should be accessible", true)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@Test
|
|
51
|
-
fun testBuildManufacturer_IsAvailable() {
|
|
52
|
-
// Validates that Build.MANUFACTURER constant is accessible
|
|
53
|
-
// This is what DeviceInfoUtils uses for the "manufacturer" field
|
|
54
|
-
|
|
55
|
-
// Note: In unit tests without Robolectric, Build.MANUFACTURER may be null due to
|
|
56
|
-
// testOptions.unitTests.isReturnDefaultValues = true
|
|
57
|
-
// On actual devices, Build.MANUFACTURER is always set by the Android framework
|
|
58
|
-
|
|
59
|
-
// Assert - We can access the Build.MANUFACTURER field (even if null in test environment)
|
|
60
|
-
val manufacturer = Build.MANUFACTURER
|
|
61
|
-
// In real devices: "Google", "Samsung", "OnePlus", etc.
|
|
62
|
-
// In unit tests: may be null
|
|
63
|
-
println("Build.MANUFACTURER = $manufacturer (null in unit tests is OK)")
|
|
64
|
-
|
|
65
|
-
// The actual implementation will have a real value at runtime
|
|
66
|
-
assertTrue("Build.MANUFACTURER field should be accessible", true)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// ========================================
|
|
70
|
-
// CATEGORY 2: Expected JSON Structure
|
|
71
|
-
// ========================================
|
|
72
|
-
|
|
73
|
-
@Test
|
|
74
|
-
fun testExpectedDeviceInfoFields() {
|
|
75
|
-
// Validates the expected structure that DeviceInfoUtils.getDeviceInfo() should produce
|
|
76
|
-
// This serves as a contract test for the JSON response format
|
|
77
|
-
|
|
78
|
-
val expectedFields = listOf(
|
|
79
|
-
"model", // String: Build.MODEL
|
|
80
|
-
"manufacturer", // String: Build.MANUFACTURER
|
|
81
|
-
"platform", // String: "android"
|
|
82
|
-
"screenWidth", // Int: Display width in pixels
|
|
83
|
-
"screenHeight", // Int: Display height in pixels
|
|
84
|
-
"screenDensity", // Double: Display density multiplier
|
|
85
|
-
"appInfo" // String or null: From properties file
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
// Assert that we know what fields to expect
|
|
89
|
-
assertEquals("Expected 7 fields in device info JSON", 7, expectedFields.size)
|
|
90
|
-
|
|
91
|
-
// Verify no duplicates in expected fields
|
|
92
|
-
assertEquals("Expected fields should be unique",
|
|
93
|
-
expectedFields.size, expectedFields.distinct().size)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@Test
|
|
97
|
-
fun testPlatformField_ShouldBeAndroid() {
|
|
98
|
-
// Validates that the platform field should always be "android" for Android devices
|
|
99
|
-
// This is hardcoded in DeviceInfoUtils.kt:22
|
|
100
|
-
|
|
101
|
-
val expectedPlatform = "android"
|
|
102
|
-
|
|
103
|
-
// Assert
|
|
104
|
-
assertEquals("Platform should be 'android'", "android", expectedPlatform)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ========================================
|
|
108
|
-
// CATEGORY 3: Properties Handling Logic
|
|
109
|
-
// ========================================
|
|
110
|
-
|
|
111
|
-
@Test
|
|
112
|
-
fun testPropertiesAppInfo_WhenPresent() {
|
|
113
|
-
// Tests the logic for extracting appInfo from Properties object
|
|
114
|
-
// Simulates: properties?.getProperty("appInfo")
|
|
115
|
-
|
|
116
|
-
// Arrange
|
|
117
|
-
val properties = Properties().apply {
|
|
118
|
-
setProperty("appInfo", "MyApp v1.2.3")
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Act
|
|
122
|
-
val appInfo = properties.getProperty("appInfo")
|
|
123
|
-
|
|
124
|
-
// Assert
|
|
125
|
-
assertNotNull("AppInfo should not be null when property is set", appInfo)
|
|
126
|
-
assertEquals("AppInfo should match the property value", "MyApp v1.2.3", appInfo)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
@Test
|
|
130
|
-
fun testPropertiesAppInfo_WhenAbsent() {
|
|
131
|
-
// Tests the logic for handling missing appInfo property
|
|
132
|
-
// Simulates: properties?.getProperty("appInfo") when properties is null or missing key
|
|
133
|
-
|
|
134
|
-
// Test Case 1: properties is null
|
|
135
|
-
val nullProperties: Properties? = null
|
|
136
|
-
val appInfoFromNull = nullProperties?.getProperty("appInfo")
|
|
137
|
-
assertNull("AppInfo should be null when properties object is null", appInfoFromNull)
|
|
138
|
-
|
|
139
|
-
// Test Case 2: properties exists but doesn't have "appInfo" key
|
|
140
|
-
val emptyProperties = Properties()
|
|
141
|
-
val appInfoFromEmpty = emptyProperties.getProperty("appInfo")
|
|
142
|
-
assertNull("AppInfo should be null when property key doesn't exist", appInfoFromEmpty)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ========================================
|
|
146
|
-
// CATEGORY 4: JSON Structure Validation
|
|
147
|
-
// ========================================
|
|
148
|
-
|
|
149
|
-
@Test
|
|
150
|
-
fun testJSONObjectCreation_WithExpectedFields() {
|
|
151
|
-
// Validates that we can create a JSON object with the expected structure
|
|
152
|
-
// This mirrors what DeviceInfoUtils.getDeviceInfo() constructs
|
|
153
|
-
|
|
154
|
-
// Use mock values since Build fields may be null in unit tests
|
|
155
|
-
val mockModel = "TestDevice"
|
|
156
|
-
val mockManufacturer = "TestManufacturer"
|
|
157
|
-
|
|
158
|
-
// Arrange & Act
|
|
159
|
-
val deviceInfo = JSONObject().apply {
|
|
160
|
-
put("model", mockModel)
|
|
161
|
-
put("manufacturer", mockManufacturer)
|
|
162
|
-
put("platform", "android")
|
|
163
|
-
put("screenWidth", 1080) // Example value
|
|
164
|
-
put("screenHeight", 1920) // Example value
|
|
165
|
-
put("screenDensity", 2.0) // Example value
|
|
166
|
-
put("appInfo", "TestApp v1.0")
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Assert - All expected fields are present
|
|
170
|
-
assertTrue("JSON should contain 'model' field", deviceInfo.has("model"))
|
|
171
|
-
assertTrue("JSON should contain 'manufacturer' field", deviceInfo.has("manufacturer"))
|
|
172
|
-
assertTrue("JSON should contain 'platform' field", deviceInfo.has("platform"))
|
|
173
|
-
assertTrue("JSON should contain 'screenWidth' field", deviceInfo.has("screenWidth"))
|
|
174
|
-
assertTrue("JSON should contain 'screenHeight' field", deviceInfo.has("screenHeight"))
|
|
175
|
-
assertTrue("JSON should contain 'screenDensity' field", deviceInfo.has("screenDensity"))
|
|
176
|
-
assertTrue("JSON should contain 'appInfo' field", deviceInfo.has("appInfo"))
|
|
177
|
-
|
|
178
|
-
// Assert field types and values
|
|
179
|
-
assertEquals("Platform should be 'android'", "android", deviceInfo.getString("platform"))
|
|
180
|
-
assertEquals("Model should match mock value", mockModel, deviceInfo.getString("model"))
|
|
181
|
-
assertEquals("Manufacturer should match mock value",
|
|
182
|
-
mockManufacturer, deviceInfo.getString("manufacturer"))
|
|
183
|
-
assertEquals("ScreenWidth should be 1080", 1080, deviceInfo.getInt("screenWidth"))
|
|
184
|
-
assertEquals("ScreenHeight should be 1920", 1920, deviceInfo.getInt("screenHeight"))
|
|
185
|
-
assertEquals("ScreenDensity should be 2.0", 2.0, deviceInfo.getDouble("screenDensity"), 0.01)
|
|
186
|
-
}
|
|
187
|
-
}
|