This project uses Vitest with jsdom for unit testing.
# Run all tests once
npm test
# Run tests in watch mode (re-runs on file changes)
npm run test:watch
# Run tests with UI
npm run test:ui
# Run tests with coverage report
npm run test:coveragetests/utils.test.js- Unit tests for utility functions (math, audio player, canvas helpers)tests/dom.test.js- DOM integration tests using jsdomtests/setup.js- Global test setup and browser API mocks
- Math utilities:
lerp(),easeInOut(),lerpColor() - Audio player:
formatTime(),updatePlayButton(),updateProgress(),updateMuteButton(),updateVolumeSlider(),handleAudioError() - Canvas utilities:
setViewportHeight(),initCellData() - Cookie notice:
closeCookieNotice() - Performance:
debounce()
- Element queries and updates
- Attribute modifications (aria-pressed, aria-label)
- Text content updates
- CSS class manipulation
- Form control states (disabled, value)
localStorage- getItem, setItem, removeItem, clearfetch- Promise-based HTTP requestsrequestAnimationFrame/cancelAnimationFrame- Animation timingwindow.dataLayer- Google Analytics tracking
The tests run in a jsdom environment which simulates a browser DOM without requiring an actual browser. This allows for:
- Fast execution
- Reliable CI/CD integration
- Full DOM API access
- Mocked browser APIs
Tests automatically run on:
- Every push to
main,master,developbranches - Every push to
copilot/**branches - Every pull request to
main,master,developbranches
The CI workflow runs tests on Node.js 18.x and 20.x to ensure compatibility.
See .github/workflows/test.yml for the full CI configuration.
Coverage reports are generated when running npm run test:coverage and are available in the coverage/ directory.
- Create a new test file in
tests/directory - Import the functions you want to test from
JS/utils.js - Use Vitest's
describe,it, andexpectfunctions - Run
npm testto verify your tests pass
Example:
import { describe, it, expect } from "vitest";
import { myFunction } from "../JS/utils.js";
describe("myFunction", () => {
it("should return expected value", () => {
expect(myFunction(1, 2)).toBe(3);
});
});