create-bcp-app 0.2.13 → 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 CHANGED
@@ -69,17 +69,17 @@ Select storage provider:
69
69
 
70
70
  New projects include `bcp.project.json`.
71
71
 
72
- Example for the `0.2.13` target:
72
+ Example for the `0.2.14` target:
73
73
 
74
74
  ```json
75
75
  {
76
76
  "schemaVersion": 1,
77
77
  "framework": "bcp",
78
78
  "projectName": "my-app",
79
- "frameworkPackage": "npm:@chidchanun/bcp@0.2.13",
79
+ "frameworkPackage": "npm:@chidchanun/bcp@0.2.14",
80
80
  "createdWith": {
81
81
  "package": "create-bcp-app",
82
- "version": "0.2.13"
82
+ "version": "0.2.14"
83
83
  },
84
84
  "packageManager": "npm",
85
85
  "presets": {
@@ -218,44 +218,101 @@ await realtime.broadcast(
218
218
  );
219
219
  ```
220
220
 
221
- Presence metadata can be attached during `join()` and read with `realtime.members(channel)`.
221
+ BCP does not install a WebSocket library. Adapt your selected provider to `RealtimeSocket`. SSE is available directly through `realtime.sse()`.
222
222
 
223
- For private channels, configure `authenticate`, `getUserId` and `authorizeChannel` on `createRealtime()`.
223
+ The memory broker/presence store are local-only. Multi-instance production deployments should provide shared `RealtimeBroker` and `RealtimePresenceStore` implementations.
224
+
225
+ ## Testing Platform — 0.2.14+
224
226
 
225
- ### WebSocket integration
227
+ `bcp/testing` adds framework-native test helpers without requiring a specific test runner.
226
228
 
227
- BCP does not install a WebSocket library. Adapt your selected provider to `RealtimeSocket` and pass it to:
229
+ Request/route example:
228
230
 
229
231
  ```ts
230
- await realtime.attachSocket(
231
- socketAdapter,
232
- {
233
- request,
234
- }
235
- );
236
- ```
232
+ import {
233
+ createRouteTestHandler,
234
+ createTestApp,
235
+ expectResponse,
236
+ } from "bcp/testing";
237
+
238
+ const app =
239
+ createTestApp({
240
+ handler:
241
+ createRouteTestHandler({
242
+ GET() {
243
+ return {
244
+ ok: true,
245
+ };
246
+ },
247
+ }),
248
+ });
237
249
 
238
- ### Server-Sent Events
250
+ await expectResponse(
251
+ await app.get("/api/health")
252
+ )
253
+ .status(200)
254
+ .json({
255
+ ok: true,
256
+ });
257
+ ```
239
258
 
240
- SSE is available without another dependency:
259
+ Create a real signed BCP auth session for authenticated requests:
241
260
 
242
261
  ```ts
243
- export function GET(
244
- request: Request
245
- ) {
246
- return realtime.sse(
247
- "jobs:42",
262
+ import {
263
+ createTestAuthSession,
264
+ } from "bcp/testing";
265
+
266
+ const session =
267
+ await createTestAuthSession(
248
268
  {
249
- signal:
250
- request.signal,
269
+ id: 42,
270
+ role: "admin",
271
+ },
272
+ {
273
+ secret:
274
+ process.env.BCP_SESSION_SECRET,
251
275
  }
252
276
  );
253
- }
277
+
278
+ app.setCookie(
279
+ session.cookieName,
280
+ session.token
281
+ );
254
282
  ```
255
283
 
256
- The memory broker/presence store are local-only. Multi-instance production deployments should provide shared `RealtimeBroker` and `RealtimePresenceStore` implementations.
284
+ Rollback database tests:
285
+
286
+ ```ts
287
+ import {
288
+ withTestTransaction,
289
+ } from "bcp/testing";
290
+
291
+ await withTestTransaction(
292
+ db,
293
+ async tx => {
294
+ await tx.execute(
295
+ "INSERT INTO users ..."
296
+ );
297
+ }
298
+ );
299
+ ```
300
+
301
+ Infrastructure helpers include:
302
+
303
+ ```text
304
+ createJobTestHarness()
305
+ createWorkflowTestHarness()
306
+ createOutboxTestHarness()
307
+ createRealtimeTestSocket()
308
+ createRealtimeTestHarness()
309
+ readSseEvents()
310
+ createFakeClock()
311
+ createSequenceIdFactory()
312
+ runTestMiddleware()
313
+ ```
257
314
 
258
- `bcp/realtime` is server-only and cannot be imported into page/client bundles.
315
+ `bcp/testing` is server-only. It can be used with Node `node:test`, Vitest, Jest or another runner; BCP does not install those runners as framework dependencies.
259
316
 
260
317
  ## Storage providers
261
318
 
@@ -295,5 +352,5 @@ npm run generate -- migration create_users
295
352
  For prerelease/local package verification:
296
353
 
297
354
  ```bash
298
- npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.2.13.tgz
355
+ npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.2.14.tgz
299
356
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bcp-app",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Create a new BCP Framework application.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -163,29 +163,86 @@ await realtime.broadcast(
163
163
  );
164
164
  ```
165
165
 
166
- Presence metadata can be supplied during `join()` and queried with `realtime.members(channel)`.
166
+ BCP does not install a WebSocket server dependency. Adapt the selected provider to `RealtimeSocket`. SSE is built in through `realtime.sse()`.
167
167
 
168
- BCP does not install a WebSocket server dependency. Adapt the selected provider to `RealtimeSocket` and call `realtime.attachSocket(socketAdapter, { request })`.
168
+ For multi-instance deployment, replace the memory broker/presence store with shared `RealtimeBroker` and `RealtimePresenceStore` implementations.
169
+
170
+ ## Testing Platform — BCP 0.2.14+
171
+
172
+ Use server-only `bcp/testing` to exercise framework contracts without adding a BCP-specific test runner.
173
+
174
+ ```ts
175
+ import {
176
+ createRouteTestHandler,
177
+ createTestApp,
178
+ expectResponse,
179
+ } from "bcp/testing";
180
+
181
+ const app =
182
+ createTestApp({
183
+ handler:
184
+ createRouteTestHandler({
185
+ GET() {
186
+ return {
187
+ ok: true,
188
+ };
189
+ },
190
+ }),
191
+ });
169
192
 
170
- SSE is built in:
193
+ await expectResponse(
194
+ await app.get("/api/health")
195
+ )
196
+ .status(200)
197
+ .json({
198
+ ok: true,
199
+ });
200
+ ```
201
+
202
+ Authentication tests can create a real signed BCP session:
171
203
 
172
204
  ```ts
173
- export function GET(
174
- request: Request
175
- ) {
176
- return realtime.sse(
177
- "jobs:42",
205
+ import {
206
+ createTestAuthSession,
207
+ } from "bcp/testing";
208
+
209
+ const session =
210
+ await createTestAuthSession(
211
+ {
212
+ id: 42,
213
+ },
178
214
  {
179
- signal:
180
- request.signal,
215
+ secret:
216
+ process.env.BCP_SESSION_SECRET,
181
217
  }
182
218
  );
183
- }
219
+
220
+ app.setCookie(
221
+ session.cookieName,
222
+ session.token
223
+ );
184
224
  ```
185
225
 
186
- For multi-instance deployment, replace the memory broker/presence store with shared `RealtimeBroker` and `RealtimePresenceStore` implementations.
226
+ Database tests can force rollback after assertions:
227
+
228
+ ```ts
229
+ import {
230
+ withTestTransaction,
231
+ } from "bcp/testing";
232
+
233
+ await withTestTransaction(
234
+ db,
235
+ async tx => {
236
+ await tx.execute(
237
+ "INSERT INTO users ..."
238
+ );
239
+ }
240
+ );
241
+ ```
242
+
243
+ Additional helpers include job/workflow/outbox harnesses, `runTestMiddleware()`, fake clocks and IDs, a fake `RealtimeSocket`, realtime event assertions and `readSseEvents()`.
187
244
 
188
- `bcp/realtime` is server-only and cannot be imported into page/client bundles.
245
+ BCP does not require Jest or Vitest; these helpers work with Node `node:test` or another runner.
189
246
 
190
247
  ## Generate framework files
191
248