web: move to vitest

This commit is contained in:
2026-08-04 03:02:09 +02:00
parent eabcd47bfd
commit 6370373f0d
6 changed files with 1228 additions and 17 deletions
+2 -1
View File
@@ -24,11 +24,12 @@ npm install
npm run dev # http://localhost:3000 npm run dev # http://localhost:3000
npm run codegen # regenerate GraphQL types (needs the backend running) npm run codegen # regenerate GraphQL types (needs the backend running)
npm run build npm run build
npm test # vitest (npm run test:watch for watch mode)
``` ```
## Pre-commit hooks ## Pre-commit hooks
[prek](https://github.com/j178/prek) runs ruff lint + format on `dnscms/**/*.py` plus a few sanity hooks. Hooks are configured in [prek.toml](prek.toml). [prek](https://github.com/j178/prek) runs ruff lint + format on `dnscms/**/*.py`, vitest on `web/` changes, plus a few sanity hooks. Hooks are configured in [prek.toml](prek.toml).
```bash ```bash
prek install # registers the git hook prek install # registers the git hook
+11
View File
@@ -27,3 +27,14 @@ exclude = '/migrations/'
id = "ruff-format" id = "ruff-format"
files = '^dnscms/.*\.py$' files = '^dnscms/.*\.py$'
exclude = '/migrations/' exclude = '/migrations/'
[[repos]]
repo = "local"
[[repos.hooks]]
id = "vitest"
name = "vitest"
entry = "npm --prefix web test"
language = "system"
files = '^web/(src/.*\.(ts|tsx)|package\.json|vitest\.config\.mts)$'
pass_filenames = false
+1194 -9
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -7,7 +7,8 @@
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",
"test": "node --test src/lib/*.test.ts", "test": "vitest run",
"test:watch": "vitest",
"codegen": "graphql-codegen", "codegen": "graphql-codegen",
"perf:build": "next build", "perf:build": "next build",
"perf:serve": "next start -p 3100", "perf:serve": "next start -p 3100",
@@ -45,6 +46,7 @@
"eslint-config-next": "16.2.10", "eslint-config-next": "16.2.10",
"lighthouse": "^13.4.0", "lighthouse": "^13.4.0",
"typescript": "^6", "typescript": "^6",
"vitest": "^4.1.10",
"wait-on": "^9.0.10" "wait-on": "^9.0.10"
}, },
"overrides": { "overrides": {
+5 -6
View File
@@ -1,24 +1,23 @@
import assert from "node:assert/strict"; import { expect, test } from "vitest";
import { test } from "node:test";
import { secondsUntilOsloMidnight } from "./revalidation.ts"; import { secondsUntilOsloMidnight } from "./revalidation.ts";
test("normal day: 12:00 CEST is 12h from midnight", () => { test("normal day: 12:00 CEST is 12h from midnight", () => {
const now = new Date("2026-07-07T10:00:00Z"); const now = new Date("2026-07-07T10:00:00Z");
assert.equal(secondsUntilOsloMidnight(now), 12 * 3600); expect(secondsUntilOsloMidnight(now)).toBe(12 * 3600);
}); });
test("clamps to 60s just before midnight", () => { test("clamps to 60s just before midnight", () => {
const now = new Date("2026-07-07T21:59:30Z"); const now = new Date("2026-07-07T21:59:30Z");
assert.equal(secondsUntilOsloMidnight(now), 60); expect(secondsUntilOsloMidnight(now)).toBe(60);
}); });
test("DST fall-back day is 25h (2026-10-25)", () => { test("DST fall-back day is 25h (2026-10-25)", () => {
const now = new Date("2026-10-24T22:00:00Z"); const now = new Date("2026-10-24T22:00:00Z");
assert.equal(secondsUntilOsloMidnight(now), 25 * 3600); expect(secondsUntilOsloMidnight(now)).toBe(25 * 3600);
}); });
test("DST spring-forward day is 23h (2026-03-29)", () => { test("DST spring-forward day is 23h (2026-03-29)", () => {
const now = new Date("2026-03-28T23:00:00Z"); const now = new Date("2026-03-28T23:00:00Z");
assert.equal(secondsUntilOsloMidnight(now), 23 * 3600); expect(secondsUntilOsloMidnight(now)).toBe(23 * 3600);
}); });
+13
View File
@@ -0,0 +1,13 @@
import { fileURLToPath } from "node:url";
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
include: ["src/**/*.test.{ts,tsx}"],
},
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});