@forinda/kickjs-testing 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Felix Orinda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,34 @@
1
+ import { AppModuleClass, Container, ModuleRoutes } from '@forinda/kickjs-core';
2
+ import { Application } from '@forinda/kickjs-http';
3
+
4
+ /**
5
+ * Options for creating a test application.
6
+ * Disables helmet, cors, compression, and morgan by default.
7
+ */
8
+ interface CreateTestAppOptions {
9
+ modules: AppModuleClass[];
10
+ overrides?: Record<symbol | string, any>;
11
+ port?: number;
12
+ apiPrefix?: string;
13
+ defaultVersion?: number;
14
+ }
15
+ /**
16
+ * Create an Application instance configured for testing.
17
+ * Resets the DI container, registers modules, applies overrides,
18
+ * and returns both the Application and its Express app.
19
+ */
20
+ declare function createTestApp(options: CreateTestAppOptions): {
21
+ app: Application;
22
+ expressApp: any;
23
+ container: Container;
24
+ };
25
+ /**
26
+ * Build a quick TestModule that explicitly registers dependencies.
27
+ * Useful for integration tests that need to control the DI graph.
28
+ */
29
+ declare function createTestModule(config: {
30
+ register: (container: Container) => void;
31
+ routes: () => ModuleRoutes | ModuleRoutes[];
32
+ }): AppModuleClass;
33
+
34
+ export { type CreateTestAppOptions, createTestApp, createTestModule };
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/index.ts
5
+ import { Container } from "@forinda/kickjs-core";
6
+ import { Application } from "@forinda/kickjs-http";
7
+ function createTestApp(options) {
8
+ Container.reset();
9
+ const container = Container.getInstance();
10
+ const app = new Application({
11
+ modules: options.modules,
12
+ port: options.port,
13
+ apiPrefix: options.apiPrefix,
14
+ defaultVersion: options.defaultVersion,
15
+ // Use minimal middleware for testing — no helmet, cors, compression, etc.
16
+ middleware: []
17
+ });
18
+ if (options.overrides) {
19
+ for (const token of Reflect.ownKeys(options.overrides)) {
20
+ container.registerInstance(token, options.overrides[token]);
21
+ }
22
+ }
23
+ app.setup();
24
+ return {
25
+ app,
26
+ expressApp: app.getExpressApp(),
27
+ container
28
+ };
29
+ }
30
+ __name(createTestApp, "createTestApp");
31
+ function createTestModule(config) {
32
+ return class TestModule {
33
+ static {
34
+ __name(this, "TestModule");
35
+ }
36
+ register(container) {
37
+ config.register(container);
38
+ }
39
+ routes() {
40
+ return config.routes();
41
+ }
42
+ };
43
+ }
44
+ __name(createTestModule, "createTestModule");
45
+ export {
46
+ createTestApp,
47
+ createTestModule
48
+ };
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n Container,\n type AppModule,\n type AppModuleClass,\n type ModuleRoutes,\n} from '@forinda/kickjs-core'\nimport { Application, type ApplicationOptions } from '@forinda/kickjs-http'\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 overrides?: Record<symbol | string, any>\n port?: number\n apiPrefix?: string\n defaultVersion?: number\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 */\nexport function createTestApp(options: CreateTestAppOptions): {\n app: Application\n expressApp: any\n container: Container\n} {\n Container.reset()\n const container = Container.getInstance()\n\n const app = new Application({\n modules: options.modules,\n port: options.port,\n apiPrefix: options.apiPrefix,\n defaultVersion: options.defaultVersion,\n // Use minimal middleware for testing — no helmet, cors, compression, etc.\n middleware: [],\n })\n\n // Apply DI overrides (e.g. mock repositories)\n // Use Reflect.ownKeys to iterate both string and symbol keys\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 // Run setup without starting the HTTP server\n app.setup()\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 */\nexport function createTestModule(config: {\n register: (container: Container) => void\n routes: () => ModuleRoutes | ModuleRoutes[]\n}): AppModuleClass {\n return class TestModule implements AppModule {\n register(container: Container) {\n config.register(container)\n }\n routes() {\n return config.routes()\n }\n } as AppModuleClass\n}\n"],"mappings":";;;;AAAA,SACEA,iBAIK;AACP,SAASC,mBAA4C;AAmB9C,SAASC,cAAcC,SAA6B;AAKzDC,YAAUC,MAAK;AACf,QAAMC,YAAYF,UAAUG,YAAW;AAEvC,QAAMC,MAAM,IAAIC,YAAY;IAC1BC,SAASP,QAAQO;IACjBC,MAAMR,QAAQQ;IACdC,WAAWT,QAAQS;IACnBC,gBAAgBV,QAAQU;;IAExBC,YAAY,CAAA;EACd,CAAA;AAIA,MAAIX,QAAQY,WAAW;AACrB,eAAWC,SAASC,QAAQC,QAAQf,QAAQY,SAAS,GAAG;AACtDT,gBAAUa,iBAAiBH,OAAOb,QAAQY,UAAUC,KAAAA,CAAa;IACnE;EACF;AAGAR,MAAIY,MAAK;AAET,SAAO;IACLZ;IACAa,YAAYb,IAAIc,cAAa;IAC7BhB;EACF;AACF;AAjCgBJ;AAuCT,SAASqB,iBAAiBC,QAGhC;AACC,SAAO,MAAMC,WAAAA;IApEf,OAoEeA;;;IACXC,SAASpB,WAAsB;AAC7BkB,aAAOE,SAASpB,SAAAA;IAClB;IACAqB,SAAS;AACP,aAAOH,OAAOG,OAAM;IACtB;EACF;AACF;AAZgBJ;","names":["Container","Application","createTestApp","options","Container","reset","container","getInstance","app","Application","modules","port","apiPrefix","defaultVersion","middleware","overrides","token","Reflect","ownKeys","registerInstance","setup","expressApp","getExpressApp","createTestModule","config","TestModule","register","routes"]}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@forinda/kickjs-testing",
3
+ "version": "0.3.0",
4
+ "description": "Test utilities, TestModule builder, and helpers for KickJS applications",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "dependencies": {
18
+ "@forinda/kickjs-core": "0.3.0",
19
+ "@forinda/kickjs-http": "0.3.0"
20
+ },
21
+ "devDependencies": {
22
+ "@swc/core": "^1.7.28",
23
+ "@types/express": "^5.0.6",
24
+ "@types/node": "^24.5.2",
25
+ "express": "^5.1.0",
26
+ "tsup": "^8.5.0",
27
+ "typescript": "^5.9.2",
28
+ "vitest": "^3.2.4"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "license": "MIT",
34
+ "author": "Felix Orinda",
35
+ "engines": {
36
+ "node": ">=20.0"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "dev": "tsup --watch",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest",
43
+ "typecheck": "tsc --noEmit",
44
+ "clean": "rm -rf dist .turbo",
45
+ "lint": "tsc --noEmit"
46
+ }
47
+ }