@chidchanun/bcp 0.2.12 → 0.2.14
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/README.md +223 -222
- package/docs/README.md +50 -54
- package/docs/api-manifest.json +32 -71
- package/docs/api-reference.md +165 -58
- package/docs/docs-web-manifest.json +9 -5
- package/docs/platform-manifest.json +33 -4
- package/docs/realtime-platform.md +447 -0
- package/docs/releases/0.2.13.md +122 -0
- package/docs/releases/0.2.14.md +241 -0
- package/docs/testing-platform.md +602 -0
- package/package.json +11 -1
- package/packages/bundler/src/client-boundary.ts +2 -0
- package/packages/client/src/realtime.mjs +973 -0
- package/packages/client/src/realtime.ts +31 -0
- package/packages/client/src/testing.mjs +2357 -0
- package/packages/client/src/testing.ts +52 -0
- package/packages/server/src/realtime.ts +1518 -0
- package/packages/server/src/testing-page.ts +274 -0
- package/packages/server/src/testing.ts +1884 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# BCP Framework 0.2.14 — Testing Platform
|
|
2
|
+
|
|
3
|
+
**Release state:** unreleased
|
|
4
|
+
|
|
5
|
+
BCP `0.2.14` adds framework-native server-side testing utilities through the new `bcp/testing` entrypoint.
|
|
6
|
+
|
|
7
|
+
The milestone is intentionally test-runner neutral: BCP does not add Jest or Vitest as runtime dependencies. The framework's own suite continues to use Node's built-in `node:test`.
|
|
8
|
+
|
|
9
|
+
## Highlights
|
|
10
|
+
|
|
11
|
+
- new server-only `bcp/testing` entrypoint,
|
|
12
|
+
- Request -> Response application test harness,
|
|
13
|
+
- persistent test cookie jar and default headers,
|
|
14
|
+
- API route module testing for GET/POST/PUT/PATCH/DELETE/HEAD/OPTIONS,
|
|
15
|
+
- page guard testing through the production guard executor,
|
|
16
|
+
- page loader testing through the production loader executor,
|
|
17
|
+
- form action testing through the production action executor,
|
|
18
|
+
- `FormData` construction helper,
|
|
19
|
+
- lightweight response assertions,
|
|
20
|
+
- real signed BCP auth session generation,
|
|
21
|
+
- optional `AuthSessionStore` registration,
|
|
22
|
+
- rollback-only database test transactions,
|
|
23
|
+
- real Middleware System v2 pipeline execution,
|
|
24
|
+
- deterministic fake clock,
|
|
25
|
+
- deterministic sequence ID factory,
|
|
26
|
+
- background job queue drain/count helpers,
|
|
27
|
+
- workflow execution/state helpers,
|
|
28
|
+
- transactional outbox dispatch/state helpers,
|
|
29
|
+
- in-memory `RealtimeSocket` test adapter,
|
|
30
|
+
- realtime connection/event harness,
|
|
31
|
+
- Server-Sent Events reader,
|
|
32
|
+
- prepared package compilation to `testing.mjs`,
|
|
33
|
+
- package smoke and client-boundary validation.
|
|
34
|
+
|
|
35
|
+
## Public API
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import {
|
|
39
|
+
createFakeClock,
|
|
40
|
+
createJobTestHarness,
|
|
41
|
+
createOutboxTestHarness,
|
|
42
|
+
createRealtimeTestHarness,
|
|
43
|
+
createRealtimeTestSocket,
|
|
44
|
+
createRouteTestHandler,
|
|
45
|
+
createSequenceIdFactory,
|
|
46
|
+
createTestApp,
|
|
47
|
+
createTestAuthSession,
|
|
48
|
+
createTestFormData,
|
|
49
|
+
createWorkflowTestHarness,
|
|
50
|
+
expectResponse,
|
|
51
|
+
readSseEvents,
|
|
52
|
+
runTestMiddleware,
|
|
53
|
+
runTestPageAction,
|
|
54
|
+
runTestPageGuards,
|
|
55
|
+
runTestPageLoader,
|
|
56
|
+
withTestTransaction,
|
|
57
|
+
} from "bcp/testing";
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Request and route testing
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const app =
|
|
64
|
+
createTestApp({
|
|
65
|
+
handler:
|
|
66
|
+
createRouteTestHandler({
|
|
67
|
+
GET() {
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const response =
|
|
76
|
+
await app.get(
|
|
77
|
+
"/api/health"
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
await expectResponse(response)
|
|
81
|
+
.status(200)
|
|
82
|
+
.json({
|
|
83
|
+
ok: true,
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The harness maintains cookies returned by `Set-Cookie` and sends them on future requests.
|
|
88
|
+
|
|
89
|
+
## Page server runtime testing
|
|
90
|
+
|
|
91
|
+
Page loader, guard and form action helpers invoke the same execution functions used by BCP runtime:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
await runTestPageGuards(
|
|
95
|
+
guard,
|
|
96
|
+
{
|
|
97
|
+
params: {
|
|
98
|
+
id: "42",
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
await runTestPageLoader(
|
|
104
|
+
loader,
|
|
105
|
+
{
|
|
106
|
+
url:
|
|
107
|
+
"/users/42?tab=profile",
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
await runTestPageAction(
|
|
112
|
+
updateUser,
|
|
113
|
+
{
|
|
114
|
+
actionName:
|
|
115
|
+
"updateUser",
|
|
116
|
+
method: "PATCH",
|
|
117
|
+
fields: {
|
|
118
|
+
name: "BCP",
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This preserves guard-data chaining, loader/action Response short-circuits, action method validation and JSON-safe result validation.
|
|
125
|
+
|
|
126
|
+
## Authentication testing
|
|
127
|
+
|
|
128
|
+
`createTestAuthSession()` uses the same BCP session token implementation as production auth.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const session =
|
|
132
|
+
await createTestAuthSession(
|
|
133
|
+
{
|
|
134
|
+
id: 42,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
secret,
|
|
138
|
+
store:
|
|
139
|
+
authSessionStore,
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
app.setCookie(
|
|
144
|
+
session.cookieName,
|
|
145
|
+
session.token
|
|
146
|
+
);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This avoids introducing a framework-only fake user header.
|
|
150
|
+
|
|
151
|
+
## Database rollback tests
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
await withTestTransaction(
|
|
155
|
+
db,
|
|
156
|
+
async tx => {
|
|
157
|
+
await tx.execute(
|
|
158
|
+
"INSERT INTO users ..."
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// assertions
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
After the callback succeeds, BCP deliberately rejects the database transaction with an internal rollback signal, then returns the callback result to the test.
|
|
167
|
+
|
|
168
|
+
## Infrastructure harnesses
|
|
169
|
+
|
|
170
|
+
`0.2.14` adds thin harnesses over the real platform contracts instead of separate mock implementations:
|
|
171
|
+
|
|
172
|
+
```text
|
|
173
|
+
BackgroundJobQueue -> createJobTestHarness()
|
|
174
|
+
Workflow -> createWorkflowTestHarness()
|
|
175
|
+
OutboxStore + Dispatcher -> createOutboxTestHarness()
|
|
176
|
+
RealtimeHub -> createRealtimeTestHarness()
|
|
177
|
+
RealtimeSocket -> createRealtimeTestSocket()
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## SSE
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
const events =
|
|
184
|
+
await readSseEvents(
|
|
185
|
+
response,
|
|
186
|
+
{
|
|
187
|
+
limit: 1,
|
|
188
|
+
timeoutMs: 1_000,
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
SSE comments and retry frames are ignored and JSON `data:` payloads are decoded when possible.
|
|
194
|
+
|
|
195
|
+
## Package/runtime contract
|
|
196
|
+
|
|
197
|
+
The prepared npm package now exposes:
|
|
198
|
+
|
|
199
|
+
```text
|
|
200
|
+
bcp/testing
|
|
201
|
+
types -> packages/client/src/testing.ts
|
|
202
|
+
browser -> packages/client/src/server-only.browser.mjs
|
|
203
|
+
default -> packages/client/src/testing.mjs
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`testing.mjs` is compiled during `package:prepare` so Node does not need a TypeScript loader to use the testing entrypoint from an installed package.
|
|
207
|
+
|
|
208
|
+
## Compatibility
|
|
209
|
+
|
|
210
|
+
`0.2.14` has no intentional breaking changes from `0.2.13`.
|
|
211
|
+
|
|
212
|
+
All existing runtime entrypoints remain supported.
|
|
213
|
+
|
|
214
|
+
## Validation
|
|
215
|
+
|
|
216
|
+
Before publishing:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npm run typecheck
|
|
220
|
+
npm run test:unit
|
|
221
|
+
npm run test:integration
|
|
222
|
+
npm run test:e2e
|
|
223
|
+
npm run test:package
|
|
224
|
+
npm run rc:check
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The release must not be tagged or published until the final release commit passes the complete RC sequence.
|
|
228
|
+
|
|
229
|
+
## Non-goals
|
|
230
|
+
|
|
231
|
+
`0.2.14` does not add:
|
|
232
|
+
|
|
233
|
+
- a DOM/browser renderer,
|
|
234
|
+
- Playwright integration,
|
|
235
|
+
- component snapshots,
|
|
236
|
+
- a coverage runner,
|
|
237
|
+
- a Jest dependency,
|
|
238
|
+
- a Vitest dependency,
|
|
239
|
+
- automatic Docker/database test provisioning.
|
|
240
|
+
|
|
241
|
+
These can be layered on top of the base testing contracts in later milestones.
|