@forinda/kickjs-testing 2.0.1 → 2.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.
@@ -0,0 +1,68 @@
1
+
2
+ import express from "express";
3
+ import { AppAdapter, AppModuleClass, Application, Container, ModuleRoutes } from "@forinda/kickjs";
4
+
5
+ //#region src/index.d.ts
6
+ /**
7
+ * Options for creating a test application.
8
+ * Disables helmet, cors, compression, and morgan by default.
9
+ */
10
+ interface CreateTestAppOptions {
11
+ modules: AppModuleClass[];
12
+ /** Adapters to attach (auth, queue, devtools, etc.) */
13
+ adapters?: AppAdapter[];
14
+ /** DI overrides applied after module registration. Supports both string and symbol keys. */
15
+ overrides?: Record<symbol | string, any>;
16
+ port?: number;
17
+ apiPrefix?: string;
18
+ defaultVersion?: number;
19
+ /** Express middleware pipeline. When provided, replaces the default (express.json()). */
20
+ middleware?: express.RequestHandler[];
21
+ /**
22
+ * Use an isolated container instead of the global singleton.
23
+ * Prevents concurrent tests from interfering with each other's DI state.
24
+ * When true, Container.create() is used instead of Container.reset() + getInstance().
25
+ */
26
+ isolated?: boolean;
27
+ }
28
+ /**
29
+ * Create an Application instance configured for testing.
30
+ * Resets the DI container, registers modules, applies overrides,
31
+ * and returns both the Application and its Express app.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const { expressApp, container } = await createTestApp({
36
+ * modules: [UserModule],
37
+ * overrides: { [USER_REPO]: new InMemoryUserRepo() },
38
+ * })
39
+ * const res = await request(expressApp).get('/api/v1/users')
40
+ * ```
41
+ */
42
+ declare function createTestApp(options: CreateTestAppOptions): Promise<{
43
+ app: Application;
44
+ expressApp: express.Express;
45
+ container: Container;
46
+ }>;
47
+ /**
48
+ * Build a quick TestModule that explicitly registers dependencies.
49
+ * Useful for integration tests that need to control the DI graph.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const TestModule = createTestModule({
54
+ * register: (c) => {
55
+ * c.registerFactory(USER_REPO, () => new InMemoryUserRepo())
56
+ * c.register(UserController)
57
+ * },
58
+ * routes: () => buildRoutes(UserController, '/users'),
59
+ * })
60
+ * ```
61
+ */
62
+ declare function createTestModule(config: {
63
+ register: (container: Container) => void;
64
+ routes: () => ModuleRoutes | ModuleRoutes[] | null;
65
+ }): AppModuleClass;
66
+ //#endregion
67
+ export { CreateTestAppOptions, createTestApp, createTestModule };
68
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;AAcA;;;UAAiB,oBAAA;EACf,OAAA,EAAS,cAAA;EAIG;EAFZ,QAAA,GAAW,UAAA;EAOwB;EALnC,SAAA,GAAY,MAAA;EACZ,IAAA;EACA,SAAA;EACA,cAAA;EALW;EAOX,UAAA,GAAa,OAAA,CAAQ,cAAA;EALT;;;;;EAWZ,QAAA;AAAA;;;;AAiBF;;;;;;;;;;;iBAAsB,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA;EAClE,GAAA,EAAK,WAAA;EACL,UAAA,EAAY,OAAA,CAAQ,OAAA;EACpB,SAAA,EAAW,SAAA;AAAA;;;;;;;AAoEb;;;;;;;;;iBAAgB,gBAAA,CAAiB,MAAA;EAC/B,QAAA,GAAW,SAAA,EAAW,SAAA;EACtB,MAAA,QAAc,YAAA,GAAe,YAAA;AAAA,IAC3B,cAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @forinda/kickjs-testing v2.2.0
3
+ *
4
+ * Copyright (c) Felix Orinda
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import express from "express";
12
+ import { Application, Container } from "@forinda/kickjs";
13
+ //#region src/index.ts
14
+ /**
15
+ * Create an Application instance configured for testing.
16
+ * Resets the DI container, registers modules, applies overrides,
17
+ * and returns both the Application and its Express app.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const { expressApp, container } = await createTestApp({
22
+ * modules: [UserModule],
23
+ * overrides: { [USER_REPO]: new InMemoryUserRepo() },
24
+ * })
25
+ * const res = await request(expressApp).get('/api/v1/users')
26
+ * ```
27
+ */
28
+ async function createTestApp(options) {
29
+ let container;
30
+ if (options.isolated) container = Container.create();
31
+ else {
32
+ Container.reset();
33
+ container = Container.getInstance();
34
+ }
35
+ const app = new Application({
36
+ modules: options.modules,
37
+ adapters: options.adapters,
38
+ port: options.port,
39
+ apiPrefix: options.apiPrefix,
40
+ defaultVersion: options.defaultVersion,
41
+ middleware: options.middleware ?? [express.json()]
42
+ });
43
+ await Promise.resolve(app.setup());
44
+ if (options.isolated) {
45
+ for (const ModuleClass of options.modules) new ModuleClass().register?.(container);
46
+ container.bootstrap();
47
+ }
48
+ if (options.overrides) for (const token of Reflect.ownKeys(options.overrides)) container.registerInstance(token, options.overrides[token]);
49
+ return {
50
+ app,
51
+ expressApp: app.getExpressApp(),
52
+ container
53
+ };
54
+ }
55
+ /**
56
+ * Build a quick TestModule that explicitly registers dependencies.
57
+ * Useful for integration tests that need to control the DI graph.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const TestModule = createTestModule({
62
+ * register: (c) => {
63
+ * c.registerFactory(USER_REPO, () => new InMemoryUserRepo())
64
+ * c.register(UserController)
65
+ * },
66
+ * routes: () => buildRoutes(UserController, '/users'),
67
+ * })
68
+ * ```
69
+ */
70
+ function createTestModule(config) {
71
+ class TestModule {
72
+ register(container) {
73
+ config.register(container);
74
+ }
75
+ routes() {
76
+ return config.routes();
77
+ }
78
+ }
79
+ return TestModule;
80
+ }
81
+ //#endregion
82
+ export { createTestApp, createTestModule };
83
+
84
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import express from 'express'\nimport {\n Container,\n type AppAdapter,\n type AppModule,\n type AppModuleClass,\n type ModuleRoutes,\n} from '@forinda/kickjs'\nimport { Application, type ApplicationOptions } from '@forinda/kickjs'\n\n/**\n * Options for creating a test application.\n * Disables helmet, cors, compression, and morgan by default.\n */\nexport interface CreateTestAppOptions {\n modules: AppModuleClass[]\n /** Adapters to attach (auth, queue, devtools, etc.) */\n adapters?: AppAdapter[]\n /** DI overrides applied after module registration. Supports both string and symbol keys. */\n overrides?: Record<symbol | string, any>\n port?: number\n apiPrefix?: string\n defaultVersion?: number\n /** Express middleware pipeline. When provided, replaces the default (express.json()). */\n middleware?: express.RequestHandler[]\n /**\n * Use an isolated container instead of the global singleton.\n * Prevents concurrent tests from interfering with each other's DI state.\n * When true, Container.create() is used instead of Container.reset() + getInstance().\n */\n isolated?: boolean\n}\n\n/**\n * Create an Application instance configured for testing.\n * Resets the DI container, registers modules, applies overrides,\n * and returns both the Application and its Express app.\n *\n * @example\n * ```ts\n * const { expressApp, container } = await createTestApp({\n * modules: [UserModule],\n * overrides: { [USER_REPO]: new InMemoryUserRepo() },\n * })\n * const res = await request(expressApp).get('/api/v1/users')\n * ```\n */\nexport async function createTestApp(options: CreateTestAppOptions): Promise<{\n app: Application\n expressApp: express.Express\n container: Container\n}> {\n let container: Container\n if (options.isolated) {\n // Isolated container — safe for concurrent tests\n container = Container.create()\n } else {\n // Global singleton — reset for serial test isolation (default)\n Container.reset()\n container = Container.getInstance()\n }\n\n const app = new Application({\n modules: options.modules,\n adapters: options.adapters,\n port: options.port,\n apiPrefix: options.apiPrefix,\n defaultVersion: options.defaultVersion,\n // Use provided middleware, or default to JSON body parsing only\n middleware: options.middleware ?? [express.json()],\n })\n\n // Run setup — mounts routes, registers modules, initializes adapters.\n // Awaited to support future async adapter hooks.\n await Promise.resolve(app.setup())\n\n // When using an isolated container, Application.setup() registers modules\n // on the global singleton (Container.getInstance()). Re-register them on\n // the isolated container so that bindings are available there too.\n if (options.isolated) {\n for (const ModuleClass of options.modules) {\n const mod = new ModuleClass()\n // register() is optional — see AppModule docs\n mod.register?.(container)\n }\n container.bootstrap()\n }\n\n // Apply DI overrides AFTER setup so they take precedence over\n // bindings registered by modules during register().\n if (options.overrides) {\n for (const token of Reflect.ownKeys(options.overrides)) {\n container.registerInstance(token, options.overrides[token as any])\n }\n }\n\n return {\n app,\n expressApp: app.getExpressApp(),\n container,\n }\n}\n\n/**\n * Build a quick TestModule that explicitly registers dependencies.\n * Useful for integration tests that need to control the DI graph.\n *\n * @example\n * ```ts\n * const TestModule = createTestModule({\n * register: (c) => {\n * c.registerFactory(USER_REPO, () => new InMemoryUserRepo())\n * c.register(UserController)\n * },\n * routes: () => buildRoutes(UserController, '/users'),\n * })\n * ```\n */\nexport function createTestModule(config: {\n register: (container: Container) => void\n routes: () => ModuleRoutes | ModuleRoutes[] | null\n}): AppModuleClass {\n class TestModule implements AppModule {\n register(container: Container) {\n config.register(container)\n }\n routes() {\n return config.routes()\n }\n }\n return TestModule\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,eAAsB,cAAc,SAIjC;CACD,IAAI;AACJ,KAAI,QAAQ,SAEV,aAAY,UAAU,QAAQ;MACzB;AAEL,YAAU,OAAO;AACjB,cAAY,UAAU,aAAa;;CAGrC,MAAM,MAAM,IAAI,YAAY;EAC1B,SAAS,QAAQ;EACjB,UAAU,QAAQ;EAClB,MAAM,QAAQ;EACd,WAAW,QAAQ;EACnB,gBAAgB,QAAQ;EAExB,YAAY,QAAQ,cAAc,CAAC,QAAQ,MAAM,CAAC;EACnD,CAAC;AAIF,OAAM,QAAQ,QAAQ,IAAI,OAAO,CAAC;AAKlC,KAAI,QAAQ,UAAU;AACpB,OAAK,MAAM,eAAe,QAAQ,QACpB,KAAI,aAAa,CAEzB,WAAW,UAAU;AAE3B,YAAU,WAAW;;AAKvB,KAAI,QAAQ,UACV,MAAK,MAAM,SAAS,QAAQ,QAAQ,QAAQ,UAAU,CACpD,WAAU,iBAAiB,OAAO,QAAQ,UAAU,OAAc;AAItE,QAAO;EACL;EACA,YAAY,IAAI,eAAe;EAC/B;EACD;;;;;;;;;;;;;;;;;AAkBH,SAAgB,iBAAiB,QAGd;CACjB,MAAM,WAAgC;EACpC,SAAS,WAAsB;AAC7B,UAAO,SAAS,UAAU;;EAE5B,SAAS;AACP,UAAO,OAAO,QAAQ;;;AAG1B,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forinda/kickjs-testing",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "Test utilities, TestModule builder, and helpers for KickJS applications",
5
5
  "keywords": [
6
6
  "kickjs",
@@ -37,30 +37,48 @@
37
37
  "vite"
38
38
  ],
39
39
  "type": "module",
40
- "main": "dist/index.js",
41
- "types": "dist/index.d.ts",
40
+ "main": "dist/index.mjs",
41
+ "types": "dist/index.d.mts",
42
42
  "exports": {
43
43
  ".": {
44
- "import": "./dist/index.js",
45
- "types": "./dist/index.d.ts"
44
+ "import": "./dist/index.mjs",
45
+ "types": "./dist/index.d.mts"
46
46
  }
47
47
  },
48
48
  "files": [
49
49
  "dist"
50
50
  ],
51
+ "wireit": {
52
+ "build": {
53
+ "command": "tsdown",
54
+ "files": [
55
+ "src/**/*.ts",
56
+ "tsdown.config.ts",
57
+ "tsconfig.json",
58
+ "package.json"
59
+ ],
60
+ "output": [
61
+ "dist/**"
62
+ ],
63
+ "dependencies": [
64
+ "../core:build",
65
+ "../http:build"
66
+ ]
67
+ }
68
+ },
51
69
  "dependencies": {
52
- "@forinda/kickjs": "2.0.1"
70
+ "@forinda/kickjs": "2.2.0"
53
71
  },
54
72
  "peerDependencies": {
55
73
  "express": "^5.1.0"
56
74
  },
57
75
  "devDependencies": {
58
- "@swc/core": "^1.7.28",
76
+ "@swc/core": "^1.15.21",
59
77
  "@types/express": "^5.0.6",
60
78
  "@types/node": "^25.0.0",
61
79
  "express": "^5.1.0",
62
80
  "typescript": "^5.9.2",
63
- "vitest": "^4.1.1"
81
+ "vitest": "^4.1.2"
64
82
  },
65
83
  "publishConfig": {
66
84
  "access": "public"
@@ -80,13 +98,12 @@
80
98
  "url": "https://github.com/forinda/kick-js/issues"
81
99
  },
82
100
  "scripts": {
83
- "build": "vite build && pnpm build:types",
84
- "build:types": "tsc -p tsconfig.build.json",
85
- "dev": "vite build --watch",
101
+ "build": "wireit",
102
+ "dev": "tsdown --watch",
86
103
  "test": "vitest run --passWithNoTests",
87
104
  "test:watch": "vitest",
88
105
  "typecheck": "tsc --noEmit",
89
- "clean": "rm -rf dist .turbo",
106
+ "clean": "rm -rf dist .wireit",
90
107
  "lint": "tsc --noEmit"
91
108
  }
92
109
  }
package/dist/index.d.ts DELETED
@@ -1,64 +0,0 @@
1
- import express from 'express';
2
- import { Container, type AppAdapter, type AppModuleClass, type ModuleRoutes } from '@forinda/kickjs';
3
- import { Application } from '@forinda/kickjs';
4
- /**
5
- * Options for creating a test application.
6
- * Disables helmet, cors, compression, and morgan by default.
7
- */
8
- export interface CreateTestAppOptions {
9
- modules: AppModuleClass[];
10
- /** Adapters to attach (auth, queue, devtools, etc.) */
11
- adapters?: AppAdapter[];
12
- /** DI overrides applied after module registration. Supports both string and symbol keys. */
13
- overrides?: Record<symbol | string, any>;
14
- port?: number;
15
- apiPrefix?: string;
16
- defaultVersion?: number;
17
- /** Express middleware pipeline. When provided, replaces the default (express.json()). */
18
- middleware?: express.RequestHandler[];
19
- /**
20
- * Use an isolated container instead of the global singleton.
21
- * Prevents concurrent tests from interfering with each other's DI state.
22
- * When true, Container.create() is used instead of Container.reset() + getInstance().
23
- */
24
- isolated?: boolean;
25
- }
26
- /**
27
- * Create an Application instance configured for testing.
28
- * Resets the DI container, registers modules, applies overrides,
29
- * and returns both the Application and its Express app.
30
- *
31
- * @example
32
- * ```ts
33
- * const { expressApp, container } = await createTestApp({
34
- * modules: [UserModule],
35
- * overrides: { [USER_REPO]: new InMemoryUserRepo() },
36
- * })
37
- * const res = await request(expressApp).get('/api/v1/users')
38
- * ```
39
- */
40
- export declare function createTestApp(options: CreateTestAppOptions): Promise<{
41
- app: Application;
42
- expressApp: express.Express;
43
- container: Container;
44
- }>;
45
- /**
46
- * Build a quick TestModule that explicitly registers dependencies.
47
- * Useful for integration tests that need to control the DI graph.
48
- *
49
- * @example
50
- * ```ts
51
- * const TestModule = createTestModule({
52
- * register: (c) => {
53
- * c.registerFactory(USER_REPO, () => new InMemoryUserRepo())
54
- * c.register(UserController)
55
- * },
56
- * routes: () => buildRoutes(UserController, '/users'),
57
- * })
58
- * ```
59
- */
60
- export declare function createTestModule(config: {
61
- register: (container: Container) => void;
62
- routes: () => ModuleRoutes | ModuleRoutes[] | null;
63
- }): AppModuleClass;
64
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EACL,SAAS,EACT,KAAK,UAAU,EAEf,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,WAAW,EAA2B,MAAM,iBAAiB,CAAA;AAEtE;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,cAAc,EAAE,CAAA;IACzB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAA;IACvB,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;IACxC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,yFAAyF;IACzF,UAAU,CAAC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAA;IACrC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;IAC1E,GAAG,EAAE,WAAW,CAAA;IAChB,UAAU,EAAE,OAAO,CAAC,OAAO,CAAA;IAC3B,SAAS,EAAE,SAAS,CAAA;CACrB,CAAC,CAsCD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAA;IACxC,MAAM,EAAE,MAAM,YAAY,GAAG,YAAY,EAAE,GAAG,IAAI,CAAA;CACnD,GAAG,cAAc,CASjB"}
package/dist/index.js DELETED
@@ -1,34 +0,0 @@
1
- import i from "express";
2
- import { Application as d, Container as s } from "@forinda/kickjs";
3
- async function o(e) {
4
- let r;
5
- e.isolated ? r = s.create() : (s.reset(), r = s.getInstance());
6
- const t = new d({
7
- modules: e.modules,
8
- adapters: e.adapters,
9
- port: e.port,
10
- apiPrefix: e.apiPrefix,
11
- defaultVersion: e.defaultVersion,
12
- middleware: e.middleware ?? [i.json()]
13
- });
14
- if (await Promise.resolve(t.setup()), e.overrides) for (const a of Reflect.ownKeys(e.overrides)) r.registerInstance(a, e.overrides[a]);
15
- return {
16
- app: t,
17
- expressApp: t.getExpressApp(),
18
- container: r
19
- };
20
- }
21
- function u(e) {
22
- return class {
23
- register(t) {
24
- e.register(t);
25
- }
26
- routes() {
27
- return e.routes();
28
- }
29
- };
30
- }
31
- export {
32
- o as createTestApp,
33
- u as createTestModule
34
- };