web: move to vitest
This commit is contained in:
@@ -24,11 +24,12 @@ npm install
|
||||
npm run dev # http://localhost:3000
|
||||
npm run codegen # regenerate GraphQL types (needs the backend running)
|
||||
npm run build
|
||||
npm test # vitest (npm run test:watch for watch mode)
|
||||
```
|
||||
|
||||
## 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
|
||||
prek install # registers the git hook
|
||||
|
||||
@@ -27,3 +27,14 @@ exclude = '/migrations/'
|
||||
id = "ruff-format"
|
||||
files = '^dnscms/.*\.py$'
|
||||
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
|
||||
|
||||
Generated
+1194
-9
File diff suppressed because it is too large
Load Diff
+3
-1
@@ -7,7 +7,8 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"test": "node --test src/lib/*.test.ts",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"codegen": "graphql-codegen",
|
||||
"perf:build": "next build",
|
||||
"perf:serve": "next start -p 3100",
|
||||
@@ -45,6 +46,7 @@
|
||||
"eslint-config-next": "16.2.10",
|
||||
"lighthouse": "^13.4.0",
|
||||
"typescript": "^6",
|
||||
"vitest": "^4.1.10",
|
||||
"wait-on": "^9.0.10"
|
||||
},
|
||||
"overrides": {
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import { secondsUntilOsloMidnight } from "./revalidation.ts";
|
||||
|
||||
test("normal day: 12:00 CEST is 12h from midnight", () => {
|
||||
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", () => {
|
||||
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)", () => {
|
||||
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)", () => {
|
||||
const now = new Date("2026-03-28T23:00:00Z");
|
||||
assert.equal(secondsUntilOsloMidnight(now), 23 * 3600);
|
||||
expect(secondsUntilOsloMidnight(now)).toBe(23 * 3600);
|
||||
});
|
||||
|
||||
@@ -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)),
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user