@scenarist/playwright-helpers 0.1.8 → 0.1.9
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 +30 -2
- package/dist/switch-scenario.d.ts.map +1 -1
- package/dist/switch-scenario.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -233,12 +233,14 @@ test("premium user scenario", async ({ page }) => {
|
|
|
233
233
|
```typescript
|
|
234
234
|
type SwitchScenarioOptions = {
|
|
235
235
|
readonly baseURL: string; // Base URL of your application
|
|
236
|
-
readonly endpoint?: string; // Scenario endpoint path (default: '/__scenario__')
|
|
236
|
+
readonly endpoint?: string; // Scenario endpoint path or absolute URL (default: '/__scenario__')
|
|
237
237
|
readonly testIdHeader?: string; // Test ID header name (default: 'x-scenarist-test-id')
|
|
238
238
|
readonly variant?: string; // Optional scenario variant
|
|
239
239
|
};
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
+
> **Tip:** Use an absolute URL for `endpoint` when your API runs on a different host/port than the frontend. See [Cross-Origin API Servers](#cross-origin-api-servers).
|
|
243
|
+
|
|
242
244
|
#### What it does
|
|
243
245
|
|
|
244
246
|
The `switchScenario` helper:
|
|
@@ -330,7 +332,33 @@ export default defineConfig({
|
|
|
330
332
|
|
|
331
333
|
**Available options:**
|
|
332
334
|
|
|
333
|
-
- `scenaristEndpoint?: string` - The endpoint path for scenario switching (default: `'/api/__scenario__'`)
|
|
335
|
+
- `scenaristEndpoint?: string` - The endpoint path or absolute URL for scenario switching (default: `'/api/__scenario__'`)
|
|
336
|
+
|
|
337
|
+
### Cross-Origin API Servers
|
|
338
|
+
|
|
339
|
+
When your API server runs on a different host or port than your frontend, use an **absolute URL** for `scenaristEndpoint`:
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
// Frontend: http://localhost:3000
|
|
343
|
+
// API Server: http://localhost:9090
|
|
344
|
+
export default defineConfig<ScenaristOptions>({
|
|
345
|
+
use: {
|
|
346
|
+
baseURL: "http://localhost:3000", // Frontend URL (for Playwright navigation)
|
|
347
|
+
scenaristEndpoint: "http://localhost:9090/__scenario__", // Absolute URL to API
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**How it works:**
|
|
353
|
+
|
|
354
|
+
- **Relative paths** (e.g., `/api/__scenario__`) are prepended with `baseURL`
|
|
355
|
+
- **Absolute URLs** (starting with `http://` or `https://`) are used directly, ignoring `baseURL`
|
|
356
|
+
|
|
357
|
+
This is useful when:
|
|
358
|
+
|
|
359
|
+
- Your API and frontend are separate services on different ports
|
|
360
|
+
- You're testing against a staging/production API endpoint
|
|
361
|
+
- Your test infrastructure uses a separate mock server
|
|
334
362
|
|
|
335
363
|
#### `switchScenario` (Fixture)
|
|
336
364
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch-scenario.d.ts","sourceRoot":"","sources":["../src/switch-scenario.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAG7C;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AA8BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,cAAc,GACzB,MAAM,IAAI,EACV,YAAY,MAAM,EAClB,SAAS,qBAAqB,KAC7B,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"switch-scenario.d.ts","sourceRoot":"","sources":["../src/switch-scenario.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAG7C;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AA8BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,cAAc,GACzB,MAAM,IAAI,EACV,YAAY,MAAM,EAClB,SAAS,qBAAqB,KAC7B,OAAO,CAAC,MAAM,CAsChB,CAAC"}
|
package/dist/switch-scenario.js
CHANGED
|
@@ -63,7 +63,9 @@ export const switchScenario = async (page, scenarioId, options) => {
|
|
|
63
63
|
// Client Components may fire API calls immediately on mount/navigation
|
|
64
64
|
await establishTestIdInterception(page, testId);
|
|
65
65
|
// Call scenario endpoint
|
|
66
|
-
|
|
66
|
+
// Support absolute URLs for when API is on different host/port than frontend
|
|
67
|
+
const isAbsoluteUrl = endpoint.startsWith("http://") || endpoint.startsWith("https://");
|
|
68
|
+
const url = isAbsoluteUrl ? endpoint : `${baseURL}${endpoint}`;
|
|
67
69
|
const response = await page.request.post(url, {
|
|
68
70
|
headers: { [SCENARIST_TEST_ID_HEADER]: testId },
|
|
69
71
|
data: {
|
package/package.json
CHANGED