test: pin test timezone to UTC, document test commands

This commit is contained in:
Florian Kostenzer
2026-07-13 23:31:44 +02:00
parent 2dc46ab007
commit ae1586cde7
5 changed files with 17 additions and 10 deletions
+6
View File
@@ -16,8 +16,14 @@ npm run check # Svelte + TypeScript type checking
npm run prettify # Format all files with Prettier npm run prettify # Format all files with Prettier
npm run migrate # Run database migrations via Knex npm run migrate # Run database migrations via Knex
npm run seed # Run database seeds (migrations run automatically first) npm run seed # Run database seeds (migrations run automatically first)
npm test # Run all tests (server unit + browser component projects)
npm run test:server # Server-side unit tests only (Node)
npm run test:client # Component tests only (headless Chromium via Playwright)
npm run test:watch # Watch mode
``` ```
Component tests need a one-time `npx playwright install chromium`.
## Architecture ## Architecture
### Dual Process Model ### Dual Process Model
+3 -3
View File
@@ -49,10 +49,10 @@
"schedule": "vite-node src/lib/server/startup.ts", "schedule": "vite-node src/lib/server/startup.ts",
"seed": "npx knex seed:run", "seed": "npx knex seed:run",
"start": "node build/main.js", "start": "node build/main.js",
"test": "vitest run", "test": "cross-env TZ=UTC vitest run",
"test:client": "vitest run --project=client", "test:client": "vitest run --project=client",
"test:server": "vitest run --project=server", "test:server": "cross-env TZ=UTC vitest run --project=server",
"test:watch": "vitest" "test:watch": "cross-env TZ=UTC vitest"
}, },
"devDependencies": { "devDependencies": {
"@internationalized/date": "^3.10.0", "@internationalized/date": "^3.10.0",
@@ -3,8 +3,8 @@ import { render } from "vitest-browser-svelte";
import StatusBarCalendar from "./StatusBarCalendar.svelte"; import StatusBarCalendar from "./StatusBarCalendar.svelte";
import type { TimestampStatusCount } from "$lib/server/types/db"; import type { TimestampStatusCount } from "$lib/server/types/db";
// Noon UTC keeps the rendered calendar date stable for any machine timezone // The browser context is pinned to UTC (see vite.config.ts), so the timezone store
// with an offset within ±11 hours (the timezone store defaults to browser TZ). // (which defaults to browser TZ) is deterministic; noon UTC keeps fixtures safe too.
const NOON_UTC = 1768478400; // 2026-01-15T12:00:00Z const NOON_UTC = 1768478400; // 2026-01-15T12:00:00Z
const day = (overrides: Partial<TimestampStatusCount>): TimestampStatusCount => ({ const day = (overrides: Partial<TimestampStatusCount>): TimestampStatusCount => ({
+3 -3
View File
@@ -32,9 +32,9 @@ import {
} from "./tool"; } from "./tool";
import type { TimestampStatusCount } from "./types/db"; import type { TimestampStatusCount } from "./types/db";
// All fixed timestamps are at 12:00 UTC so that local-date-based functions // The npm scripts pin TZ=UTC, so local-date-based functions (GetDayStartTimestampUTC
// (GetDayStartTimestampUTC mixes local date parts with Date.UTC) produce the // mixes local date parts with Date.UTC) are deterministic here. Fixtures still use
// same result on any machine with a UTC offset between -11 and +11 hours. // noon UTC so the tests stay safe even if vitest is run directly without the pin.
const NOON_UTC = 1768478400; // 2026-01-15T12:00:00Z const NOON_UTC = 1768478400; // 2026-01-15T12:00:00Z
const DAY_START = 1768435200; // 2026-01-15T00:00:00Z const DAY_START = 1768435200; // 2026-01-15T00:00:00Z
+3 -2
View File
@@ -5,6 +5,7 @@ import version from "vite-plugin-package-version";
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import devtoolsJson from "vite-plugin-devtools-json"; import devtoolsJson from "vite-plugin-devtools-json";
import { playwright } from "@vitest/browser-playwright"; import { playwright } from "@vitest/browser-playwright";
import { configDefaults } from "vitest/config";
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
@@ -66,7 +67,7 @@ export default defineConfig(({ mode }) => {
name: "server", name: "server",
environment: "node", environment: "node",
include: ["src/**/*.{test,spec}.{js,ts}"], include: ["src/**/*.{test,spec}.{js,ts}"],
exclude: ["src/**/*.svelte.{test,spec}.{js,ts}"], exclude: [...configDefaults.exclude, "src/**/*.svelte.{test,spec}.{js,ts}"],
}, },
}, },
{ {
@@ -76,7 +77,7 @@ export default defineConfig(({ mode }) => {
browser: { browser: {
enabled: true, enabled: true,
headless: true, headless: true,
provider: playwright(), provider: playwright({ contextOptions: { timezoneId: "UTC" } }),
instances: [{ browser: "chromium" }], instances: [{ browser: "chromium" }],
// Vitest's default browser API port (63315) can fall inside Windows // Vitest's default browser API port (63315) can fall inside Windows
// Hyper-V excluded TCP port ranges; pin below the ephemeral range. // Hyper-V excluded TCP port ranges; pin below the ephemeral range.