rusackas opened a new pull request, #35305: URL: https://github.com/apache/superset/pull/35305
## Summary This PR implements a comprehensive migration strategy to move away from nested `describe`/`it` test patterns to flat `test()` functions, following [Kent C. Dodds' "avoid nesting when testing"](https://kentcdodds.com/blog/avoid-nesting-when-youre-testing) best practices. ## Changes ### 1. ESLint Rules Enforcement - Added `jest/consistent-test-it` rule to enforce `test` over `it` - Added `no-restricted-globals` rule to error on `describe` and `it` usage - Configured in `superset-frontend/src/.eslintrc.json` ### 2. Automated Migrations - **Auto-migrated all `it` to `test`**: 194 files updated via `npm run lint-fix` - **Flattened simple describe blocks**: 5 files with no hooks or complex setup safely migrated ### 3. Legacy Code Handling - Added `eslint-disable` comments with TODO markers to 243 files containing `describe` blocks - Marked 1,080 existing `describe` blocks with: `// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks` - This allows existing code to work while preventing new usage ## Migration Statistics - **Total test files**: 482 - **`it` → `test` migration**: 100% complete (194 files) - **`describe` blocks removed**: 5 files (simple cases without hooks) - **`describe` blocks with TODOs**: 243 files (to be migrated gradually) - **Files with hooks requiring manual migration**: 198 ## Files Successfully Flattened These files had simple `describe` blocks without hooks and were safely migrated: - `utils/urlUtils.test.ts` - `explore/controlPanels/Separator.test.ts` - `components/ErrorMessage/ErrorAlert.test.tsx` - `components/ModalTitleWithIcon/ModalTitleWithIcon.test.tsx` - `components/MessageToasts/reducers.test.js` ## Benefits 1. **Enforces modern patterns**: New tests cannot use `describe`/`it` (ESLint error) 2. **Preserves functionality**: All existing tests continue to work 3. **Clear technical debt**: TODO markers make legacy patterns visible 4. **Gradual migration path**: Files can be updated as they're touched 5. **Better test readability**: Flat structure is easier to understand and maintain ## Testing Instructions 1. Run tests to confirm everything still passes: ```bash npm run test ``` 2. Try adding a new `describe` block - it should trigger an ESLint error: ```javascript describe('NewComponent', () => { // ❌ ESLint error test('works', () => {}); }); ``` 3. New tests should use flat structure: ```javascript test('NewComponent works', () => { // ✅ Correct pattern // test implementation }); ``` ## Additional Information This migration follows React Testing Library and Jest best practices. The flat test structure: - Reduces nesting complexity - Makes test names more descriptive - Eliminates confusion about hook scopes - Improves test maintainability The TODO markers allow us to track and gradually migrate the remaining `describe` blocks without breaking existing tests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
