hazo_testing 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGE_LOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # hazo_testing changelog
2
2
 
3
+ ## 0.2.0 — 2026-06-11
4
+
5
+ ### Added — Vitest-compatible surfaces (additive; Jest preset unchanged)
6
+
7
+ The package now ships Vitest-flavoured presets and component-test helpers
8
+ alongside the existing Jest infrastructure. All v0.1.x exports are unchanged —
9
+ `jest-preset.cjs`, `src/hooks/after_each_setup.ts`, and every existing source
10
+ file were left untouched. hazo_admin's Jest consumption is unaffected.
11
+
12
+ - **`hazo_testing/vitest-preset`** — `vitest-preset.mjs`, a Vitest config
13
+ factory mirroring `jest-preset.cjs`. Returns a `UserConfig` with
14
+ `test.environment: "node"` (consumers opt into jsdom per-file), wires
15
+ `setupFiles: ["hazo_testing/vitest-setup"]`, `testTimeout: 10000`, a
16
+ `server-only` → empty-stub `resolve.alias`, and `server.deps.inline: [/hazo_/]`
17
+ so hazo_* packages transform through Vite. Accepts `{ alias, setupFiles }`
18
+ overrides.
19
+ - **`hazo_testing/vitest-setup`** — `src/vitest-setup.ts` setup entry that wires
20
+ the afterEach reset-hook runner. Backed by a new
21
+ `src/hooks/after_each_setup.vitest.ts` (sibling to the Jest
22
+ `after_each_setup.ts`) that imports `afterEach` explicitly from `vitest`
23
+ rather than relying on a Jest-injected global.
24
+ - **`hazo_testing/render`** — `renderWithIntl(ui, { locale?, messages?,
25
+ renderOptions? })` wraps a component in next-intl's `NextIntlClientProvider`
26
+ and renders it via `@testing-library/react`. Both peers are optional and
27
+ resolved lazily via `await import(...)` (same idiom as `src/nextjs/index.ts`).
28
+ `locale` defaults to `"en"`, `messages` to `{}`.
29
+ - **`hazo_testing/axe`** — `expectNoAxeViolations(container, options?)` runs
30
+ axe-core against a DOM container and throws a formatted error listing
31
+ violations. Defaults to the WCAG 2.0/2.1 A + AA tag set. `axe-core` is a real
32
+ dependency (always present when a11y testing is used).
33
+ - **`server-only` test stub** — `src/test/server_only_stub.ts`, shipped in dist
34
+ so consumers don't need a local copy; referenced by `vitest-preset.mjs`.
35
+
36
+ ### Dependencies
37
+
38
+ - Added `axe-core` to `dependencies`.
39
+ - Added `@testing-library/react`, `next-intl`, and `vitest` as **optional** peer
40
+ dependencies (`peerDependenciesMeta`).
41
+
3
42
  ## 0.1.1 — 2026-05-31
4
43
 
5
44
  ### Changed — consume hazo_llm_api 2.1.0 public API (FR-001 + FR-002 resolved)
package/README.md CHANGED
@@ -304,6 +304,64 @@ Without `--experimental-vm-modules`, ESM imports (`hazo_notify`, `hazo_jobs`, `h
304
304
 
305
305
  ---
306
306
 
307
+ ## Vitest preset (0.2.0)
308
+
309
+ `hazo_testing/vitest-preset` is the Vitest counterpart to the Jest preset — an
310
+ ESM config factory. Additive: the Jest preset and all v0.1.x exports are
311
+ unchanged.
312
+
313
+ ```ts
314
+ // vitest.config.ts
315
+ import { defineConfig } from "vitest/config";
316
+ import hazoTestingVitest from "hazo_testing/vitest-preset";
317
+
318
+ export default defineConfig(
319
+ hazoTestingVitest({
320
+ // alias: { ... }, // optional — extra resolve.alias entries
321
+ // setupFiles: [ ... ], // optional — additional setup files
322
+ }),
323
+ );
324
+ ```
325
+
326
+ - `test.environment: "node"` — opt into jsdom per-file with a
327
+ `// @vitest-environment jsdom` docblock.
328
+ - `setupFiles: ["hazo_testing/vitest-setup"]` — runs registered reset hooks in
329
+ `afterEach` (Vitest imports `afterEach` explicitly; it is not a global).
330
+ - `resolve.alias` maps `server-only` → an empty stub so server modules import
331
+ cleanly under Vitest.
332
+ - `server.deps.inline: [/hazo_/]` — hazo_* packages transform through Vite.
333
+ - `testTimeout: 10 000` ms.
334
+ - `vitest-preset.mjs` is ESM (Vitest reads config through Vite's ESM loader).
335
+
336
+ Install the optional peer: `npm install --save-dev vitest`.
337
+
338
+ ### `renderWithIntl` — `hazo_testing/render`
339
+
340
+ ```tsx
341
+ import { renderWithIntl } from "hazo_testing/render";
342
+
343
+ const { getByText } = await renderWithIntl(<MyComponent />, {
344
+ locale: "en", // default "en"
345
+ messages: { Greeting: { hi: "Hello" } }, // default {}
346
+ });
347
+ ```
348
+
349
+ Wraps `ui` in next-intl's `NextIntlClientProvider` and renders via
350
+ `@testing-library/react`. Both are optional peers, resolved lazily.
351
+
352
+ ### `expectNoAxeViolations` — `hazo_testing/axe`
353
+
354
+ ```ts
355
+ import { expectNoAxeViolations } from "hazo_testing/axe";
356
+
357
+ await expectNoAxeViolations(container); // WCAG 2.0/2.1 A + AA by default
358
+ ```
359
+
360
+ Throws a formatted error listing any axe-core violations. `axe-core` ships as a
361
+ direct dependency.
362
+
363
+ ---
364
+
307
365
  ## Reset hooks
308
366
 
309
367
  ```ts
@@ -105,7 +105,39 @@ If you use `hazo_testing/nextjs` for in-process server tests, install the option
105
105
  npm install --save-dev next
106
106
  ```
107
107
 
108
- ### 9. Add `.gitignore` entries
108
+ ### 9. (Optional, 0.2.0) Use the Vitest preset instead of Jest
109
+
110
+ `hazo_testing/vitest-preset` is an ESM config factory — the Vitest counterpart
111
+ to `hazo_testing/jest-preset`. Create `vitest.config.ts`:
112
+
113
+ ```ts
114
+ // vitest.config.ts
115
+ import { defineConfig } from "vitest/config";
116
+ import hazoTestingVitest from "hazo_testing/vitest-preset";
117
+
118
+ export default defineConfig(hazoTestingVitest());
119
+ ```
120
+
121
+ It sets `test.environment: "node"` (opt into jsdom per-file with a
122
+ `// @vitest-environment jsdom` docblock), wires `hazo_testing/vitest-setup`
123
+ (the afterEach reset-hook runner), `testTimeout: 10000`, a `server-only` →
124
+ empty-stub alias, and `server.deps.inline: [/hazo_/]`. Pass `{ alias,
125
+ setupFiles }` to extend. Install the optional peer:
126
+
127
+ ```bash
128
+ npm install --save-dev vitest
129
+ ```
130
+
131
+ For component tests, two more optional helpers ship in 0.2.0:
132
+
133
+ - **`hazo_testing/render`** — `renderWithIntl(ui, { locale?, messages? })`
134
+ wraps a component in next-intl's `NextIntlClientProvider`. Needs the optional
135
+ peers `next-intl` and `@testing-library/react`.
136
+ - **`hazo_testing/axe`** — `expectNoAxeViolations(container, options?)` asserts a
137
+ DOM container has no axe-core violations (WCAG 2.0/2.1 A + AA by default).
138
+ `axe-core` ships as a direct dependency — no extra install.
139
+
140
+ ### 10. Add `.gitignore` entries
109
141
 
110
142
  `wireHazoLlmApi` calls `initialize_llm_api` internally, which creates a `prompt_library.sqlite` file in the current working directory. Add it to your consumer's `.gitignore`:
111
143
 
@@ -0,0 +1,2 @@
1
+ import { type RunOptions } from "axe-core";
2
+ export declare function expectNoAxeViolations(container: Element, options?: RunOptions): Promise<void>;
@@ -0,0 +1,16 @@
1
+ // src/axe_helper.ts
2
+ // Purpose: assert that a rendered DOM container has no axe-core accessibility
3
+ // violations. `axe-core` is a real dependency (small, always needed when a11y
4
+ // testing is used), so it is imported statically rather than as an optional
5
+ // peer.
6
+ import axe from "axe-core";
7
+ const DEFAULT_OPTIONS = {
8
+ runOnly: { type: "tag", values: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"] },
9
+ };
10
+ export async function expectNoAxeViolations(container, options = DEFAULT_OPTIONS) {
11
+ const results = await axe.run(container, options);
12
+ if (results.violations.length === 0)
13
+ return;
14
+ const msg = results.violations.map(v => `[${v.impact}] ${v.description}\n Nodes: ${v.nodes.map(n => n.html).join(", ")}`).join("\n");
15
+ throw new Error(`Axe violations found:\n${msg}`);
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ // src/hooks/after_each_setup.vitest.ts
2
+ // Purpose: Vitest counterpart to after_each_setup.ts — runs all registered
3
+ // reset hooks after every test. Unlike Jest, Vitest does not inject `afterEach`
4
+ // as a global, so it is imported explicitly from "vitest". Sibling file; the
5
+ // Jest version (after_each_setup.ts) is left untouched.
6
+ import { afterEach } from "vitest";
7
+ import { runResetHooks } from "./reset_hooks.js";
8
+ afterEach(async () => { await runResetHooks(); });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const HAZO_TESTING_VERSION = "0.1.0";
1
+ export declare const HAZO_TESTING_VERSION = "0.2.0";
2
2
  export { DockerNotSupported, UnmappedLlmCall } from "./errors.js";
3
3
  export { augmentAdapter } from "./db/augmented_adapter.js";
4
4
  export type { AugmentedAdapter } from "./db/augmented_adapter.js";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  // hazo_testing public server barrel.
3
- export const HAZO_TESTING_VERSION = "0.1.0";
3
+ export const HAZO_TESTING_VERSION = "0.2.0";
4
4
  export { DockerNotSupported, UnmappedLlmCall } from "./errors.js";
5
5
  export { augmentAdapter } from "./db/augmented_adapter.js";
6
6
  export { createTestDatabase, createTestDatabaseSqlite, createTestDatabaseDocker, } from "./db/test_database.js";
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ export interface RenderWithIntlOptions {
3
+ /** BCP-47 locale passed to NextIntlClientProvider. Defaults to "en". */
4
+ locale?: string;
5
+ /** Message catalog passed to NextIntlClientProvider. Defaults to {}. */
6
+ messages?: Record<string, unknown>;
7
+ /** Extra options forwarded to @testing-library/react's render(). */
8
+ renderOptions?: Record<string, unknown>;
9
+ }
10
+ /**
11
+ * Render `ui` inside a NextIntlClientProvider. Returns the
12
+ * `@testing-library/react` RenderResult. Both peers are resolved lazily.
13
+ */
14
+ export declare function renderWithIntl(ui: React.ReactElement, options?: RenderWithIntlOptions): Promise<unknown>;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Render `ui` inside a NextIntlClientProvider. Returns the
4
+ * `@testing-library/react` RenderResult. Both peers are resolved lazily.
5
+ */
6
+ export async function renderWithIntl(ui, options = {}) {
7
+ const { locale = "en", messages = {}, renderOptions } = options;
8
+ let NextIntlClientProvider;
9
+ try {
10
+ // optional peer — `next-intl` may not be installed at runtime
11
+ ({ NextIntlClientProvider } = await import("next-intl"));
12
+ }
13
+ catch {
14
+ throw new Error("renderWithIntl requires the optional peer dependency `next-intl` to be installed.");
15
+ }
16
+ let render;
17
+ try {
18
+ // optional peer — `@testing-library/react` may not be installed at runtime
19
+ ({ render } = await import("@testing-library/react"));
20
+ }
21
+ catch {
22
+ throw new Error("renderWithIntl requires the optional peer dependency `@testing-library/react` to be installed.");
23
+ }
24
+ const wrapped = (_jsx(NextIntlClientProvider, { locale: locale, messages: messages, children: ui }));
25
+ return render(wrapped, renderOptions);
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import "./hooks/after_each_setup.vitest.js";
@@ -0,0 +1,6 @@
1
+ // src/vitest-setup.ts
2
+ // Purpose: Vitest setupFiles entry point referenced by vitest-preset.mjs
3
+ // (`setupFiles: ["hazo_testing/vitest-setup"]`). Wires the afterEach reset-hook
4
+ // runner into every Vitest test file. The Jest equivalents (polyfills.ts +
5
+ // after_each_setup.ts, wired via the jest preset) are left unchanged.
6
+ import "./hooks/after_each_setup.vitest.js";
package/package.json CHANGED
@@ -1,55 +1,111 @@
1
1
  {
2
2
  "name": "hazo_testing",
3
- "version": "0.1.1",
4
- "description": "Shared test infrastructure for hazo apps: SQLite test DB, real-package wiring, auth factories, apiTestClient, fixtures, Jest preset.",
3
+ "version": "0.2.0",
4
+ "description": "Shared test infrastructure for hazo apps: SQLite test DB, real-package wiring, auth factories, apiTestClient, fixtures, Jest + Vitest presets.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
- ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
10
- "./client": { "types": "./dist/index.client.d.ts", "default": "./dist/index.client.js" },
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./client": {
14
+ "types": "./dist/index.client.d.ts",
15
+ "default": "./dist/index.client.js"
16
+ },
11
17
  "./jest-preset": "./jest-preset.cjs",
12
- "./playwright": { "types": "./dist/playwright/index.d.ts", "default": "./dist/playwright/index.js" },
13
- "./nextjs": { "types": "./dist/nextjs/index.d.ts", "default": "./dist/nextjs/index.js" }
18
+ "./vitest-preset": "./vitest-preset.mjs",
19
+ "./vitest-setup": {
20
+ "types": "./dist/vitest-setup.d.ts",
21
+ "default": "./dist/vitest-setup.js"
22
+ },
23
+ "./render": {
24
+ "types": "./dist/render_with_intl.d.ts",
25
+ "default": "./dist/render_with_intl.js"
26
+ },
27
+ "./axe": {
28
+ "types": "./dist/axe_helper.d.ts",
29
+ "default": "./dist/axe_helper.js"
30
+ },
31
+ "./playwright": {
32
+ "types": "./dist/playwright/index.d.ts",
33
+ "default": "./dist/playwright/index.js"
34
+ },
35
+ "./nextjs": {
36
+ "types": "./dist/nextjs/index.d.ts",
37
+ "default": "./dist/nextjs/index.js"
38
+ }
14
39
  },
15
- "files": ["dist", "jest-preset.cjs", "config", "README.md", "SETUP_CHECKLIST.md", "CHANGE_LOG.md"],
40
+ "files": [
41
+ "dist",
42
+ "jest-preset.cjs",
43
+ "vitest-preset.mjs",
44
+ "config",
45
+ "README.md",
46
+ "SETUP_CHECKLIST.md",
47
+ "CHANGE_LOG.md"
48
+ ],
16
49
  "scripts": {
17
50
  "build": "tsc -p tsconfig.build.json",
18
51
  "lint": "tsc --noEmit",
19
52
  "test": "NODE_OPTIONS=--experimental-vm-modules jest"
20
53
  },
21
54
  "dependencies": {
55
+ "axe-core": "^4.12.1",
22
56
  "jose": "^4.15.9 || ^5.9.6"
23
57
  },
24
58
  "peerDependencies": {
25
- "hazo_core": "^1.0.1",
26
- "hazo_connect": "^3.0.0",
27
- "hazo_auth": "^9.0.0",
59
+ "@playwright/test": "^1.0.0",
60
+ "@testing-library/react": "^16.0.0",
61
+ "hazo_auth": "^10.0.0",
62
+ "hazo_connect": "^3.4.1",
63
+ "hazo_core": "^1.1.0",
28
64
  "hazo_jobs": "^0.12.0",
29
- "hazo_notify": "^6.1.0",
30
65
  "hazo_llm_api": "^2.1.0",
66
+ "hazo_notify": "^6.1.3",
67
+ "next": "^14.0.0 || ^16.0.0",
68
+ "next-intl": "^4.0.0",
31
69
  "react": "^18.0.0 || ^19.0.0",
32
70
  "react-dom": "^18.0.0 || ^19.0.0",
33
- "@playwright/test": "^1.0.0",
34
- "next": "^14.0.0 || ^16.0.0"
71
+ "vitest": "^2.0.0 || ^3.0.0"
35
72
  },
36
73
  "peerDependenciesMeta": {
37
- "@playwright/test": { "optional": true },
38
- "next": { "optional": true },
39
- "react": { "optional": true },
40
- "react-dom": { "optional": true }
74
+ "@playwright/test": {
75
+ "optional": true
76
+ },
77
+ "@testing-library/react": {
78
+ "optional": true
79
+ },
80
+ "next": {
81
+ "optional": true
82
+ },
83
+ "next-intl": {
84
+ "optional": true
85
+ },
86
+ "react": {
87
+ "optional": true
88
+ },
89
+ "react-dom": {
90
+ "optional": true
91
+ },
92
+ "vitest": {
93
+ "optional": true
94
+ }
41
95
  },
42
96
  "devDependencies": {
43
- "typescript": "^5.7.2",
44
- "jest": "^30.2.0",
45
- "ts-jest": "^29.4.5",
46
- "@types/jest": "^30.0.0",
47
- "jest-environment-node": "^30.2.0",
48
- "jest-environment-jsdom": "^30.2.0",
49
- "@testing-library/react": "^16.1.0",
50
97
  "@testing-library/jest-dom": "^6.6.3",
98
+ "@testing-library/react": "^16.1.0",
99
+ "@types/jest": "^30.0.0",
51
100
  "@types/node": "^22.10.0",
52
101
  "@types/react": "^19.0.0",
53
- "@types/react-dom": "^19.0.0"
102
+ "@types/react-dom": "^19.0.0",
103
+ "jest": "^30.2.0",
104
+ "jest-environment-jsdom": "^30.2.0",
105
+ "jest-environment-node": "^30.2.0",
106
+ "next-intl": "^4.13.0",
107
+ "ts-jest": "^29.4.5",
108
+ "typescript": "^5.7.2",
109
+ "vitest": "^3.2.6"
54
110
  }
55
111
  }
@@ -0,0 +1,49 @@
1
+ // vitest-preset.mjs
2
+ // Purpose: shared Vitest config factory for hazo consumers — the Vitest
3
+ // counterpart to jest-preset.cjs. Additive: the Jest preset is unchanged.
4
+ // Usage:
5
+ // import hazoTestingVitest from "hazo_testing/vitest-preset";
6
+ // import { defineConfig } from "vitest/config";
7
+ // export default defineConfig(hazoTestingVitest());
8
+ //
9
+ // The package is `type: "module"`, and Vitest reads its config through Vite's
10
+ // ESM loader, so this factory is `.mjs` (mirrors jest-preset.cjs being CJS for
11
+ // Jest's synchronous config read).
12
+ import path from "node:path";
13
+ import { fileURLToPath } from "node:url";
14
+
15
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
+
17
+ // Empty stub for the `server-only` package. The real module throws unless it is
18
+ // imported from an RSC bundler context, which breaks any server module that
19
+ // begins with `import "server-only";` under Vitest. Aliasing it to this dist
20
+ // file lets those modules import cleanly. (Mirror of Kinstripe's
21
+ // src/test/server-only-stub.ts, shipped here so consumers need no local copy.)
22
+ const serverOnlyStub = path.join(__dirname, "dist/test/server_only_stub.js");
23
+
24
+ export default function vitestPreset(options = {}) {
25
+ const { alias = {}, setupFiles = [] } = options;
26
+
27
+ return {
28
+ test: {
29
+ // Node by default — the consuming project opts into jsdom per-file via
30
+ // the `// @vitest-environment jsdom` docblock comment.
31
+ environment: "node",
32
+ setupFiles: ["hazo_testing/vitest-setup", ...setupFiles],
33
+ testTimeout: 10000,
34
+ },
35
+ resolve: {
36
+ alias: {
37
+ "server-only": serverOnlyStub,
38
+ ...alias,
39
+ },
40
+ },
41
+ server: {
42
+ // hazo_* packages ship ESM/CJS dual builds; Vite must inline-transform
43
+ // them rather than externalising, or their sub-path exports break.
44
+ deps: {
45
+ inline: [/hazo_/],
46
+ },
47
+ },
48
+ };
49
+ }