@dunx/testing 2.0.0 → 2.1.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.
Files changed (2) hide show
  1. package/README.md +22 -17
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -35,7 +35,7 @@ registration that has to out-rank the real one.
35
35
 
36
36
  A module is a scope, and `providers` are private to it. So a test override cannot be
37
37
  an extra module appended at the end that wins - an appended module's providers are
38
- invisible to every scope that does not import it, which is exactly the scope the
38
+ invisible to every scope that does not import it, being the scope the
39
39
  code under test resolves from.
40
40
 
41
41
  `createTestApp` therefore builds the same scope graph the app would have and
@@ -45,9 +45,9 @@ substitutes by token inside it. Three consequences worth relying on:
45
45
  `Logger` does not have to know how many modules bind it, and does not have to name
46
46
  a scope. Where two scopes genuinely bind one token differently and only one is
47
47
  meant, resolve through the module you care about instead.
48
- - **An override naming a token nobody binds is an error**, not a silent no-op. A
48
+ - **An override naming a token nobody binds is an error** rather than a silent no-op. A
49
49
  typo'd token would otherwise leave the suite asserting against the real provider
50
- it thought it had swapped, which is the failure mode this package exists to
50
+ it thought it had swapped, the failure mode this package exists to
51
51
  prevent.
52
52
  - **The discarded provider is never instantiated.** Its `useFactory` never runs and
53
53
  its `onInit` never fires. Overriding the database does not open a connection to
@@ -73,19 +73,24 @@ applies there as well.
73
73
  synthetic root, so no fixture module has to be written by hand. Anything a module
74
74
  ref can be works - a class, or a `DynamicModule` from a `forRoot`.
75
75
 
76
- `TestServer` is a `TestClient` plus `app` (the real `HttpApp`, for `app.get(...)`)
77
- and `close()`. `createTestServer` passes `HttpOptions` through, with two
78
- differences: `port` is always 0, and **`requestLogging` defaults to `false`** - it
79
- is on by default in production for good reasons, none of which apply to a suite
80
- that would otherwise print one JSON line per assertion. Pass
81
- `requestLogging: true` to test the logging itself.
76
+ `TestServer` is a `TestClient` plus `app` (the real `HttpApp`, for
77
+ `app.get(...)`) and `close()`.
82
78
 
83
- Everything else is **absent unless passed**, and `middleware` and `onError` decide
84
- what the application is: forget them and the fixture has no global guards and the
85
- default error mapper, and answers 200 where production answers 401. Export one
86
- `httpOptions(config)` and spread it into both `main.ts` and every suite. Omitting
87
- `middleware` in a graph that declares a `Middleware` no `@UseGuards` attaches warns
88
- on `console.warn`; `middleware: []` says the omission is deliberate.
79
+ `createTestServer` passes `HttpOptions` through, with two differences: `port`
80
+ is always 0, and **`requestLogging` defaults to `false`** - it is on by default
81
+ in production for good reasons, none of which apply to a suite that would
82
+ otherwise print one JSON line per assertion. Pass `requestLogging: true` to
83
+ test the logging itself.
84
+
85
+ Everything else is **absent unless passed**, and `middleware` and `onError`
86
+ decide what the application is: forget them and the fixture has no global
87
+ guards and the default error mapper, and answers 200 where production answers
88
+ 401. Export one `httpOptions(config)` and spread it into both `main.ts` and
89
+ every suite.
90
+
91
+ Omitting `middleware` in a graph that declares a `Middleware` no `@UseGuards`
92
+ attaches warns on `console.warn`; `middleware: []` says the omission is
93
+ deliberate.
89
94
 
90
95
  ### The client
91
96
 
@@ -121,7 +126,7 @@ It records; it does not interpret. No level filtering, no error promotion, no
121
126
  merging of extras - those are `@arkv/logger`'s behaviour, and asserting against a
122
127
  reimplementation of them would prove nothing.
123
128
 
124
- ## Deliberately not here
129
+ ## Not here
125
130
 
126
131
  - **A fluent assertion DSL** (`expect(res).toHaveStatus(200)`, supertest-style
127
132
  chaining). `status` and a parsed `body` read fine through `expect` already, and a
@@ -137,7 +142,7 @@ reimplementation of them would prove nothing.
137
142
  dunx wrote, and not the parts Bun owns - route matching, params, method
138
143
  dispatch, upgrades. The real server is cheaper than the lie.
139
144
  - **Database fixtures, transactional rollback, seeding.** That is drizzle's
140
- surface, not this package's. `@dunx/infra/db` binds an in-memory `bun:sqlite`
145
+ surface rather than this package's. `@dunx/infra/db` binds an in-memory `bun:sqlite`
141
146
  with the same driver as production, which is a better fixture than a mock.
142
147
  - **A websocket client.** Bun implements `WebSocket` natively, and a gateway test
143
148
  is `new WebSocket(server.url.replace('http', 'ws') + '/chat')`. Wrapping that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dunx/testing",
3
- "version": "2.0.0",
3
+ "version": "2.1.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.0.0",
55
- "@dunx/http": "^2.0.0",
54
+ "@dunx/core": "^2.1.0",
55
+ "@dunx/http": "^2.1.0",
56
56
  "@types/bun": ">=1.3.0"
57
57
  },
58
58
  "peerDependenciesMeta": {