@scenarist/express-adapter 0.3.3 → 0.4.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/README.md
CHANGED
|
@@ -416,6 +416,38 @@ expect(response2.status).toBe(404);
|
|
|
416
416
|
expect(response2.body.error).toBe("No active scenario for this test ID");
|
|
417
417
|
```
|
|
418
418
|
|
|
419
|
+
#### `GET /__scenarist__/state` - Debug State Endpoint
|
|
420
|
+
|
|
421
|
+
Inspect the current test state for debugging. Useful when testing multi-stage flows with `afterResponse.setState`.
|
|
422
|
+
|
|
423
|
+
**Response (200):**
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
{
|
|
427
|
+
testId: string;
|
|
428
|
+
state: Record<string, unknown>; // Current test state
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Example:**
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
const response = await request(app)
|
|
436
|
+
.get("/__scenarist__/state")
|
|
437
|
+
.set("x-scenarist-test-id", "test-123");
|
|
438
|
+
|
|
439
|
+
expect(response.status).toBe(200);
|
|
440
|
+
console.log(response.body.state); // { submitted: true, phase: "review" }
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
**When to use:**
|
|
444
|
+
|
|
445
|
+
- Debugging failing tests with state-aware mocking
|
|
446
|
+
- Verifying `afterResponse.setState` mutations
|
|
447
|
+
- Testing conditional `afterResponse` behavior (see [ADR-0020](../../docs/adrs/0020-conditional-afterresponse.md))
|
|
448
|
+
|
|
449
|
+
**Note:** This endpoint is automatically included in `scenarist.middleware` - no additional setup required!
|
|
450
|
+
|
|
419
451
|
## Core Capabilities
|
|
420
452
|
|
|
421
453
|
Scenarist provides 20+ powerful features for scenario-based testing. All capabilities work seamlessly with Express via automatic test ID propagation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenario-endpoints.d.ts","sourceRoot":"","sources":["../../src/endpoints/scenario-endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"scenario-endpoints.d.ts","sourceRoot":"","sources":["../../src/endpoints/scenario-endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAC;AAuF9D,eAAO,MAAM,uBAAuB,GAClC,SAAS,eAAe,EACxB,QAAQ,eAAe,KACtB,MAQF,CAAC"}
|
|
@@ -55,9 +55,21 @@ const handleGetScenario = (manager, config) => {
|
|
|
55
55
|
});
|
|
56
56
|
};
|
|
57
57
|
};
|
|
58
|
+
const handleGetState = (manager, config) => {
|
|
59
|
+
return (req, res) => {
|
|
60
|
+
const context = new ExpressRequestContext(req, config);
|
|
61
|
+
const testId = context.getTestId();
|
|
62
|
+
const state = manager.getState(testId);
|
|
63
|
+
res.status(200).json({
|
|
64
|
+
testId,
|
|
65
|
+
state,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
};
|
|
58
69
|
export const createScenarioEndpoints = (manager, config) => {
|
|
59
70
|
const router = Router();
|
|
60
71
|
router.post(config.endpoints.setScenario, handleSetScenario(manager, config));
|
|
61
72
|
router.get(config.endpoints.getScenario, handleGetScenario(manager, config));
|
|
73
|
+
router.get(config.endpoints.getState, handleGetState(manager, config));
|
|
62
74
|
return router;
|
|
63
75
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenarist/express-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Express middleware adapter for Scenarist",
|
|
5
5
|
"author": "Paul Hammond (citypaul) <paul@packsoftware.co.uk>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"zod": "^4.1.13",
|
|
51
|
-
"@scenarist/core": "0.
|
|
52
|
-
"@scenarist/msw-adapter": "0.
|
|
51
|
+
"@scenarist/core": "0.4.0",
|
|
52
|
+
"@scenarist/msw-adapter": "0.4.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"express": "^4.18.0 || ^5.0.0",
|