@classytic/arc-testkit 0.1.0 → 0.1.2

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/dist/index.d.mts CHANGED
@@ -1,54 +1,11 @@
1
- import { ArcModuleInput, CreateAppOptions } from "@classytic/arc/factory";
2
- import { FastifyInstance } from "fastify";
1
+ import { BootModuleAppOptions as BootModuleAppOptions$1, BootModulesInput, ModuleTestApp as ModuleTestApp$1, TestkitContext as TestkitContext$1 } from "@classytic/arc/testing";
3
2
  import { Connection } from "mongoose";
4
3
 
5
4
  //#region src/index.d.ts
6
- /** The context a backend yields — a live connection + the URI it connects to. */
7
- interface BackendContext {
8
- connection: Connection;
9
- uri: string;
10
- }
11
- /**
12
- * A pluggable database backend. Structurally satisfied by
13
- * `@classytic/mongokit/testkit`'s `mongoMemoryBackend()` — no import of it in
14
- * the type, so arc-testkit never hard-depends on the kit (one-way: arc-testkit
15
- * consumes a backend by shape).
16
- */
17
- interface TestBackend {
18
- setup(): Promise<{
19
- ctx: BackendContext;
20
- teardown: () => Promise<void>;
21
- }>;
22
- }
23
- /** What a module factory receives — the live connection + its URI. */
24
- interface TestkitContext {
25
- connection: Connection;
26
- mongoUri: string;
27
- }
28
- type ModulesInput = ArcModuleInput | readonly ArcModuleInput[] | ((ctx: TestkitContext) => ArcModuleInput | readonly ArcModuleInput[] | Promise<ArcModuleInput | readonly ArcModuleInput[]>);
29
- interface BootModuleAppOptions {
30
- /**
31
- * Use a single-node replica set instead of a standalone mongod. Required when
32
- * the module under test opens multi-document transactions. Ignored when a
33
- * custom `backend` is supplied. Default false.
34
- */
35
- replset?: boolean;
36
- /** Merged over the testkit defaults (`preset: 'testing'`, `auth: false`). */
37
- app?: Partial<CreateAppOptions>;
38
- /**
39
- * Override the database backend. Default: `mongoMemoryBackend()` from
40
- * `@classytic/mongokit/testkit`. Supply your own to point at a shared server,
41
- * a real Atlas cluster, or a different kit's backend.
42
- */
43
- backend?: TestBackend;
44
- }
45
- interface ModuleTestApp {
46
- app: FastifyInstance;
47
- connection: Connection;
48
- mongoUri: string;
49
- /** Close app → tear the backend down (disconnect + stop server). Idempotent. */
50
- close(): Promise<void>;
51
- }
5
+ type TestkitContext = TestkitContext$1<Connection>;
6
+ type ModulesInput = BootModulesInput<Connection>;
7
+ type BootModuleAppOptions = BootModuleAppOptions$1<Connection>;
8
+ type ModuleTestApp = ModuleTestApp$1<Connection>;
52
9
  declare function bootModuleApp(modules: ModulesInput, options?: BootModuleAppOptions): Promise<ModuleTestApp>;
53
10
  //#endregion
54
- export { BackendContext, BootModuleAppOptions, ModuleTestApp, ModulesInput, TestBackend, TestkitContext, bootModuleApp };
11
+ export { BootModuleAppOptions, ModuleTestApp, ModulesInput, TestkitContext, bootModuleApp };
package/dist/index.mjs CHANGED
@@ -1,73 +1,27 @@
1
- import { createApp } from "@classytic/arc/factory";
1
+ import { bootModuleApp as bootModuleApp$1 } from "@classytic/arc/testing";
2
2
  //#region src/index.ts
3
3
  /**
4
- * `@classytic/arc-testkit` — boot a REAL arc app around the module(s) under
5
- * test, on a real (in-memory) database. The ecosystem's contributor contract:
6
- * **if your module boots green here, it composes into any arc host.**
4
+ * @classytic/arc-testkit — boots a REAL arc app around the module(s) under
5
+ * test on in-memory MongoDB. The contributor contract: if your module boots
6
+ * green here, it composes into any arc vertical.
7
7
  *
8
- * ```ts
9
- * const t = await bootModuleApp(({ connection }) => [
10
- * createAccountingModule({ connection, permissions }),
11
- * ]);
12
- * const res = await t.app.inject({ method: 'GET', url: '/accounting/accounts' });
13
- * await t.close();
14
- * ```
8
+ * const t = await bootModuleApp(({ connection }) => [
9
+ * createAccountingModule({ connection, country, permissions }),
10
+ * ]);
11
+ * const res = await t.app.inject({ method: 'GET', url: '/accounting/accounts' });
12
+ * const engine = t.exports<AccountingEngine>('accounting'); // typed module export
13
+ * await t.close();
15
14
  *
16
- * This is a thin generic core: `bootModuleApp` resolves the module list, opens a
17
- * database via a pluggable **backend**, and boots arc around it. The default
18
- * backend is `mongoMemoryBackend()` from `@classytic/mongokit/testkit` — loaded
19
- * via dynamic `import()` so `@classytic/mongokit` + `mongodb-memory-server` stay
20
- * OPTIONAL peers (needed only when you use the default backend). Pass your own
21
- * `backend` — e.g. one pointed at a shared server, or a real Atlas cluster — to
22
- * override it.
23
- *
24
- * Modules usually need the live DB connection in their deps, so the primary
25
- * input is a FACTORY receiving `{ connection, mongoUri }`. Plain module lists
26
- * are also accepted.
15
+ * Since arc 2.22 the harness itself lives in `@classytic/arc/testing`
16
+ * (upstreamed from this package — default-connection ownership, boot-failure
17
+ * cleanup, idempotent close, the typed `exports()` accessor, `sensible: false`
18
+ * and all). This package is now the MONGO-TYPED face of it: arc core stays
19
+ * DB-agnostic (`connection: unknown` generic), the module fleet is Mongoose —
20
+ * the wrapper pins `TConn = Connection` once so every module test gets a typed
21
+ * connection with zero casts.
27
22
  */
28
- /** Load the default backend lazily so mongokit + memory-server stay optional. */
29
- async function defaultBackend(replset) {
30
- try {
31
- const { mongoMemoryBackend } = await import("@classytic/mongokit/testkit");
32
- return mongoMemoryBackend({ replset });
33
- } catch (err) {
34
- throw new Error(`[arc-testkit] the default backend needs \`@classytic/mongokit\` (>=3.19.0) and \`mongodb-memory-server\` installed as devDependencies. Install them, or pass your own \`backend\` to bootModuleApp. Original error: ${err.message}`);
35
- }
36
- }
37
- async function bootModuleApp(modules, options = {}) {
38
- const { ctx, teardown } = await (options.backend ?? await defaultBackend(options.replset ?? false)).setup();
39
- const testkitCtx = {
40
- connection: ctx.connection,
41
- mongoUri: ctx.uri
42
- };
43
- const resolved = typeof modules === "function" ? await modules(testkitCtx) : modules;
44
- const list = Array.isArray(resolved) ? resolved : [resolved];
45
- let app;
46
- try {
47
- app = await createApp({
48
- preset: "testing",
49
- auth: false,
50
- sensible: false,
51
- ...options.app,
52
- modules: list
53
- });
54
- await app.ready();
55
- } catch (err) {
56
- await teardown().catch(() => void 0);
57
- throw err;
58
- }
59
- let closed = false;
60
- return {
61
- app,
62
- connection: ctx.connection,
63
- mongoUri: ctx.uri,
64
- close: async () => {
65
- if (closed) return;
66
- closed = true;
67
- await app.close().catch(() => void 0);
68
- await teardown();
69
- }
70
- };
23
+ function bootModuleApp(modules, options = {}) {
24
+ return bootModuleApp$1(modules, options);
71
25
  }
72
26
  //#endregion
73
27
  export { bootModuleApp };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@classytic/arc-testkit",
3
- "version": "0.1.0",
4
- "description": "Boot a real @classytic/arc app around the module(s) under test on in-memory MongoDB — the ecosystem test harness. If your arc module boots green here, it composes into any arc host.",
3
+ "version": "0.1.2",
4
+ "description": "Boot a real @classytic/arc app around the module(s) under test on in-memory MongoDB — the ecosystem test harness. Thin Mongo-typed wrapper over @classytic/arc/testing (arc 2.22+). If your arc module boots green here, it composes into any arc host.",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -28,24 +28,13 @@
28
28
  "lint": "biome check src/",
29
29
  "prepublishOnly": "node ../../scripts/prepublish-gate.mjs"
30
30
  },
31
+ "dependencies": {
32
+ "mongodb-memory-server": ">=10.0.0"
33
+ },
31
34
  "peerDependencies": {
32
- "@classytic/arc": ">=2.20.0",
33
- "@classytic/mongokit": ">=3.19.0",
34
- "fastify": ">=5.0.0",
35
- "mongodb-memory-server": ">=10.0.0",
35
+ "@classytic/arc": ">=2.22.0",
36
36
  "mongoose": ">=9.4.1"
37
37
  },
38
- "peerDependenciesMeta": {
39
- "@classytic/mongokit": {
40
- "optional": true
41
- },
42
- "mongodb-memory-server": {
43
- "optional": true
44
- },
45
- "mongoose": {
46
- "optional": true
47
- }
48
- },
49
38
  "keywords": [
50
39
  "arc",
51
40
  "fastify",