Files
sofarr/vitest.config.js
T
gronod 3e6af1bff2
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
Add frontend unit tests with Vitest + jsdom
- 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)
2026-05-21 00:07:41 +01:00

50 lines
2.0 KiB
JavaScript

// Copyright (c) 2026 Gordon Bolton. MIT License.
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
// 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
// (tokenStore cache, config singletons) doesn't leak between files
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',
reporter: ['text', 'lcov', 'html'],
reportsDirectory: './coverage',
// Only measure coverage on production source files
include: ['server/**/*.js'],
exclude: [
'server/index.js', // entry point with side-effects (process.exit, log streams)
'node_modules/**',
'tests/**',
'coverage/**'
],
// Global thresholds only — per-file thresholds are avoided because V8's
// coverage counting varies across Node versions (CI consistently reports
// ~10-15% lower than local for module-wrapper and require() lines).
// Thresholds updated after adding integration tests for dashboard.js,
// emby.js, sonarr.js, radarr.js, and sabnzbd.js. The SSE /stream
// endpoint and poller.js remain untested so thresholds are set
// conservatively to avoid CI flap from V8 coverage variance.
thresholds: {
lines: 55,
functions: 55,
branches: 40,
statements: 55
}
}
}
});