@blixis-io/testing 0.0.0 → 0.1.3

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) 2026 Michael Voeten
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.
package/README.md CHANGED
@@ -1 +1,24 @@
1
- placeholder
1
+ # `@blixis-io/testing`
2
+
3
+ A thin testing layer on top of `@blixis-io/http`. Build a real application in a test, override providers with fakes, hit it with real requests.
4
+
5
+ ```bash
6
+ npm install -D @blixis-io/testing
7
+ ```
8
+
9
+ ```ts
10
+ import { Test } from "@blixis-io/testing";
11
+
12
+ const app = await Test.createModule({ imports: [PostsModule] })
13
+ .override(PostRepository, { useValue: fakeRepo })
14
+ .compile();
15
+
16
+ const res = await app.request("/posts");
17
+ expect(res.status).toBe(200);
18
+
19
+ await app.close();
20
+ ```
21
+
22
+ `compile()` builds a full `HttpApplication`, exactly the way `createHttpApplication` would in production — nothing about request handling, validation, or guards is mocked. `.override()` swaps in a fake for one provider before the module graph resolves.
23
+
24
+ Part of [Blixis Framework](https://github.com/blixis-io/framework) — full docs: [Testing](https://blixis-io.github.io/framework/concepts/testing/) · [API reference](https://blixis-io.github.io/framework/reference/blixis-testing/).
@@ -0,0 +1,33 @@
1
+ import { ModuleMetadata } from "@blixis-io/core";
2
+ import { HttpApplication, HttpApplicationOptions } from "@blixis-io/http";
3
+ import { ClassProvider, ExistingProvider, FactoryProvider, Token, ValueProvider } from "@blixis-io/di";
4
+ //#region src/test-application.d.ts
5
+ interface TestRequestInit extends Omit<RequestInit, "body"> {
6
+ body?: RequestInit["body"];
7
+ /** JSON-stringified into the body, with `content-type: application/json` set automatically. */
8
+ json?: unknown;
9
+ }
10
+ /** Thin sugar over `HttpApplication` for tests: a `request()` helper that builds absolute URLs and JSON bodies. */
11
+ export declare class TestApplication {
12
+ private readonly app;
13
+ constructor(app: HttpApplication);
14
+ request(path: string, init?: TestRequestInit): Promise<Response>;
15
+ get<T>(token: Token<T>): T;
16
+ close(signal?: string): Promise<void>;
17
+ }
18
+ //#endregion
19
+ //#region src/test-module-builder.d.ts
20
+ type OverrideDefinition<T> = Omit<ClassProvider<T>, "provide"> | Omit<ValueProvider<T>, "provide"> | Omit<FactoryProvider<T>, "provide"> | Omit<ExistingProvider<T>, "provide">;
21
+ export declare class TestModuleBuilder {
22
+ #private;
23
+ constructor(metadata: ModuleMetadata);
24
+ /** Replaces the provider registered under `token` with `definition`, applied before the module graph resolves. */
25
+ override<T>(token: Token<T>, definition: OverrideDefinition<T>): this;
26
+ compile(options?: Omit<HttpApplicationOptions, "overrides">): Promise<TestApplication>;
27
+ }
28
+ export declare const Test: {
29
+ createModule(metadata?: ModuleMetadata): TestModuleBuilder;
30
+ };
31
+ //#endregion
32
+ export type { OverrideDefinition, TestRequestInit };
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/test-application.ts","../src/test-module-builder.ts"],"mappings":";;;;UAGiB,wBAAwB,KAAK;EAC5C,OAAO;;EAEP;;;qBAMW;mBACkB;EAA7B,YAA6B,KAAK;EAE5B,QAAQ,cAAc,OAAM,kBAAuB,QAAQ;EAejE,IAAI,GAAG,OAAO,MAAM,KAAK;EAInB,MAAM,kBAAkB;;;;KC5BpB,mBAAmB,KAC3B,KAAK,cAAc,iBACnB,KAAK,cAAc,iBACnB,KAAK,gBAAgB,iBACrB,KAAK,iBAAiB;qBAEb;;EAIX,YAAY,UAAU;;EAKtB,SAAS,GAAG,OAAO,MAAM,IAAI,YAAY,mBAAmB;EAKtD,QAAQ,UAAS,KAAK,uCAA4C,QAAQ;;qBASrE;EACX,aAAY,WAAW,iBAAsB"}
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ import { Module } from "@blixis-io/core";
2
+ import { createHttpApplication } from "@blixis-io/http";
3
+ //#region src/test-application.ts
4
+ const BASE_URL = "http://localhost";
5
+ /** Thin sugar over `HttpApplication` for tests: a `request()` helper that builds absolute URLs and JSON bodies. */
6
+ var TestApplication = class {
7
+ constructor(app) {
8
+ this.app = app;
9
+ }
10
+ async request(path, init = {}) {
11
+ const { json, headers, body, ...rest } = init;
12
+ const finalHeaders = new Headers(headers);
13
+ let finalBody = body;
14
+ if (json !== void 0) {
15
+ finalHeaders.set("content-type", "application/json");
16
+ finalBody = JSON.stringify(json);
17
+ }
18
+ return this.app.handle(new Request(new URL(path, BASE_URL), {
19
+ ...rest,
20
+ headers: finalHeaders,
21
+ ...finalBody !== void 0 ? { body: finalBody } : {}
22
+ }));
23
+ }
24
+ get(token) {
25
+ return this.app.get(token);
26
+ }
27
+ async close(signal) {
28
+ await this.app.close(signal);
29
+ }
30
+ };
31
+ //#endregion
32
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/decorate.js
33
+ function __decorate(decorators, target, key, desc) {
34
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
36
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
37
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
38
+ }
39
+ //#endregion
40
+ //#region src/test-module-builder.ts
41
+ var TestModuleBuilder = class {
42
+ #metadata;
43
+ #overrides = [];
44
+ constructor(metadata) {
45
+ this.#metadata = metadata;
46
+ }
47
+ /** Replaces the provider registered under `token` with `definition`, applied before the module graph resolves. */
48
+ override(token, definition) {
49
+ this.#overrides.push({
50
+ provide: token,
51
+ ...definition
52
+ });
53
+ return this;
54
+ }
55
+ async compile(options = {}) {
56
+ let TestRootModule = class TestRootModule {};
57
+ TestRootModule = __decorate([Module(this.#metadata)], TestRootModule);
58
+ return new TestApplication(await createHttpApplication(TestRootModule, {
59
+ ...options,
60
+ overrides: this.#overrides
61
+ }));
62
+ }
63
+ };
64
+ const Test = { createModule(metadata = {}) {
65
+ return new TestModuleBuilder(metadata);
66
+ } };
67
+ //#endregion
68
+ export { Test, TestApplication, TestModuleBuilder };
69
+
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/test-application.ts","../src/test-module-builder.ts"],"sourcesContent":["import type { HttpApplication } from \"@blixis-io/http\";\nimport type { Token } from \"@blixis-io/di\";\n\nexport interface TestRequestInit extends Omit<RequestInit, \"body\"> {\n body?: RequestInit[\"body\"];\n /** JSON-stringified into the body, with `content-type: application/json` set automatically. */\n json?: unknown;\n}\n\nconst BASE_URL = \"http://localhost\";\n\n/** Thin sugar over `HttpApplication` for tests: a `request()` helper that builds absolute URLs and JSON bodies. */\nexport class TestApplication {\n constructor(private readonly app: HttpApplication) {}\n\n async request(path: string, init: TestRequestInit = {}): Promise<Response> {\n const { json, headers, body, ...rest } = init;\n const finalHeaders = new Headers(headers);\n let finalBody = body;\n\n if (json !== undefined) {\n finalHeaders.set(\"content-type\", \"application/json\");\n finalBody = JSON.stringify(json);\n }\n\n return this.app.handle(\n new Request(new URL(path, BASE_URL), { ...rest, headers: finalHeaders, ...(finalBody !== undefined ? { body: finalBody } : {}) }),\n );\n }\n\n get<T>(token: Token<T>): T {\n return this.app.get(token);\n }\n\n async close(signal?: string): Promise<void> {\n await this.app.close(signal);\n }\n}\n","import type { ModuleMetadata } from \"@blixis-io/core\";\nimport { Module } from \"@blixis-io/core\";\nimport type { ClassProvider, ExistingProvider, FactoryProvider, Provider, Token, ValueProvider } from \"@blixis-io/di\";\nimport { createHttpApplication, type HttpApplicationOptions } from \"@blixis-io/http\";\nimport { TestApplication } from \"./test-application.js\";\n\nexport type OverrideDefinition<T> =\n | Omit<ClassProvider<T>, \"provide\">\n | Omit<ValueProvider<T>, \"provide\">\n | Omit<FactoryProvider<T>, \"provide\">\n | Omit<ExistingProvider<T>, \"provide\">;\n\nexport class TestModuleBuilder {\n #metadata: ModuleMetadata;\n #overrides: Provider[] = [];\n\n constructor(metadata: ModuleMetadata) {\n this.#metadata = metadata;\n }\n\n /** Replaces the provider registered under `token` with `definition`, applied before the module graph resolves. */\n override<T>(token: Token<T>, definition: OverrideDefinition<T>): this {\n this.#overrides.push({ provide: token, ...definition });\n return this;\n }\n\n async compile(options: Omit<HttpApplicationOptions, \"overrides\"> = {}): Promise<TestApplication> {\n @Module(this.#metadata)\n class TestRootModule {}\n\n const app = await createHttpApplication(TestRootModule, { ...options, overrides: this.#overrides });\n return new TestApplication(app);\n }\n}\n\nexport const Test = {\n createModule(metadata: ModuleMetadata = {}): TestModuleBuilder {\n return new TestModuleBuilder(metadata);\n },\n};\n"],"mappings":";;;AASA,MAAM,WAAW;;AAGjB,IAAa,kBAAb,MAA6B;CAC3B,YAAY,KAAuC;EAAtB,KAAA,MAAA;CAAuB;CAEpD,MAAM,QAAQ,MAAc,OAAwB,CAAC,GAAsB;EACzE,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,SAAS;EACzC,MAAM,eAAe,IAAI,QAAQ,OAAO;EACxC,IAAI,YAAY;EAEhB,IAAI,SAAS,KAAA,GAAW;GACtB,aAAa,IAAI,gBAAgB,kBAAkB;GACnD,YAAY,KAAK,UAAU,IAAI;EACjC;EAEA,OAAO,KAAK,IAAI,OACd,IAAI,QAAQ,IAAI,IAAI,MAAM,QAAQ,GAAG;GAAE,GAAG;GAAM,SAAS;GAAc,GAAI,cAAc,KAAA,IAAY,EAAE,MAAM,UAAU,IAAI,CAAC;EAAG,CAAC,CAClI;CACF;CAEA,IAAO,OAAoB;EACzB,OAAO,KAAK,IAAI,IAAI,KAAK;CAC3B;CAEA,MAAM,MAAM,QAAgC;EAC1C,MAAM,KAAK,IAAI,MAAM,MAAM;CAC7B;AACF;;;;;;;;;;;ACzBA,IAAa,oBAAb,MAA+B;CAC7B;CACA,aAAyB,CAAC;CAE1B,YAAY,UAA0B;EACpC,KAAK,YAAY;CACnB;;CAGA,SAAY,OAAiB,YAAyC;EACpE,KAAK,WAAW,KAAK;GAAE,SAAS;GAAO,GAAG;EAAW,CAAC;EACtD,OAAO;CACT;CAEA,MAAM,QAAQ,UAAqD,CAAC,GAA6B;EAC/F,IACM,iBADN,MACM,eAAe,CAAC;EADrB,iBAAA,WAAA,CAAA,OAAO,KAAK,SAAS,CAAA,GAAA,cAAA;EAItB,OAAO,IAAI,gBAAgB,MADT,sBAAsB,gBAAgB;GAAE,GAAG;GAAS,WAAW,KAAK;EAAW,CAAC,CACpE;CAChC;AACF;AAEA,MAAa,OAAO,EAClB,aAAa,WAA2B,CAAC,GAAsB;CAC7D,OAAO,IAAI,kBAAkB,QAAQ;AACvC,EACF"}
package/package.json CHANGED
@@ -1 +1,44 @@
1
- { "name": "@blixis-io/testing", "version": "0.0.0", "description": "placeholder" }
1
+ {
2
+ "name": "@blixis-io/testing",
3
+ "version": "0.1.3",
4
+ "description": "A thin testing layer on top of @blixis-io/http. Build a real application in a test, override providers with fakes, hit it with real requests.",
5
+ "license": "MIT",
6
+ "author": "Michael Voeten <michael@voeten.online>",
7
+ "homepage": "https://blixis-io.github.io/framework/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/blixis-io/framework.git",
11
+ "directory": "packages/testing"
12
+ },
13
+ "type": "module",
14
+ "engines": {
15
+ "node": ">=24"
16
+ },
17
+ "keywords": [
18
+ "testing",
19
+ "http",
20
+ "typescript"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "@blixis-io/source": "./src/index.ts",
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ }
34
+ },
35
+ "dependencies": {
36
+ "@blixis-io/core": "0.3.0",
37
+ "@blixis-io/di": "0.1.1",
38
+ "@blixis-io/http": "0.3.1"
39
+ },
40
+ "scripts": {
41
+ "typecheck": "tsc -p tsconfig.json",
42
+ "build": "rolldown -c"
43
+ }
44
+ }