@forinda/kickjs-testing 3.0.6 → 3.0.8

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,23 +1,23 @@
1
1
 
2
2
  import express from "express";
3
- import { AppAdapter, AppModuleClass, Application, Container, ModuleRoutes } from "@forinda/kickjs";
3
+ import { AppAdapter, AppModuleClass, Application, ApplicationOptions, Container, ModuleRoutes } from "@forinda/kickjs";
4
4
 
5
5
  //#region src/index.d.ts
6
+ /**
7
+ * Bootstrap options forwarded verbatim to the underlying Application so
8
+ * test apps exercise the same HTTP pipeline shape as production.
9
+ */
10
+ type BootstrapPassthroughOptions = Pick<ApplicationOptions, 'port' | 'apiPrefix' | 'defaultVersion' | 'middleware' | 'onError' | 'onNotFound' | 'plugins' | 'trustProxy' | 'jsonLimit' | 'security'>;
6
11
  /**
7
12
  * Options for creating a test application.
8
13
  * Disables helmet, cors, compression, and morgan by default.
9
14
  */
10
- interface CreateTestAppOptions {
15
+ interface CreateTestAppOptions extends BootstrapPassthroughOptions {
11
16
  modules: AppModuleClass[];
12
17
  /** Adapters to attach (auth, queue, devtools, etc.) */
13
18
  adapters?: AppAdapter[];
14
19
  /** DI overrides applied after module registration. Supports both string and symbol keys. */
15
20
  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
21
  /**
22
22
  * Use an isolated container instead of the global singleton.
23
23
  * Prevents concurrent tests from interfering with each other's DI state.
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;AASwB;;KAMnB,2BAAA,GAA8B,IAAA,CACjC,kBAAA;;;AAiBF;;UAAiB,oBAAA,SAA6B,2BAAA;EAC5C,OAAA,EAAS,cAAA;EAEE;EAAX,QAAA,GAAW,UAAA;EAHiC;EAK5C,SAAA,GAAY,MAAA;EAL2D;;;;;EAWvE,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;;;;;;;;AA0Eb;;;;;;;;iBAAgB,gBAAA,CAAiB,MAAA;EAC/B,QAAA,GAAW,SAAA,EAAW,SAAA;EACtB,MAAA,QAAc,YAAA,GAAe,YAAA;AAAA,IAC3B,cAAA"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs-testing v3.0.6
2
+ * @forinda/kickjs-testing v3.0.8
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -38,7 +38,13 @@ async function createTestApp(options) {
38
38
  port: options.port,
39
39
  apiPrefix: options.apiPrefix,
40
40
  defaultVersion: options.defaultVersion,
41
- middleware: options.middleware ?? [express.json()]
41
+ middleware: options.middleware ?? [express.json()],
42
+ onError: options.onError,
43
+ onNotFound: options.onNotFound,
44
+ plugins: options.plugins,
45
+ trustProxy: options.trustProxy,
46
+ jsonLimit: options.jsonLimit,
47
+ security: options.security
42
48
  });
43
49
  await Promise.resolve(app.setup());
44
50
  if (options.isolated) {
@@ -1 +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"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import express from 'express'\nimport {\n Application,\n Container,\n type AppAdapter,\n type AppModule,\n type AppModuleClass,\n type ApplicationOptions,\n type ModuleRoutes,\n} from '@forinda/kickjs'\n\n/**\n * Bootstrap options forwarded verbatim to the underlying Application so\n * test apps exercise the same HTTP pipeline shape as production.\n */\ntype BootstrapPassthroughOptions = Pick<\n ApplicationOptions,\n | 'port'\n | 'apiPrefix'\n | 'defaultVersion'\n | 'middleware'\n | 'onError'\n | 'onNotFound'\n | 'plugins'\n | 'trustProxy'\n | 'jsonLimit'\n | 'security'\n>\n\n/**\n * Options for creating a test application.\n * Disables helmet, cors, compression, and morgan by default.\n */\nexport interface CreateTestAppOptions extends BootstrapPassthroughOptions {\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 /**\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 onError: options.onError,\n onNotFound: options.onNotFound,\n plugins: options.plugins,\n trustProxy: options.trustProxy,\n jsonLimit: options.jsonLimit,\n security: options.security,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,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;EAClD,SAAS,QAAQ;EACjB,YAAY,QAAQ;EACpB,SAAS,QAAQ;EACjB,YAAY,QAAQ;EACpB,WAAW,QAAQ;EACnB,UAAU,QAAQ;EACnB,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": "3.0.6",
3
+ "version": "3.0.8",
4
4
  "description": "Test utilities, TestModule builder, and helpers for KickJS applications",
5
5
  "keywords": [
6
6
  "kickjs",
@@ -78,10 +78,13 @@
78
78
  "@swc/core": "^1.15.21",
79
79
  "@types/express": "^5.0.6",
80
80
  "@types/node": "^25.0.0",
81
+ "@types/supertest": "^6.0.3",
81
82
  "express": "^5.1.0",
83
+ "reflect-metadata": "^0.2.2",
84
+ "supertest": "^7.2.2",
82
85
  "typescript": "^5.9.2",
83
86
  "vitest": "^4.1.2",
84
- "@forinda/kickjs": "3.0.6"
87
+ "@forinda/kickjs": "3.0.8"
85
88
  },
86
89
  "publishConfig": {
87
90
  "access": "public"