-
Task
-
Resolution: Done
-
Normal
-
None
-
None
-
Future Sustainability
-
5
-
False
-
-
False
-
None
-
Unset
-
None
-
-
-
HCC Framework Sprint 52
-
Problem Statement
The Data Driven Forms monorepo currently uses an ad-hoc Jest configuration that is not properly structured for NX workspaces. To successfully migrate to TypeScript (Epic RHCLOUD-44570), we need to modernize the Jest test infrastructure to provide reliable test coverage validation throughout the migration process.
Current State
- Complex, non-standard Jest configuration that doesn't follow NX workspace patterns
- Jest v27 with limited TypeScript support
- Inconsistent test environments causing timezone and DOM-related failures
- Test API compatibility issues with updated testing libraries
- No centralized test configuration across packages
Requirements
Jest Configuration Modernization
- Migrate to NX workspace Jest patterns using getJestProjectsAsync() for package auto-discovery
- Create centralized jest.preset.js extending @nx/jest/preset for consistent configuration
- Add individual Jest configuration files for each package following NX best practices
- Remove ad-hoc Jest configuration and test scripts from individual package.json files
TypeScript Integration Setup
- Update Jest to v29 for better TypeScript support
- Integrate ts-jest for proper TypeScript compilation during testing
- Create tsconfig.spec.json for test-specific TypeScript configuration
- Ensure Jest can handle both JavaScript and TypeScript files during migration transition
Test Environment Consistency
- Fix JSDOM setup for reliable React component testing
- Update testing libraries (@testing-library/react, @testing-library/user-event) for compatibility
- Configure consistent UTC timezone to eliminate environment-specific date/time test failures
- Resolve DOM globals and browser API mocking
Test API Compatibility
- Address breaking changes in @testing-library/user-event API (v13+ compatibility)
- Fix keyboard modifier handling in tests (Ctrl+click, Shift+click interactions)
- Resolve timing issues in conditional field value setting tests
- Ensure all existing tests pass without modifying expected behavior or test data
Acceptance Criteria
- All test suites must pass across all component mapper packages:
- @data-driven-forms/react-form-renderer
- @data-driven-forms/carbon-component-mapper
- @data-driven-forms/mui-component-mapper
- @data-driven-forms/blueprint-component-mapper
- @data-driven-forms/pf4-component-mapper
- @data-driven-forms/ant-component-mapper
- @data-driven-forms/common
- Jest configuration follows NX workspace best practices
- TypeScript compilation and type checking work in test environment
- Consistent test environment eliminates flaky timezone/environment-dependent tests
- No regressions in existing test coverage or functionality
- Test infrastructure supports seamless TypeScript migration process
Technical Approach
File Structure Target
├── jest.config.js # Root configuration using getJestProjectsAsync() ├── jest.preset.js # Centralized preset for all packages ├── config/ │ ├── jest.setup.js # Global test setup │ └── globalSetup.js # Global Jest setup (timezone, etc.) ├── tsconfig.spec.json # TypeScript config for tests └── packages/ └── */jest.config.ts # Individual package configurations
Key Configuration Features Needed
- NX workspace integration with build system and caching
- TypeScript support with full compilation and type checking
- Consistent environment (UTC timezone, JSDOM setup, React testing utilities)
- Proper module mapping for local packages and assets
- Centralized coverage reporting across all packages