Add vitest browser test framework#2537
Conversation
12253ca to
5578c20
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2537 +/- ##
=======================================
Coverage ? 85.49%
=======================================
Files ? 185
Lines ? 6727
Branches ? 395
=======================================
Hits ? 5751
Misses ? 894
Partials ? 82
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR introduces vitest as a browser test framework for JavaScript code, using the cookie functions in switch-dark-mode.js as a proof of concept. It adds vitest configuration, package.json, initial tests, and CI integration, while also refactoring switch-dark-mode.js to use const declarations, strict equality, arrow functions, and exports for testability.
Changes:
- Sets up vitest browser testing framework with WebdriverIO provider, coverage via istanbul, and CI integration in GitHub Actions.
- Adds browser tests for
getCookieandsetCookiefunctions fromswitch-dark-mode.js. - Refactors
switch-dark-mode.jsto export functions, useconst/let, strict equality,globalThis, and arrow functions.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
vitest.config.js |
New vitest configuration with browser mode (WebdriverIO, Chrome + Firefox) and istanbul coverage |
package.json |
New package metadata with devDependencies for vitest and test runner |
djangoproject/static/js/mod/tests/switch-dark-mode.test.js |
New browser tests for getCookie and setCookie |
djangoproject/static/js/mod/switch-dark-mode.js |
Refactored to use exports, const/let, globalThis, strict equality, arrow functions |
.nvmrc |
New file pinning Node.js to the LTS version |
.gitignore |
Added node_modules/ and coverage/ ignore rules |
.github/workflows/tests.yml |
Renamed tests job to python, added vitest CI job, and added Codecov reporting to both |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
b458625 to
e4a37dc
Compare
89a5cdf to
2ec6504
Compare
|
We recently added Playwright tests. I just opened a pr to show how we could add some tests here: #2623 |
Yes, I do believe it's needed. I want to add unit tests, not integration tests. The latter is done via Playwright but comes at a performance and reliability cost. Besides, writing unit tests is a more rewarding experience in most cases. We recently added the same framework to django-debug-toolbar too, and it serves us well. |
|
There's not much JavaScript in this project currently, and there should be less as time goes on. My preference would be to invest in Playwright tests now and finish the in-progress JavaScript refactor before evaluating the need for JavaScript unit tests. |
While I don't believe there will be less JavaScript in the future, I only added this to provide tests for the fix of the If you say I don't have to, I won't. However, a refactor may benefit from unit test. I would use Playwright with the same caution, as Selenium. I love Python, but not to test JavaScript. |
|
I'm not against more things to help us test. And I'm sure there will always be some JS that could be tested. |
First step towards a robust test suite to enable JavaScript changes with confidence.
I chose the cookie functions as PoC.
@django/django-website was this what you had regarding
"We need to test the changed javascript for regressions"?
I didn't add Edge as a test browser since Edge and Chromium are engine-wise almost identical.