Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: setup base for unit testing using vitest #531

Merged
merged 31 commits into from
Feb 7, 2025

Conversation

cswni
Copy link
Contributor

@cswni cswni commented Feb 7, 2025

This pull request introduces testing capabilities and coverage reporting to the project, along with some minor refactoring and dependency updates. The most important changes include adding testing libraries and configurations, updating the package.json with new scripts and dependencies, and creating a test file for the modal component.

Testing and Coverage:

  • Added testing libraries and configurations in package.json, including vitest, @testing-library/react, and @testing-library/jest-dom. [1] [2] [3] [4] [5]
  • Updated vite.config.ts to include test configurations with vitest and coverage provider v8. [1] [2]
  • Created setupTest.ts to extend expect with matchers from @testing-library/jest-dom.

Script Updates:

  • Modified package.json to add new scripts for running tests and generating coverage reports.
  • Updated .github/workflows/ci.yml to run tests with coverage during the CI process.

Component Testing:

  • Created a test file src/components/test/modal.test.tsx for the Modal component, including multiple test cases.

Minor Changes:

  • Exported ModalProps interface in src/components/modal.tsx.
  • Updated an icon in src/sections/user/profile-transfer.tsx.
  • Added type definitions for testing libraries in tsconfig.app.json.

geolffreym and others added 10 commits February 6, 2025 08:41
- **vite.config.ts**: Added Vitest configuration for testing, global enabled, jsdom environment, setup file, and coverage provider set to v8.
- **tsconfig.json & tsconfig.app.json**: Included Vitest and Testing Library types for type-checking.
- **package.json**: Added Vitest scripts (`test` and `test:coverage`), along with dependencies for Vitest, Testing Library, and related tooling.
- **setupTest.ts**: Added setup file to extend `expect` with Testing Library matchers.
- Added `modal.test.tsx` with tests to validate Modal behavior:
  - Ensures component matches the snapshot.
  - Confirms the title is displayed when `open` is true.
  - Verifies the title is absent when `open` is false.
- Created a snapshot file `modal.test.tsx.snap`.
- Exported `ModalProps` in `modal.tsx` to enable type usage in tests.
- Removed direct import of '@testing-library/jest-dom'.
- Updated to use matchers from '@testing-library/jest-dom/matchers'.
- Ensures consistency in imports and aligns with testing setup best practices.
- Removed unused `MemoryRouter` from `modal.test.tsx`.
- Updated snapshot-related test case to use `baseElement` for clarity.
- Added new test cases:
  - Verify modal content rendering.
  - Verify `onClose` prop is called when modal is closed.
- Revised and improved existing test case descriptions for readability.
- Deleted stale snapshot file `modal.test.tsx.snap`.
- Replace "make test" with "npm run test" in `.github/workflows/ci.yml`.
- Ensures consistency by aligning the test task with npm scripts.
- Improves clarity and uniformity in the CI process.
- Updated `.github/workflows/ci.yml`:
  - Modified the "Test" step to include coverage by running `npm run test -- --coverage`.
@cswni cswni added the test label Feb 7, 2025
@cswni cswni requested review from geolffreym and Jadapema February 7, 2025 06:28
@cswni cswni self-assigned this Feb 7, 2025
cswni added 4 commits February 7, 2025 00:36
- Created a new snapshot file `modal.test.tsx.snap` under `src/components/test/__snapshots__`.
- Captures the rendered structure of the modal component to ensure consistent UI updates.
- Updated `.github/workflows/ci.yml`:
  - Added a step to cache Node.js dependencies using `actions/cache@v4`.
  - Configured cache key based on `package-lock.json` hash for efficient reuse.
This change aims to speed up CI runs and reduce redundant package installations.
- Updated the test command in `.github/workflows/ci.yml` to include the `--silent` flag for cleaner output.
- Commented out the "Generate report" step to disable its execution for now.
- Deleted the "Cache Node dependencies" step in `.github/workflows/ci.yml`.
- Rationale: Simplifies the workflow as caching is not necessary for the current setup.
```
@cswni
Copy link
Contributor Author

cswni commented Feb 7, 2025

@geolffreym
We can send the coverage report to codecov.io but i need the app installed in repo app context.

Review and evaluate.

geolffreym and others added 10 commits February 7, 2025 08:01
# Conflicts:
#	.github/workflows/ci.yml
- Updated `.github/workflows/ci.yml` to include the `--coverage` flag when running tests.
- This ensures test coverage data is generated and can be uploaded to Codecov for better analysis.
- Updated `.github/workflows/ci.yml`:
  - Split the "Test" step into two separate steps: one for running tests (`npm run test`) and another for coverage generation (`npm run test:coverage`).
  - Ensures more granular execution and better step visibility in CI pipelines.
- Removed redundant "Coverage" step from `.github/workflows/ci.yml`.
- Ensured `test:coverage` is run only once during the CI process.
- Improved clarity and reduced duplication in the workflow configuration.
- Updated `.github/workflows/ci.yml`:
  - Replaced `codecov-action@v5` with `codecov-action@v4`.
  - Commented out unused `token` and `slug` parameters.
This ensures compatibility and simplifies configuration.
Copy link

codecov bot commented Feb 7, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link

sonarqubecloud bot commented Feb 7, 2025

@geolffreym geolffreym merged commit 04663da into next Feb 7, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants