hazo_testing 0.1.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.
Files changed (44) hide show
  1. package/CHANGE_LOG.md +55 -0
  2. package/README.md +359 -0
  3. package/SETUP_CHECKLIST.md +115 -0
  4. package/config/hazo_testing_config.ini.sample +22 -0
  5. package/dist/api/test_client.d.ts +24 -0
  6. package/dist/api/test_client.js +82 -0
  7. package/dist/components/test_providers.d.ts +20 -0
  8. package/dist/components/test_providers.js +10 -0
  9. package/dist/db/augmented_adapter.d.ts +8 -0
  10. package/dist/db/augmented_adapter.js +24 -0
  11. package/dist/db/test_database.d.ts +16 -0
  12. package/dist/db/test_database.js +42 -0
  13. package/dist/errors.d.ts +7 -0
  14. package/dist/errors.js +22 -0
  15. package/dist/factories/scopes.d.ts +19 -0
  16. package/dist/factories/scopes.js +12 -0
  17. package/dist/factories/users.d.ts +14 -0
  18. package/dist/factories/users.js +44 -0
  19. package/dist/fixtures/registry.d.ts +6 -0
  20. package/dist/fixtures/registry.js +11 -0
  21. package/dist/fixtures/starter.d.ts +1 -0
  22. package/dist/fixtures/starter.js +47 -0
  23. package/dist/hooks/after_each_setup.d.ts +1 -0
  24. package/dist/hooks/after_each_setup.js +6 -0
  25. package/dist/hooks/polyfills.d.ts +1 -0
  26. package/dist/hooks/polyfills.js +6 -0
  27. package/dist/hooks/reset_hooks.d.ts +4 -0
  28. package/dist/hooks/reset_hooks.js +5 -0
  29. package/dist/index.client.d.ts +2 -0
  30. package/dist/index.client.js +3 -0
  31. package/dist/index.d.ts +20 -0
  32. package/dist/index.js +15 -0
  33. package/dist/nextjs/index.d.ts +10 -0
  34. package/dist/nextjs/index.js +26 -0
  35. package/dist/playwright/index.d.ts +13 -0
  36. package/dist/playwright/index.js +8 -0
  37. package/dist/wiring/jobs.d.ts +5 -0
  38. package/dist/wiring/jobs.js +46 -0
  39. package/dist/wiring/llm.d.ts +8 -0
  40. package/dist/wiring/llm.js +83 -0
  41. package/dist/wiring/notify.d.ts +8 -0
  42. package/dist/wiring/notify.js +52 -0
  43. package/jest-preset.cjs +21 -0
  44. package/package.json +55 -0
@@ -0,0 +1,52 @@
1
+ /** A minimal no-op in-app channel: validates anything, send is a no-op. */
2
+ const INAPP_STUB = {
3
+ capabilities: {
4
+ channel_id: "inapp",
5
+ display_name: "In-App (stub)",
6
+ template_body_keys: [],
7
+ max_text_length: null,
8
+ splits_long_messages: false,
9
+ supports_explicit_recipient: false,
10
+ retry: { max_attempts: 1, backoff_ms: () => 0 },
11
+ },
12
+ validate: () => ({ ok: true }),
13
+ send: async () => ({ ok: true }),
14
+ };
15
+ export async function wireHazoNotify(adapter, opts = {}) {
16
+ // Dynamic imports — deferred to avoid the "require() of ES module being
17
+ // import()ed" race when hazo_connect/server (CJS dist) and hazo_notify
18
+ // sub-exports (ESM) both load hazo_core concurrently in Jest ESM mode.
19
+ const { initInbox } = await import("hazo_notify/inbox");
20
+ const { registerChannel, __resetChannelRegistry } = await import("hazo_notify/channels");
21
+ const { dispatch } = await import("hazo_notify/dispatcher");
22
+ // Reset channel registry from any previous test (registerChannel throws on duplicate).
23
+ // The inbox connection is stored on globalThis and is overwritten by initInbox, so
24
+ // no explicit reset is needed — __resetInboxConnection is not exported from the
25
+ // hazo_notify/inbox sub-export (only from the internal connection.js file).
26
+ __resetChannelRegistry();
27
+ // Boot the inbox — the SQLite adapter satisfies the looksLikeAdapter check
28
+ // (query + claimRows + getConfig all exist).
29
+ await initInbox({ adapter: adapter });
30
+ // Always register the built-in inapp stub so the no-creds inbox path works.
31
+ // The dispatcher only writes inbox rows when enabled.length > 0; the stub
32
+ // channel's no-op send means no external I/O occurs.
33
+ registerChannel(INAPP_STUB);
34
+ // Register requested external channels.
35
+ for (const ch of opts.channels ?? []) {
36
+ if (ch === "email") {
37
+ const { EmailChannel } = await import("hazo_notify/adapters/email");
38
+ registerChannel(new EmailChannel());
39
+ }
40
+ if (ch === "telegram") {
41
+ const { TelegramChannel } = await import("hazo_notify/adapters/telegram");
42
+ registerChannel(new TelegramChannel());
43
+ }
44
+ if (ch === "webhook") {
45
+ const { WebhookChannel } = await import("hazo_notify/adapters/webhook");
46
+ // WebhookChannel requires a WebhookChannelOptions arg (unlike Email/Telegram).
47
+ // Not exercised by the test suite — pass an empty opts object.
48
+ registerChannel(new WebhookChannel({}));
49
+ }
50
+ }
51
+ return { dispatch };
52
+ }
@@ -0,0 +1,21 @@
1
+ // jest-preset.js
2
+ // Purpose: shared Jest preset factory for hazo consumers.
3
+ // Usage: const preset = require("hazo_testing/jest-preset"); module.exports = preset({ ... });
4
+ const path = require("node:path");
5
+
6
+ module.exports = function hazoTestingPreset(options = {}) {
7
+ const { aliasRoot = "<rootDir>", setupFilesAfterEnv = [] } = options;
8
+ const moduleNameMapper = {};
9
+ if (aliasRoot !== false) moduleNameMapper["^@/(.*)$"] = `${aliasRoot}/$1`;
10
+
11
+ return {
12
+ testEnvironment: "jsdom",
13
+ transform: { "^.+\\.(t|j)sx?$": ["ts-jest", { tsconfig: "tsconfig.test.json", isolatedModules: true }] },
14
+ transformIgnorePatterns: ["/node_modules/(?!(hazo_[a-z_]+)/)"],
15
+ moduleNameMapper,
16
+ setupFiles: [path.join(__dirname, "dist/hooks/polyfills.js")],
17
+ setupFilesAfterEnv: [path.join(__dirname, "dist/hooks/after_each_setup.js"), ...setupFilesAfterEnv],
18
+ testTimeout: 10000,
19
+ coverageReporters: ["text", "lcov", "html"],
20
+ };
21
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "hazo_testing",
3
+ "version": "0.1.0",
4
+ "description": "Shared test infrastructure for hazo apps: SQLite test DB, real-package wiring, auth factories, apiTestClient, fixtures, Jest preset.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
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" },
11
+ "./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" }
14
+ },
15
+ "files": ["dist", "jest-preset.cjs", "config", "README.md", "SETUP_CHECKLIST.md", "CHANGE_LOG.md"],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.build.json",
18
+ "lint": "tsc --noEmit",
19
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest"
20
+ },
21
+ "dependencies": {
22
+ "jose": "^4.15.9 || ^5.9.6"
23
+ },
24
+ "peerDependencies": {
25
+ "hazo_core": "^1.0.1",
26
+ "hazo_connect": "^3.0.0",
27
+ "hazo_auth": "^9.0.0",
28
+ "hazo_jobs": "^0.12.0",
29
+ "hazo_notify": "^6.1.0",
30
+ "hazo_llm_api": "^2.0.0",
31
+ "react": "^18.0.0 || ^19.0.0",
32
+ "react-dom": "^18.0.0 || ^19.0.0",
33
+ "@playwright/test": "^1.0.0",
34
+ "next": "^14.0.0 || ^16.0.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@playwright/test": { "optional": true },
38
+ "next": { "optional": true },
39
+ "react": { "optional": true },
40
+ "react-dom": { "optional": true }
41
+ },
42
+ "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
+ "@testing-library/jest-dom": "^6.6.3",
51
+ "@types/node": "^22.10.0",
52
+ "@types/react": "^19.0.0",
53
+ "@types/react-dom": "^19.0.0"
54
+ }
55
+ }