@forinda/kickjs-testing 1.3.2 → 1.4.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/dist/index.d.ts +37 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -1
- package/package.json +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,64 @@
|
|
|
1
|
-
import
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { Container, type AppAdapter, type AppModuleClass, type ModuleRoutes } from '@forinda/kickjs-core';
|
|
2
3
|
import { Application } from '@forinda/kickjs-http';
|
|
3
|
-
|
|
4
4
|
/**
|
|
5
5
|
* Options for creating a test application.
|
|
6
6
|
* Disables helmet, cors, compression, and morgan by default.
|
|
7
7
|
*/
|
|
8
|
-
interface CreateTestAppOptions {
|
|
8
|
+
export interface CreateTestAppOptions {
|
|
9
9
|
modules: AppModuleClass[];
|
|
10
10
|
/** Adapters to attach (auth, queue, devtools, etc.) */
|
|
11
11
|
adapters?: AppAdapter[];
|
|
12
|
+
/** DI overrides applied after module registration. Supports both string and symbol keys. */
|
|
12
13
|
overrides?: Record<symbol | string, any>;
|
|
13
14
|
port?: number;
|
|
14
15
|
apiPrefix?: string;
|
|
15
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;
|
|
16
25
|
}
|
|
17
26
|
/**
|
|
18
27
|
* Create an Application instance configured for testing.
|
|
19
28
|
* Resets the DI container, registers modules, applies overrides,
|
|
20
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
|
+
* ```
|
|
21
39
|
*/
|
|
22
|
-
declare function createTestApp(options: CreateTestAppOptions): {
|
|
40
|
+
export declare function createTestApp(options: CreateTestAppOptions): Promise<{
|
|
23
41
|
app: Application;
|
|
24
|
-
expressApp:
|
|
42
|
+
expressApp: express.Express;
|
|
25
43
|
container: Container;
|
|
26
|
-
}
|
|
44
|
+
}>;
|
|
27
45
|
/**
|
|
28
46
|
* Build a quick TestModule that explicitly registers dependencies.
|
|
29
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
|
+
* ```
|
|
30
59
|
*/
|
|
31
|
-
declare function createTestModule(config: {
|
|
60
|
+
export declare function createTestModule(config: {
|
|
32
61
|
register: (container: Container) => void;
|
|
33
62
|
routes: () => ModuleRoutes | ModuleRoutes[] | null;
|
|
34
63
|
}): AppModuleClass;
|
|
35
|
-
|
|
36
|
-
export { type CreateTestAppOptions, createTestApp, createTestModule };
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,sBAAsB,CAAA;AAC7B,OAAO,EAAE,WAAW,EAA2B,MAAM,sBAAsB,CAAA;AAE3E;;;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
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import i from "express";
|
|
2
|
+
import { Container as s } from "@forinda/kickjs-core";
|
|
3
|
+
import { Application as d } from "@forinda/kickjs-http";
|
|
4
|
+
async function p(e) {
|
|
5
|
+
let r;
|
|
6
|
+
e.isolated ? r = s.create() : (s.reset(), r = s.getInstance());
|
|
7
|
+
const t = new d({
|
|
8
|
+
modules: e.modules,
|
|
9
|
+
adapters: e.adapters,
|
|
10
|
+
port: e.port,
|
|
11
|
+
apiPrefix: e.apiPrefix,
|
|
12
|
+
defaultVersion: e.defaultVersion,
|
|
13
|
+
middleware: e.middleware ?? [i.json()]
|
|
14
|
+
});
|
|
15
|
+
if (await Promise.resolve(t.setup()), e.overrides) for (const a of Reflect.ownKeys(e.overrides)) r.registerInstance(a, e.overrides[a]);
|
|
16
|
+
return {
|
|
17
|
+
app: t,
|
|
18
|
+
expressApp: t.getExpressApp(),
|
|
19
|
+
container: r
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function c(e) {
|
|
23
|
+
return class {
|
|
24
|
+
register(t) {
|
|
25
|
+
e.register(t);
|
|
26
|
+
}
|
|
27
|
+
routes() {
|
|
28
|
+
return e.routes();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
p as createTestApp,
|
|
34
|
+
c as createTestModule
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forinda/kickjs-testing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Test utilities, TestModule builder, and helpers for KickJS applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kickjs",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"@forinda/kickjs-queue",
|
|
34
34
|
"@forinda/kickjs-multi-tenant",
|
|
35
35
|
"@forinda/kickjs-devtools",
|
|
36
|
-
"@forinda/kickjs-notifications"
|
|
36
|
+
"@forinda/kickjs-notifications",
|
|
37
|
+
"vite"
|
|
37
38
|
],
|
|
38
39
|
"type": "module",
|
|
39
40
|
"main": "dist/index.js",
|
|
@@ -48,8 +49,8 @@
|
|
|
48
49
|
"dist"
|
|
49
50
|
],
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@forinda/kickjs-core": "1.
|
|
52
|
-
"@forinda/kickjs-http": "1.
|
|
52
|
+
"@forinda/kickjs-core": "1.4.0",
|
|
53
|
+
"@forinda/kickjs-http": "1.4.0"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
56
|
"express": "^5.1.0"
|
|
@@ -59,7 +60,6 @@
|
|
|
59
60
|
"@types/express": "^5.0.6",
|
|
60
61
|
"@types/node": "^24.5.2",
|
|
61
62
|
"express": "^5.1.0",
|
|
62
|
-
"tsup": "^8.5.0",
|
|
63
63
|
"typescript": "^5.9.2",
|
|
64
64
|
"vitest": "^3.2.4"
|
|
65
65
|
},
|
|
@@ -81,8 +81,9 @@
|
|
|
81
81
|
"url": "https://github.com/forinda/kick-js/issues"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
|
-
"build": "
|
|
85
|
-
"
|
|
84
|
+
"build": "vite build && pnpm build:types",
|
|
85
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
86
|
+
"dev": "vite build --watch",
|
|
86
87
|
"test": "vitest run --passWithNoTests",
|
|
87
88
|
"test:watch": "vitest",
|
|
88
89
|
"typecheck": "tsc --noEmit",
|