@dunx/testing 2.2.0 → 2.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/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -148,12 +148,12 @@ var createTestServer = async (options) => {
|
|
|
148
148
|
};
|
|
149
149
|
};
|
|
150
150
|
export {
|
|
151
|
-
|
|
152
|
-
testClient,
|
|
153
|
-
createTestServer,
|
|
151
|
+
RecordingLogger,
|
|
154
152
|
createTestApp,
|
|
155
|
-
|
|
153
|
+
createTestServer,
|
|
154
|
+
testClient,
|
|
155
|
+
testRoot
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
//# debugId=
|
|
158
|
+
//# debugId=542D5DFC23443AC664756E2164756E21
|
|
159
159
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
"import {\n collectModules,\n readControllers,\n type Ctor,\n type ResolvedModule,\n} from '@dunx/core';\nimport {\n discoverRoutes,\n HttpFactory,\n type HttpApp,\n type HttpOptions,\n type Middleware,\n} from '@dunx/http';\nimport { appOptions, testRoot, type TestAppOptions } from './app.js';\nimport { testClient, type TestClient } from './client.js';\n\nexport interface TestServerOptions\n extends TestAppOptions, Omit<HttpOptions, 'port' | 'overrides'> {\n /**\n * `setGlobalPrefix`, applied before `listen()` so the client's URLs carry it.\n *\n * Explicitly `| undefined`, unlike the rest of the options: a suite that runs\n * the same fixture prefixed and unprefixed passes a variable here, and under\n * `exactOptionalPropertyTypes` that is otherwise a conditional spread. \"No\n * prefix\" and \"absent\" mean the same thing, so nothing is lost by allowing it.\n */\n readonly prefix?: string | undefined;\n}\n\nexport interface TestServer extends TestClient {\n readonly app: HttpApp;\n /** `app.shutdown()` - stops the server, then tears the container down. */\n close(): Promise<void>;\n}\n\nconst middlewareShaped = (ctor: Ctor<unknown>): boolean =>\n typeof (ctor.prototype as { handle?: unknown } | undefined)?.handle ===\n 'function';\n\n/** Every class provider in the graph that implements `Middleware`. */\nconst declaredMiddleware = (\n modules: readonly ResolvedModule[],\n): readonly Ctor<unknown>[] => {\n const found: Ctor<unknown>[] = [];\n for (const module of modules) {\n for (const entry of module.options.providers ?? []) {\n const ctor =\n typeof entry === 'function'\n ? entry\n : entry.provider.kind === 'class'\n ? entry.provider.ctor\n : undefined;\n if (ctor !== undefined && middlewareShaped(ctor)) found.push(ctor);\n }\n }\n return found;\n};\n\n/**\n * The guards `@UseGuards` already puts in the route table. They are not global, so\n * omitting `middleware` costs them nothing and warning about them would be noise.\n */\nconst scopedGuards = (\n app: HttpApp,\n modules: readonly ResolvedModule[],\n): ReadonlySet<Ctor<Middleware>> => {\n const applied = new Set<Ctor<Middleware>>();\n for (const module of modules) {\n for (const controller of readControllers(module)) {\n for (const route of discoverRoutes(app.get(controller) as object)) {\n for (const guard of route.guards ?? []) applied.add(guard);\n }\n }\n }\n return applied;\n};\n\n/**\n * The one silent way this harness can lie: `middleware` and `onError` default\n * away, so a suite that forgets them boots a server with no global guards and the\n * default error mapper, which still answers 200 where the application answers 401.\n * A first integration run of 12 pass / 10 fail is the reported cost of finding\n * that out by hand.\n *\n * So a `Middleware` implementation that is in the graph, is not attached by\n * `@UseGuards`, and was not passed here is worth one line on `console.warn` -\n * `console`, not the bound `Logger`, because a suite asserting on a\n * `RecordingLogger` should not see an entry the application never wrote.\n */\nconst warnAboutGlobals = (\n app: HttpApp,\n modules: readonly ResolvedModule[],\n): void => {\n const declared = declaredMiddleware(modules);\n if (declared.length === 0) return;\n const scoped = scopedGuards(app, modules);\n const orphaned = declared.filter(\n (ctor) => !scoped.has(ctor as Ctor<Middleware>),\n );\n if (orphaned.length === 0) return;\n\n console.warn(\n `createTestServer: ${orphaned.map((ctor) => ctor.name).join(', ')} ` +\n 'implement Middleware and are in the graph under test, but no `middleware` ' +\n 'was supplied. If they are global in main.ts then this fixture is not the ' +\n 'application: no global guard runs and `onError` is the default mapper. ' +\n 'Export one httpOptions(config) and give it to both, or pass ' +\n '`middleware: []` to say the omission is deliberate.',\n );\n};\n\n/**\n * A **real** `Bun.serve` on port 0, with the same override semantics as\n * {@link createTestApp}. Nothing is faked: `Bun.serve` binds in about a\n * millisecond, and a fake would only be able to prove the parts of the request\n * path dunx wrote rather than the parts Bun owns - routing, params, method\n * dispatch, upgrades.\n *\n * ```ts\n * const server = await createTestServer({ modules: [ApiModule], prefix: 'api' });\n * const { status, body } = await server.json('api/users');\n * await server.close();\n * ```\n *\n * Request logging and boot logging are both **off** unless asked for: they are on by\n * default in production for good reasons, none of which apply to a suite that would\n * print one JSON line per assertion and one route table per file.\n *\n * **An `HttpOptions` field not passed is absent, not inherited from production.**\n * `middleware` (where global guards live) and `onError` are the two that change\n * what the application does, so pass the same object `main.ts` passes - one\n * exported `httpOptions(config)` spread into both. Omitting `middleware` in a graph\n * that declares a `Middleware` no `@UseGuards` attaches writes one line to\n * `console.warn`; `middleware: []` says the omission is deliberate.\n */\nexport const createTestServer = async (\n options: TestServerOptions,\n): Promise<TestServer> => {\n const { modules, overrides, prefix, requestLogging, bootLogging, ...http } =\n options;\n\n const root = testRoot(modules);\n const app = await HttpFactory.create(root, {\n ...http,\n ...appOptions(overrides),\n requestLogging: requestLogging ?? false,\n // Off for the same reason: a suite that boots a server per file does not want a\n // route table per file. A suite asserting on the table asks for it.\n bootLogging: bootLogging ?? false,\n port: 0,\n });\n if (http.middleware === undefined)\n warnAboutGlobals(app, collectModules(root));\n if (prefix !== undefined) app.setGlobalPrefix(prefix);\n\n return {\n ...testClient(await app.listen()),\n app,\n close: () => app.shutdown(),\n };\n};\n"
|
|
9
9
|
],
|
|
10
10
|
"mappings": ";;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,WAAW;AAAC;AAUlB,IAAM,SAAS,CACb,YACoC,MAAM,QAAQ,OAAO;AAOpD,IAAM,WAAW,CACtB,aACmB;AAAA,EACnB,QAAQ;AAAA,EACR,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SAClE;AAAA,EAEF,MAAM,OAAO,SAAS,OAAO;AAAA,EAC7B,MAAM,MAAM,MAAM,YAAY,OAAO,MAAM;AAAA,OACtC;AAAA,OACA,WAAW,SAAS;AAAA,IACvB,gBAAgB,kBAAkB;AAAA,IAGlC,aAAa,eAAe;AAAA,IAC5B,MAAM;AAAA,EACR,CAAC;AAAA,EACD,IAAI,KAAK,eAAe;AAAA,IACtB,iBAAiB,KAAK,eAAe,IAAI,CAAC;AAAA,EAC5C,IAAI,WAAW;AAAA,IAAW,IAAI,gBAAgB,MAAM;AAAA,EAEpD,OAAO;AAAA,OACF,WAAW,MAAM,IAAI,OAAO,CAAC;AAAA,IAChC;AAAA,IACA,OAAO,MAAM,IAAI,SAAS;AAAA,EAC5B;AAAA;",
|
|
11
|
-
"debugId": "
|
|
11
|
+
"debugId": "542D5DFC23443AC664756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dunx/testing",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Test harness for dunx apps: a container with providers replaced in place, and a real Bun.serve on port 0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"@dunx/http": "workspace:*"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@dunx/core": "^2.
|
|
55
|
-
"@dunx/http": "^2.
|
|
54
|
+
"@dunx/core": "^2.3.0",
|
|
55
|
+
"@dunx/http": "^2.3.0",
|
|
56
56
|
"@types/bun": ">=1.3.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|