adding a github action to allow npm tests to run on PR#146
adding a github action to allow npm tests to run on PR#146josev814 wants to merge 8 commits intoexpertiza:mainfrom
Conversation
We should be testing if our tests pass before merging into main
Some tests are currently broken, implementing this will allow us to prevent breaking changes to make it in if a test fails
While the current product is using Node 18, 20 it the current LTS, so added testing for both Node 18 and 20
Right now we have to use npm install instead of npm ci (clean-install) because the package.json and package-lock.json are out of sync. We should look at getting these synced.
So many of the tests were broken. So took the time to get them working with some AI help. There are still failures, but it's much better now.
since vitest is used it made sense to replace jest with vi where it was mocking calls
Test Files 2 failed | 10 passed (12)
Tests 2 failed | 61 passed | 5 skipped (68)
Start at 06:41:44
Duration 39.33s (transform 3.31s, setup 1.64s, collect 12.03s, tests 10.13s, environment 6.65s, prepare 2.83s)
📝 WalkthroughWalkthroughThe changes establish a comprehensive test infrastructure by configuring Vitest testing framework with coverage reporting capabilities, adding a GitHub Actions workflow to execute tests on pull requests targeting the main branch with Node.js version matrix (18.x and 20.x), and updating test-related dependencies and configuration files. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
vitest.config.mts (1)
25-27: The HTML coverage report is currently discarded in CI.
.github/workflows/test-on-pr.ymlruns--coverage, but nothing uploads the generatedcoverage/directory. That means every matrix leg pays to generate the HTML report and then throws it away. Either uploadcoverage/as an artifact in the workflow or keephtmlas a local-only reporter.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@vitest.config.mts` around lines 25 - 27, The Vitest coverage config includes 'html' in coverage.reporter (in vitest.config.mts) but CI never preserves the generated coverage/ HTML, so either remove 'html' from the reporter array to stop generating discarded files or modify the CI workflow to upload the coverage/ directory as an artifact; update coverage.reporter to ['text','text-summary'] if you choose the former, or add an artifact-upload step in the CI job that runs tests to persist the coverage/ output if you choose the latter.src/test/setup.ts (1)
1-2: Use the Vitest-specificjest-domentrypoint here.This file is wired through Vitest
setupFiles, so the supported setup import is@testing-library/jest-dom/vitest. Keeping the generic entrypoint makes the setup drift from the documented Vitest integration and can leave matcher typings/setup behavior inconsistent. (github.com)♻️ Proposed fix
-import '@testing-library/jest-dom'; +import '@testing-library/jest-dom/vitest'; import { expect, vi, afterAll, beforeAll } from 'vitest';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/setup.ts` around lines 1 - 2, The test setup currently imports the generic entrypoint '@testing-library/jest-dom' which is incorrect for Vitest; update the import to the Vitest-specific entrypoint '@testing-library/jest-dom/vitest' in the setup module (the same file that imports expect, vi, beforeAll, afterAll) so Vitest matcher wiring and typings are applied correctly while leaving the existing named imports (expect, vi, beforeAll, afterAll) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/test-on-pr.yml:
- Around line 28-29: Replace the workflow step that currently runs "npm install"
with "npm ci" in the CI job (the step labeled "Install dependencies") so the
action uses the lockfile for reproducible installs and better
caching/performance; update the run command to "npm ci" and keep the step name
unchanged.
In `@src/pages/Courses/CourseAssignments.test.tsx`:
- Around line 76-80: The test currently makes the table assertion vacuous by
guarding it with "if (table)"; remove that conditional and assert the table
exists unconditionally (e.g., use screen.getByRole('table') or
expect(table).toBeInTheDocument() without the if) so a missing Table rendered by
CourseAssignments will fail the test; ensure the test still uses the existing
mock data matching mockCourseId so the Table should be present.
---
Nitpick comments:
In `@src/test/setup.ts`:
- Around line 1-2: The test setup currently imports the generic entrypoint
'@testing-library/jest-dom' which is incorrect for Vitest; update the import to
the Vitest-specific entrypoint '@testing-library/jest-dom/vitest' in the setup
module (the same file that imports expect, vi, beforeAll, afterAll) so Vitest
matcher wiring and typings are applied correctly while leaving the existing
named imports (expect, vi, beforeAll, afterAll) unchanged.
In `@vitest.config.mts`:
- Around line 25-27: The Vitest coverage config includes 'html' in
coverage.reporter (in vitest.config.mts) but CI never preserves the generated
coverage/ HTML, so either remove 'html' from the reporter array to stop
generating discarded files or modify the CI workflow to upload the coverage/
directory as an artifact; update coverage.reporter to ['text','text-summary'] if
you choose the former, or add an artifact-upload step in the CI job that runs
tests to persist the coverage/ output if you choose the latter.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ba321e26-c486-4b2a-be4d-1729f1f7ef08
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (8)
.github/workflows/test-on-pr.ymlpackage.jsonsrc/pages/Assignments/__tests__/AssignmentEditor.test.tsxsrc/pages/Assignments/__tests__/CreateTeams.test.tsxsrc/pages/Courses/CourseAssignments.test.tsxsrc/setupTests.tssrc/test/setup.tsvitest.config.mts
💤 Files with no reviewable changes (1)
- src/setupTests.ts
|
Test Files 2 failed | 11 passed (13) |
|
@kgudipe is there anything that would prevent this pr from going in? I think it would be beneficial to have PRs have tests ran before merging them. |
We should be testing if our tests pass before merging into main. To prevent issues like this in the future.
Implementing this will allow us to prevent breaking changes from making it into main if a test fails
While the current product is using Node 18, 20 is the current LTS, so added testing for both Node 18 and 20
Test Files 2 failed | 10 passed (12)
Tests 2 failed | 61 passed | 5 skipped (68)
Start at 06:41:44
Duration 39.33s (transform 3.31s, setup 1.64s, collect 12.03s, tests 10.13s, environment 6.65s, prepare 2.83s)
Summary by CodeRabbit
Tests
Chores