[PR #29881] perf: improve Jest caching and configuration in web tests #32598

Closed
opened 2026-02-21 20:51:43 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/29881

State: closed
Merged: Yes


Performance: CI Test Improvements & Test Reliability Enhancements

Overview

This PR significantly improves web frontend test performance and reliability while maintaining comprehensive test coverage. The changes focus on CI optimization, test stability improvements, and enhanced error handling.

Key Changes

🚀 CI Performance Improvements

  • Jest Caching: Added persistent Jest cache layer (web/.cache/jest) to speed up test execution
  • Parallel Testing: Replaced --runInBand with --maxWorkers=100% to utilize all available CPU cores
  • Cache Strategy: Configured proper cache keying based on OS and dependency lock file
  • Expected Impact: ~60-80% reduction in CI test execution time

🧪 Test Reliability Enhancements

  • Headless UI Mocks: Added targeted mocks for @headlessui/react in concurrent test environments
  • Race Condition Fix: Synchronized rendering for Popover/Menu/Dialog components to prevent timing issues
  • Targeted Approach: Mocks applied only to affected test files, preserving integration test integrity
  • Preserved Logic: Mock implementations maintain conditional rendering and accessibility attributes

📝 Test Suite Improvements

  • Enhanced Error Testing: Improved error handling coverage in EditAnnotationModal tests
  • Toast Notifications: Added proper error toast verification for API failure scenarios
  • User Experience: Tested error message display and user feedback mechanisms
  • API Contract Testing: Verified proper error propagation and fallback behavior

🔧 Component Refinements

  • EditAnnotationModal: Enhanced error handling with proper try-catch blocks and user feedback
  • Internationalization: Added missing success/error message translations across 21 languages
  • Type Safety: Improved type definitions for annotation-related components

Technical Details

Mock Implementation Strategy

// Applied locally to prevent CI race conditions
// Preserves conditional rendering: if (!context?.open) return null
// Maintains accessibility: role="dialog", aria-expanded
// Avoids global __mocks__/ directory to keep real component tests

Files Modified

  • CI/CD: .github/workflows/web-tests.yml, web/jest.config.ts
  • Test Files: Enhanced 4 test suites with better coverage and reliability
  • Components: Improved error handling in annotation editing workflow
  • i18n: Added missing translations for error/success messages

Testing Strategy

  • All existing tests continue to pass
  • New tests cover edge cases and error scenarios
  • Performance optimizations maintain test quality
  • Mocks are minimal and targeted

Impact

  • CI Speed: Significantly faster test execution
  • Reliability: Eliminated flaky tests due to timing issues
  • Coverage: Improved error handling test coverage
  • Maintainability: Clear documentation for future developers
**Original Pull Request:** https://github.com/langgenius/dify/pull/29881 **State:** closed **Merged:** Yes --- # Performance: CI Test Improvements & Test Reliability Enhancements ## Overview This PR significantly improves web frontend test performance and reliability while maintaining comprehensive test coverage. The changes focus on CI optimization, test stability improvements, and enhanced error handling. ## Key Changes ### 🚀 CI Performance Improvements - **Jest Caching**: Added persistent Jest cache layer (`web/.cache/jest`) to speed up test execution - **Parallel Testing**: Replaced `--runInBand` with `--maxWorkers=100%` to utilize all available CPU cores - **Cache Strategy**: Configured proper cache keying based on OS and dependency lock file - **Expected Impact**: ~60-80% reduction in CI test execution time ### 🧪 Test Reliability Enhancements - **Headless UI Mocks**: Added targeted mocks for `@headlessui/react` in concurrent test environments - **Race Condition Fix**: Synchronized rendering for Popover/Menu/Dialog components to prevent timing issues - **Targeted Approach**: Mocks applied only to affected test files, preserving integration test integrity - **Preserved Logic**: Mock implementations maintain conditional rendering and accessibility attributes ### 📝 Test Suite Improvements - **Enhanced Error Testing**: Improved error handling coverage in EditAnnotationModal tests - **Toast Notifications**: Added proper error toast verification for API failure scenarios - **User Experience**: Tested error message display and user feedback mechanisms - **API Contract Testing**: Verified proper error propagation and fallback behavior ### 🔧 Component Refinements - **EditAnnotationModal**: Enhanced error handling with proper try-catch blocks and user feedback - **Internationalization**: Added missing success/error message translations across 21 languages - **Type Safety**: Improved type definitions for annotation-related components ## Technical Details ### Mock Implementation Strategy ```typescript // Applied locally to prevent CI race conditions // Preserves conditional rendering: if (!context?.open) return null // Maintains accessibility: role="dialog", aria-expanded // Avoids global __mocks__/ directory to keep real component tests ``` ### Files Modified - **CI/CD**: `.github/workflows/web-tests.yml`, `web/jest.config.ts` - **Test Files**: Enhanced 4 test suites with better coverage and reliability - **Components**: Improved error handling in annotation editing workflow - **i18n**: Added missing translations for error/success messages ## Testing Strategy - ✅ All existing tests continue to pass - ✅ New tests cover edge cases and error scenarios - ✅ Performance optimizations maintain test quality - ✅ Mocks are minimal and targeted ## Impact - **CI Speed**: Significantly faster test execution - **Reliability**: Eliminated flaky tests due to timing issues - **Coverage**: Improved error handling test coverage - **Maintainability**: Clear documentation for future developers
yindo added the pull-request label 2026-02-21 20:51:43 -05:00
yindo closed this issue 2026-02-21 20:51:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32598