Skip to content

Comments

Fix tests with vitest for Vite#31

Merged
technologic-technologic merged 4 commits into26-migrate-app-from-cra-to-vitefrom
28-fix-tests-with-vitest
Oct 15, 2025
Merged

Fix tests with vitest for Vite#31
technologic-technologic merged 4 commits into26-migrate-app-from-cra-to-vitefrom
28-fix-tests-with-vitest

Conversation

@technologic-technologic
Copy link
Owner

Testing working again
Testing fixed after the migration from CRA to Vite.
For this fix was necessary to strengthen the contexts and all the components that make contact with the Api <- Refactored these files.
Added test script to package to allow npm to run the tests.

Key changes

  • Fixes InventoryTablePageSelector.test.tsx, InventoryTable.test.tsx, NewProductButton.test.tsx, ProductForm.test.tsx.
  • Updated DataContext.test.tsx, SearchContext.test.tsx
  • Refactored for the new context management:
    • InventoryTable.tsx,
    • InventoryTableObj.tsx,
    • InventoryTablePageSelector.tsx
    • EncoraContent.tsx

Breaking or pending changes

  • SearchBar component testing is still pending
  • Update documentation to the new version

More info below

Fixed the bug where multiple calls to the backend where made for no reason

## Key changes
- Updated DataProvider
- Added exposed component to interact with the one and only DataContext context.
Upgraded the testing configuration to be compatible with vitest new variables, and avoid problems in the future.

## Key changes
- Updated gitignore to avoid constantly modifying package lock
- Commiting for the last time package-lock changes
- Added test parameters in app config to allow smooth testing
- Added jsdom dependency to devDependencies
-Added globals to frame config to allow testing, easier.

Signed-off-by: Leonardo Trevizo <leonardo.trevizo@encora.com>
Added two more testing files to test the context, to make testing more robust.

## Key changes
- Created DataContext.test.tsx
- Created SearchContext.test.tsx

Signed-off-by: Leonardo Trevizo <leonardo.trevizo@encora.com>
Testing fixed after the migration from CRA to Vite.
For this fix was necessary to strengthen the contexts and all the components that make contact with the Api <- Refactored these files.
Added test script to package to allow npm to run the tests.

## Key changes
- Fixes InventoryTablePageSelector.test.tsx, InventoryTable.test.tsx, NewProductButton.test.tsx, ProductForm.test.tsx.
- Updated DataContext.test.tsx, SearchContext.test.tsx
- Refactored for the new context management:
   - InventoryTable.tsx,
   - InventoryTableObj.tsx,
   - InventoryTablePageSelector.tsx
   - EncoraContent.tsx

## Breaking or pending changes
- SearchBar component testing is still pending
- Update documentation to the new version

Signed-off-by: Leonardo Trevizo <leonardo.trevizo@encora.com>
@github-actions
Copy link

PR Summary

WHAT Changed

  • Updated Dependencies: Added @testing-library/user-event and jsdom to package-lock.json and package.json.
  • Modified .gitignore: Added package-lock.json to be ignored.
  • Refactored Component Imports: Adjusted import paths for InventoryTableObj and InventoryTablePageSelector.
  • Enhanced InputSearch Component: Added debouncing to the search input to reduce unnecessary state updates.
  • Updated Tests: Refactored tests for NewProductButton and ProductForm to use vitest and @testing-library/jest-dom.
  • Removed InventoryTable Tests: Deleted the InventoryTable.test.tsx file.
  • New Tests: Added new tests for InventoryTable and InventoryTablePageSelector.
  • Refactored DataContext: Introduced useDataContext for better state management and error handling.

WHY It Matters

  • Improved Performance: Debouncing in the search input enhances user experience by reducing the number of state updates.
  • Updated Testing Framework: Transitioning to vitest and @testing-library/jest-dom improves testing capabilities and compatibility.
  • Cleaner Codebase: Refactoring and organizing imports and components lead to better maintainability.

RISKS

  • Dependency Compatibility: New dependencies may introduce breaking changes or compatibility issues.
  • Refactored Tests: Changes in test structure may lead to missed edge cases if not thoroughly validated.

TESTS to Add

  • Ensure that all new and modified components have corresponding tests.
  • Validate the debouncing functionality in the InputSearch component.
  • Test the integration of the new useDataContext with existing components.

BREAKING CHANGES

  • Refactored Imports: Changes in import paths may require updates in other components that rely on the previous structure.
  • Removed Tests: Deleting the InventoryTable.test.tsx file may lead to gaps in coverage for that component.

Changed File Paths

  • inventory-manager/.gitignore
  • inventory-manager/package-lock.json
  • inventory-manager/package.json
  • inventory-manager/src/components/page-content/EncoraContent.tsx
  • inventory-manager/src/components/page-content/segment1-search_product/input-bars/InputSearch.tsx
  • inventory-manager/src/components/page-content/segment2-new_product/NewProductButton.test.tsx
  • inventory-manager/src/components/page-content/segment2-new_product/ProductForm.test.tsx
  • inventory-manager/src/components/page-content/segment3-table/InventoryTable.test.tsx (deleted)
  • inventory-manager/src/components/page-content/segment3-table/InventoryTable.tsx
  • inventory-manager/src/components/page-content/segment3-table/segment/InventoryTableObj.tsx
  • inventory-manager/src/components/page-content/segment3-table/segment/InventoryTablePageSelector.tsx
  • inventory-manager/src/context/DataContext.tsx
  • inventory-manager/src/context/DataContext.test.tsx
  • inventory-manager/src/context/SearchContext.test.tsx
  • inventory-manager/tsconfig.app.json
  • inventory-manager/vite.config.ts

@technologic-technologic technologic-technologic merged commit ba2db4d into 26-migrate-app-from-cra-to-vite Oct 15, 2025
1 check passed
@technologic-technologic technologic-technologic linked an issue Oct 15, 2025 that may be closed by this pull request
@technologic-technologic technologic-technologic deleted the 28-fix-tests-with-vitest branch October 15, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix and update tests to work with Vitest

1 participant