hazo_testing 0.1.0 → 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 +56 -0
- package/README.md +58 -0
- package/SETUP_CHECKLIST.md +33 -1
- package/dist/axe_helper.d.ts +2 -0
- package/dist/axe_helper.js +16 -0
- package/dist/hooks/after_each_setup.vitest.d.ts +1 -0
- package/dist/hooks/after_each_setup.vitest.js +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/render_with_intl.d.ts +14 -0
- package/dist/render_with_intl.js +26 -0
- package/dist/test/server_only_stub.d.ts +1 -0
- package/dist/test/server_only_stub.js +1 -0
- package/dist/vitest-setup.d.ts +1 -0
- package/dist/vitest-setup.js +6 -0
- package/dist/wiring/llm.js +14 -60
- package/package.json +82 -26
- package/vitest-preset.mjs +49 -0
package/CHANGE_LOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
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
|
+
|
|
42
|
+
## 0.1.1 — 2026-05-31
|
|
43
|
+
|
|
44
|
+
### Changed — consume hazo_llm_api 2.1.0 public API (FR-001 + FR-002 resolved)
|
|
45
|
+
|
|
46
|
+
- **`wireHazoLlmApi` now uses the public `hazo_llm_api/server` API.** hazo_llm_api
|
|
47
|
+
2.1.0 publicly exports the provider registry (`clear_registry`,
|
|
48
|
+
`register_provider`, `set_enabled_llms`, `set_primary_llm`, …) and provider
|
|
49
|
+
classes (`GeminiProvider`, `QwenProvider`) — so the wiring no longer resolves
|
|
50
|
+
internal `dist/` paths via `import.meta.resolve`. Removes the FR-001 fragility.
|
|
51
|
+
Peer dep bumped: `hazo_llm_api ^2.0.0` → `^2.1.0`.
|
|
52
|
+
- **Dropped the Jest `forceExit` workaround.** A new `jest.setup.cjs` sets
|
|
53
|
+
`HAZO_LLM_API_NO_AUTO_INIT=1` (FR-002, hazo_llm_api 2.1.0) so importing
|
|
54
|
+
`hazo_llm_api/server` no longer fires an orphaned import-time DB init that
|
|
55
|
+
"require()s after the jest environment is torn down". The suite now exits 0 on
|
|
56
|
+
its own. (A `prompt_library.sqlite` is still created by the explicit
|
|
57
|
+
`initialize_llm_api()` call inside the llm wiring test — still gitignored.)
|
|
58
|
+
|
|
3
59
|
## 0.1.0 — 2026-05-31
|
|
4
60
|
|
|
5
61
|
### Initial release
|
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
|
package/SETUP_CHECKLIST.md
CHANGED
|
@@ -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.
|
|
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,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
|
+
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.
|
|
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/dist/wiring/llm.js
CHANGED
|
@@ -1,69 +1,23 @@
|
|
|
1
1
|
// src/wiring/llm.ts
|
|
2
|
-
// Purpose: wire the REAL hazo_llm_api service + provider registry
|
|
2
|
+
// Purpose: wire the REAL hazo_llm_api service + provider registry against a test
|
|
3
|
+
// setup, using the PUBLIC hazo_llm_api/server API.
|
|
3
4
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// 2. GeminiProvider / QwenProvider are NOT exported from "hazo_llm_api/server"
|
|
12
|
-
// either. They are in dist/lib/providers/gemini/index.js and
|
|
13
|
-
// dist/lib/providers/qwen/index.js respectively. Same resolution technique.
|
|
14
|
-
//
|
|
15
|
-
// 3. Provider constructors require { api_key, logger, ... }. We read the API key
|
|
16
|
-
// from process.env at call time. With an empty api_key (no creds), the
|
|
17
|
-
// constructor does NOT throw — validation only fails at actual API call time.
|
|
18
|
-
// This lets test 1 (no creds) assert "run is a function" without credentials.
|
|
19
|
-
//
|
|
20
|
-
// 4. hazo_llm_text_text IS exported from "hazo_llm_api/server" with signature:
|
|
21
|
-
// (params: TextTextParams, llm?: ProviderName) => Promise<LLMResponse>
|
|
22
|
-
// TextTextParams: { prompt?: string, ... }
|
|
23
|
-
// LLMResponse: { success: boolean, text?: string, error?: string, ... }
|
|
24
|
-
//
|
|
25
|
-
// 5. hazo_llm_text_text calls check_initialized() internally, which requires
|
|
26
|
-
// initialize_llm_api() to have been called. We call it with a stub hazo_connect
|
|
27
|
-
// (api_log disabled) to set initialized=true without touching SQLite.
|
|
28
|
-
// After initialize_llm_api returns, we override the registry with our
|
|
29
|
-
// manually-constructed providers.
|
|
30
|
-
//
|
|
31
|
-
// All imports are deferred to dynamic import() inside wireHazoLlmApi to avoid the
|
|
32
|
-
// "require() of ES module being import()ed" CJS/ESM race under Jest ESM mode
|
|
33
|
-
// (same technique used in Tasks 6 & 7).
|
|
34
|
-
import { fileURLToPath } from "node:url";
|
|
35
|
-
import { dirname } from "node:path";
|
|
5
|
+
// As of hazo_llm_api 2.1.0 (FR-001) the registry functions and provider classes
|
|
6
|
+
// are public exports of `hazo_llm_api/server`, so this no longer resolves
|
|
7
|
+
// internal dist paths via import.meta.resolve — it imports them directly. The
|
|
8
|
+
// import stays a deferred dynamic import() (canonical-import exemption per D-022)
|
|
9
|
+
// to avoid the CJS/ESM module-load race under Jest's --experimental-vm-modules
|
|
10
|
+
// runner. hazo_llm_api 2.1.0 also makes the import hermetic when
|
|
11
|
+
// HAZO_LLM_API_NO_AUTO_INIT=1 is set (see jest.setup.cjs) — no orphaned DB init.
|
|
36
12
|
export async function wireHazoLlmApi(opts) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
// import.meta.resolve gives us the file:// URL of the server entry point.
|
|
42
|
-
const serverFileUrl = await import.meta.resolve("hazo_llm_api/server");
|
|
43
|
-
// serverFileUrl → file:///…/hazo_llm_api/dist/server.js
|
|
44
|
-
const distRoot = dirname(fileURLToPath(serverFileUrl));
|
|
45
|
-
// distRoot → /…/hazo_llm_api/dist
|
|
46
|
-
// Step 3: Import internal registry functions from the dist (not in exports map).
|
|
47
|
-
const registryPath = `file://${distRoot}/lib/providers/registry.js`;
|
|
48
|
-
const registry = await import(registryPath);
|
|
49
|
-
const { clear_registry, register_provider, set_enabled_llms, set_primary_llm } = registry;
|
|
50
|
-
// Step 4: Import provider classes from their internal dist paths.
|
|
51
|
-
const geminiPath = `file://${distRoot}/lib/providers/gemini/index.js`;
|
|
52
|
-
const qwenPath = `file://${distRoot}/lib/providers/qwen/index.js`;
|
|
53
|
-
const { GeminiProvider } = await import(geminiPath);
|
|
54
|
-
const { QwenProvider } = await import(qwenPath);
|
|
55
|
-
// Step 5: Call initialize_llm_api with a no-op hazo_connect stub so
|
|
56
|
-
// (a) initialized = true is set (required by check_initialized),
|
|
57
|
-
// (b) SQLite is never touched,
|
|
58
|
-
// (c) api_log table setup is skipped.
|
|
59
|
-
// initialize_llm_api will also call load_and_register_providers internally —
|
|
60
|
-
// that may or may not register providers depending on env/config. We override
|
|
61
|
-
// the registry immediately afterwards.
|
|
13
|
+
const { initialize_llm_api, hazo_llm_text_text, default_logger, clear_registry, register_provider, set_enabled_llms, set_primary_llm, GeminiProvider, QwenProvider, } = await import("hazo_llm_api/server");
|
|
14
|
+
// Initialize with a no-op hazo_connect stub (api_log disabled) so
|
|
15
|
+
// check_initialized() passes without touching SQLite. We then override the
|
|
16
|
+
// registry with our manually-constructed providers.
|
|
62
17
|
await initialize_llm_api({
|
|
63
18
|
hazo_connect: {},
|
|
64
19
|
api_log: { enabled: false },
|
|
65
20
|
});
|
|
66
|
-
// Step 6: Reset registry and wire it up for the requested providers.
|
|
67
21
|
clear_registry();
|
|
68
22
|
set_enabled_llms(opts.providers);
|
|
69
23
|
set_primary_llm(opts.primary);
|
|
@@ -71,7 +25,7 @@ export async function wireHazoLlmApi(opts) {
|
|
|
71
25
|
if (name === "gemini") {
|
|
72
26
|
const api_key = process.env.GEMINI_API_KEY ?? "";
|
|
73
27
|
// Constructor does NOT throw on empty api_key — error only surfaces at
|
|
74
|
-
// call time, which lets
|
|
28
|
+
// call time, which lets the no-creds test assert typeof run === "function".
|
|
75
29
|
register_provider(new GeminiProvider({ api_key, logger: default_logger }));
|
|
76
30
|
}
|
|
77
31
|
if (name === "qwen") {
|
package/package.json
CHANGED
|
@@ -1,55 +1,111 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hazo_testing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Shared test infrastructure for hazo apps: SQLite test DB, real-package wiring, auth factories, apiTestClient, fixtures, Jest
|
|
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
|
-
".": {
|
|
10
|
-
|
|
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
|
-
"./
|
|
13
|
-
"./
|
|
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": [
|
|
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
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"hazo_auth": "^
|
|
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
|
-
"
|
|
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
|
-
"
|
|
34
|
-
"next": "^14.0.0 || ^16.0.0"
|
|
71
|
+
"vitest": "^2.0.0 || ^3.0.0"
|
|
35
72
|
},
|
|
36
73
|
"peerDependenciesMeta": {
|
|
37
|
-
"@playwright/test": {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"react
|
|
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
|
+
}
|