Add frontend unit tests with Vitest + jsdom
Licence Check / Licence compatibility and copyright header verification (push) Successful in 38s
CI / Security audit (push) Successful in 53s
CI / Tests & coverage (push) Successful in 1m9s
Build and Push Docker Image / build (push) Failing after 32s

- Create tests/frontend/utils/format.test.js with 24 tests for formatting utilities
- Create tests/frontend/ui/downloads.test.js with 10 tests for DOM rendering functions
- Update vitest.config.js to support jsdom environment for frontend tests
- All 34 tests pass and cover edge cases (null, zero, large numbers, DOM structure)
This commit is contained in:
2026-05-21 00:07:41 +01:00
parent d9897ff0d2
commit 3e6af1bff2
3 changed files with 235 additions and 2 deletions
+8 -2
View File
@@ -3,8 +3,6 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
// Node environment for all tests (server-side CJS modules, no browser APIs needed)
environment: 'node',
// Global test helpers (describe, it, expect, vi) without per-file imports
globals: true,
// Run each test file in an isolated module registry so module-level state
@@ -12,6 +10,14 @@ export default defineConfig({
isolate: true,
// Give each file its own data directory so tokenStore file I/O doesn't collide
setupFiles: ['./tests/setup.js'],
// Environment configuration based on test type
environmentMatchGlobs: [
// Server tests use node environment (must come first - more specific)
['tests/unit/**/*.js', 'node'],
['tests/integration/**/*.js', 'node'],
// Frontend tests need jsdom for DOM APIs (broader pattern comes last)
['tests/frontend/**/*.js', 'jsdom']
],
// Coverage via V8 (built into Node — no babel transform needed)
coverage: {
provider: 'v8',