@scenarist/nextjs-adapter 0.1.6 → 0.1.8
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 +335 -234
- package/dist/app/context.d.ts +1 -1
- package/dist/app/context.d.ts.map +1 -1
- package/dist/app/context.js +2 -2
- package/dist/app/endpoints.d.ts +1 -1
- package/dist/app/endpoints.d.ts.map +1 -1
- package/dist/app/endpoints.js +5 -5
- package/dist/app/helpers.d.ts +0 -10
- package/dist/app/helpers.d.ts.map +1 -1
- package/dist/app/helpers.js +18 -14
- package/dist/app/impl.d.ts +3 -68
- package/dist/app/impl.d.ts.map +1 -1
- package/dist/app/impl.js +3 -15
- package/dist/app/index.d.ts +7 -7
- package/dist/app/index.js +5 -5
- package/dist/app/production.d.ts +1 -1
- package/dist/app/production.d.ts.map +1 -1
- package/dist/app/production.js +2 -2
- package/dist/app/production.test.js +62 -62
- package/dist/app/setup.d.ts +2 -2
- package/dist/app/setup.js +1 -1
- package/dist/common/create-scenarist-base.d.ts +2 -2
- package/dist/common/create-scenarist-base.d.ts.map +1 -1
- package/dist/common/create-scenarist-base.js +7 -6
- package/dist/common/endpoint-handlers.d.ts +1 -1
- package/dist/common/endpoint-handlers.js +5 -5
- package/dist/pages/context.d.ts +2 -2
- package/dist/pages/context.d.ts.map +1 -1
- package/dist/pages/context.js +5 -5
- package/dist/pages/endpoints.d.ts +2 -2
- package/dist/pages/endpoints.d.ts.map +1 -1
- package/dist/pages/endpoints.js +5 -5
- package/dist/pages/helpers.d.ts +2 -7
- package/dist/pages/helpers.d.ts.map +1 -1
- package/dist/pages/helpers.js +16 -6
- package/dist/pages/impl.d.ts +3 -41
- package/dist/pages/impl.d.ts.map +1 -1
- package/dist/pages/impl.js +3 -10
- package/dist/pages/index.d.ts +7 -7
- package/dist/pages/index.js +5 -5
- package/dist/pages/production.d.ts +2 -2
- package/dist/pages/production.test.js +78 -70
- package/dist/pages/setup.d.ts +2 -2
- package/dist/pages/setup.js +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-scenarist-base.d.ts","sourceRoot":"","sources":["../../src/common/create-scenarist-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AAGzB;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;IAChD,QAAQ,CAAC,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,kBAAkB,KAC1B,
|
|
1
|
+
{"version":3,"file":"create-scenarist-base.d.ts","sourceRoot":"","sources":["../../src/common/create-scenarist-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AAGzB;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;IAChD,QAAQ,CAAC,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,kBAAkB,KAC1B,kBAyDF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { setupServer } from
|
|
2
|
-
import { buildConfig, createScenarioManager, createResponseSelector, InMemoryScenarioRegistry, InMemoryScenarioStore, createInMemorySequenceTracker, createInMemoryStateManager, SCENARIST_TEST_ID_HEADER, } from
|
|
3
|
-
import { createDynamicHandler } from
|
|
1
|
+
import { setupServer } from "msw/node";
|
|
2
|
+
import { buildConfig, createScenarioManager, createResponseSelector, InMemoryScenarioRegistry, InMemoryScenarioStore, createInMemorySequenceTracker, createInMemoryStateManager, SCENARIST_TEST_ID_HEADER, } from "@scenarist/core";
|
|
3
|
+
import { createDynamicHandler } from "@scenarist/msw-adapter";
|
|
4
4
|
/**
|
|
5
5
|
* Creates the base Scenarist setup shared by both Pages and App Router.
|
|
6
6
|
*
|
|
@@ -16,11 +16,12 @@ import { createDynamicHandler } from '@scenarist/msw-adapter';
|
|
|
16
16
|
export const createScenaristBase = (options) => {
|
|
17
17
|
const config = buildConfig(options);
|
|
18
18
|
// Use injected ports or in-memory defaults
|
|
19
|
+
// Note: registry/store fallback branches are exercised via singleton pattern in impl.ts
|
|
20
|
+
// (globals pass these through, but v8 coverage can't trace that execution path)
|
|
19
21
|
const registry = options.registry ?? new InMemoryScenarioRegistry();
|
|
20
22
|
const store = options.store ?? new InMemoryScenarioStore();
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const sequenceTracker = createInMemorySequenceTracker();
|
|
23
|
+
const stateManager = options.stateManager ?? createInMemoryStateManager();
|
|
24
|
+
const sequenceTracker = options.sequenceTracker ?? createInMemorySequenceTracker();
|
|
24
25
|
// Create scenario manager with all dependencies
|
|
25
26
|
const manager = createScenarioManager({
|
|
26
27
|
registry,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { ScenarioRequestSchema, } from
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ScenarioRequestSchema, } from "@scenarist/core";
|
|
3
3
|
/**
|
|
4
4
|
* Business logic for POST scenario endpoint.
|
|
5
5
|
*
|
|
@@ -61,7 +61,7 @@ export const handlePostLogic = async (body, context, manager) => {
|
|
|
61
61
|
return {
|
|
62
62
|
success: false,
|
|
63
63
|
status: 400,
|
|
64
|
-
error:
|
|
64
|
+
error: "Invalid request body",
|
|
65
65
|
details: error.issues,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
@@ -69,7 +69,7 @@ export const handlePostLogic = async (body, context, manager) => {
|
|
|
69
69
|
return {
|
|
70
70
|
success: false,
|
|
71
71
|
status: 500,
|
|
72
|
-
error:
|
|
72
|
+
error: "Internal server error",
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
};
|
|
@@ -108,7 +108,7 @@ export const handleGetLogic = (context, manager) => {
|
|
|
108
108
|
return {
|
|
109
109
|
success: false,
|
|
110
110
|
status: 404,
|
|
111
|
-
error:
|
|
111
|
+
error: "No active scenario for this test ID",
|
|
112
112
|
testId,
|
|
113
113
|
};
|
|
114
114
|
}
|
package/dist/pages/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NextApiRequest } from
|
|
2
|
-
import { type RequestContext, type ScenaristConfig } from
|
|
1
|
+
import type { NextApiRequest } from "next";
|
|
2
|
+
import { type RequestContext, type ScenaristConfig } from "@scenarist/core";
|
|
3
3
|
/**
|
|
4
4
|
* RequestContext implementation for Next.js Pages Router.
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/pages/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/pages/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAC;AAEzB;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IAEtD,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,eAAe;IAG1C,SAAS,IAAI,MAAM;IAcnB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;IAI3D,WAAW,IAAI,MAAM;CAgBtB"}
|
package/dist/pages/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SCENARIST_TEST_ID_HEADER } from
|
|
1
|
+
import { SCENARIST_TEST_ID_HEADER, } from "@scenarist/core";
|
|
2
2
|
/**
|
|
3
3
|
* RequestContext implementation for Next.js Pages Router.
|
|
4
4
|
*
|
|
@@ -14,7 +14,7 @@ export class PagesRequestContext {
|
|
|
14
14
|
}
|
|
15
15
|
getTestId() {
|
|
16
16
|
const header = this.req.headers[SCENARIST_TEST_ID_HEADER];
|
|
17
|
-
if (typeof header ===
|
|
17
|
+
if (typeof header === "string") {
|
|
18
18
|
return header;
|
|
19
19
|
}
|
|
20
20
|
if (Array.isArray(header) && header.length > 0 && header[0]) {
|
|
@@ -28,14 +28,14 @@ export class PagesRequestContext {
|
|
|
28
28
|
getHostname() {
|
|
29
29
|
const host = this.req.headers.host;
|
|
30
30
|
if (!host) {
|
|
31
|
-
return
|
|
31
|
+
return "";
|
|
32
32
|
}
|
|
33
33
|
// After null check, host is string | string[]
|
|
34
|
-
if (typeof host ===
|
|
34
|
+
if (typeof host === "string") {
|
|
35
35
|
return host;
|
|
36
36
|
}
|
|
37
37
|
// host must be string[] at this point (type assertion needed due to TS control flow limitation)
|
|
38
38
|
const hostArray = host;
|
|
39
|
-
return hostArray.length > 0 ? hostArray[0] ??
|
|
39
|
+
return hostArray.length > 0 ? (hostArray[0] ?? "") : "";
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NextApiRequest, NextApiResponse } from
|
|
2
|
-
import type { ScenarioManager, ScenaristConfig } from
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from "next";
|
|
2
|
+
import type { ScenarioManager, ScenaristConfig } from "@scenarist/core";
|
|
3
3
|
/**
|
|
4
4
|
* Create scenario endpoint handler for Next.js Pages Router.
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/pages/endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/pages/endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAgExE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,eAAe,EACxB,QAAQ,eAAe,MAKT,KAAK,cAAc,EAAE,KAAK,eAAe,KAAG,OAAO,CAAC,IAAI,CAavE,CAAC"}
|
package/dist/pages/endpoints.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PagesRequestContext } from
|
|
2
|
-
import { handlePostLogic, handleGetLogic } from
|
|
1
|
+
import { PagesRequestContext } from "./context.js";
|
|
2
|
+
import { handlePostLogic, handleGetLogic, } from "../common/endpoint-handlers.js";
|
|
3
3
|
/**
|
|
4
4
|
* Handle POST request to switch scenarios.
|
|
5
5
|
*
|
|
@@ -71,14 +71,14 @@ export const createScenarioEndpoint = (manager, config) => {
|
|
|
71
71
|
const postHandler = handlePost(manager, config);
|
|
72
72
|
const getHandler = handleGet(manager, config);
|
|
73
73
|
return async (req, res) => {
|
|
74
|
-
if (req.method ===
|
|
74
|
+
if (req.method === "POST") {
|
|
75
75
|
return postHandler(req, res);
|
|
76
76
|
}
|
|
77
|
-
if (req.method ===
|
|
77
|
+
if (req.method === "GET") {
|
|
78
78
|
return getHandler(req, res);
|
|
79
79
|
}
|
|
80
80
|
res.status(405).json({
|
|
81
|
-
error:
|
|
81
|
+
error: "Method not allowed",
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
84
|
};
|
package/dist/pages/helpers.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { IncomingMessage } from
|
|
1
|
+
import type { IncomingMessage } from "http";
|
|
2
2
|
/**
|
|
3
3
|
* Type for request objects that have headers.
|
|
4
4
|
* Compatible with both NextApiRequest and GetServerSidePropsContext.req
|
|
5
5
|
*/
|
|
6
6
|
type RequestWithHeaders = {
|
|
7
|
-
headers: IncomingMessage[
|
|
7
|
+
headers: IncomingMessage["headers"];
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Safe helper to extract Scenarist infrastructure headers from a request.
|
|
@@ -18,11 +18,6 @@ type RequestWithHeaders = {
|
|
|
18
18
|
* - Safe to spread in fetch headers without guards
|
|
19
19
|
* - Zero runtime overhead (tree-shaken in production builds)
|
|
20
20
|
*
|
|
21
|
-
* **Why use this instead of scenarist.getHeaders()?**
|
|
22
|
-
* - No need to check if scenarist is defined (`scenarist?.getHeaders(req) ?? {}`)
|
|
23
|
-
* - Works automatically by accessing the global singleton
|
|
24
|
-
* - Consistent API across development, test, and production
|
|
25
|
-
*
|
|
26
21
|
* @param req - Request object with headers (NextApiRequest or GetServerSidePropsContext.req)
|
|
27
22
|
* @returns Object with single entry: configured test ID header name → value from request or default
|
|
28
23
|
* Returns `{}` in production when scenarist is undefined
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/pages/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/pages/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAS5C;;;GAGG;AACH,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,kBAAkB,GACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBxB"}
|
package/dist/pages/helpers.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { SCENARIST_TEST_ID_HEADER } from "@scenarist/core";
|
|
2
|
+
/**
|
|
3
|
+
* Fallback constant for default test ID when scenarist is undefined (production builds).
|
|
4
|
+
* In development/test, this is overridden by values from scenarist.config.
|
|
5
|
+
*/
|
|
6
|
+
const FALLBACK_DEFAULT_TEST_ID = "default-test";
|
|
1
7
|
/**
|
|
2
8
|
* Safe helper to extract Scenarist infrastructure headers from a request.
|
|
3
9
|
*
|
|
@@ -10,11 +16,6 @@
|
|
|
10
16
|
* - Safe to spread in fetch headers without guards
|
|
11
17
|
* - Zero runtime overhead (tree-shaken in production builds)
|
|
12
18
|
*
|
|
13
|
-
* **Why use this instead of scenarist.getHeaders()?**
|
|
14
|
-
* - No need to check if scenarist is defined (`scenarist?.getHeaders(req) ?? {}`)
|
|
15
|
-
* - Works automatically by accessing the global singleton
|
|
16
|
-
* - Consistent API across development, test, and production
|
|
17
|
-
*
|
|
18
19
|
* @param req - Request object with headers (NextApiRequest or GetServerSidePropsContext.req)
|
|
19
20
|
* @returns Object with single entry: configured test ID header name → value from request or default
|
|
20
21
|
* Returns `{}` in production when scenarist is undefined
|
|
@@ -45,5 +46,14 @@
|
|
|
45
46
|
*/
|
|
46
47
|
export function getScenaristHeaders(req) {
|
|
47
48
|
const scenarist = global.__scenarist_instance_pages;
|
|
48
|
-
|
|
49
|
+
if (!scenarist) {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
const defaultTestId = scenarist.config?.defaultTestId ?? FALLBACK_DEFAULT_TEST_ID;
|
|
53
|
+
const headerValue = req.headers[SCENARIST_TEST_ID_HEADER];
|
|
54
|
+
const testId = (Array.isArray(headerValue) ? headerValue[0] : headerValue) ??
|
|
55
|
+
defaultTestId;
|
|
56
|
+
return {
|
|
57
|
+
[SCENARIST_TEST_ID_HEADER]: testId,
|
|
58
|
+
};
|
|
49
59
|
}
|
package/dist/pages/impl.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import { createScenarioEndpoint } from './endpoints.js';
|
|
1
|
+
import type { BaseAdapterOptions, ScenaristAdapter, ScenarioRegistry, ScenarioStore } from "@scenarist/core";
|
|
2
|
+
import { createScenarioEndpoint } from "./endpoints.js";
|
|
4
3
|
/**
|
|
5
4
|
* Global state for Next.js Pages Router adapter.
|
|
6
5
|
*
|
|
@@ -24,13 +23,6 @@ declare global {
|
|
|
24
23
|
var __scenarist_store_pages: ScenarioStore | undefined;
|
|
25
24
|
var __scenarist_instance_pages: PagesScenarist | undefined;
|
|
26
25
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Type for request objects that have headers.
|
|
29
|
-
* Compatible with both NextApiRequest and GetServerSidePropsContext.req
|
|
30
|
-
*/
|
|
31
|
-
type RequestWithHeaders = {
|
|
32
|
-
headers: IncomingMessage['headers'];
|
|
33
|
-
};
|
|
34
26
|
/**
|
|
35
27
|
* Next.js Pages Router adapter options.
|
|
36
28
|
*
|
|
@@ -43,7 +35,7 @@ export type PagesAdapterOptions = BaseAdapterOptions;
|
|
|
43
35
|
* Provides MSW server lifecycle management and scenario endpoint factory.
|
|
44
36
|
* Unlike Express adapter, doesn't provide middleware (Next.js doesn't have global middleware for Pages Router).
|
|
45
37
|
*/
|
|
46
|
-
export type PagesScenarist = Omit<ScenaristAdapter<never>,
|
|
38
|
+
export type PagesScenarist = Omit<ScenaristAdapter<never>, "middleware"> & {
|
|
47
39
|
/**
|
|
48
40
|
* Create scenario endpoint handler for use in pages/api/__scenario__.ts
|
|
49
41
|
*
|
|
@@ -56,35 +48,6 @@ export type PagesScenarist = Omit<ScenaristAdapter<never>, 'middleware'> & {
|
|
|
56
48
|
* ```
|
|
57
49
|
*/
|
|
58
50
|
createScenarioEndpoint: () => ReturnType<typeof createScenarioEndpoint>;
|
|
59
|
-
/**
|
|
60
|
-
* Extract Scenarist infrastructure headers from the request.
|
|
61
|
-
*
|
|
62
|
-
* This helper respects the configured test ID header name and default test ID,
|
|
63
|
-
* ensuring headers are forwarded correctly when making external API calls.
|
|
64
|
-
*
|
|
65
|
-
* Works with both NextApiRequest (API routes) and GetServerSidePropsContext.req (SSR).
|
|
66
|
-
*
|
|
67
|
-
* @param req - Request object with headers
|
|
68
|
-
* @returns Object with single entry: configured test ID header name → value from request or default
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* // API Route
|
|
73
|
-
* export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
74
|
-
* const response = await fetch('http://localhost:3001/products', {
|
|
75
|
-
* headers: scenarist.getHeaders(req),
|
|
76
|
-
* });
|
|
77
|
-
* }
|
|
78
|
-
*
|
|
79
|
-
* // getServerSideProps
|
|
80
|
-
* export const getServerSideProps: GetServerSideProps = async (context) => {
|
|
81
|
-
* const response = await fetch('http://localhost:3001/products', {
|
|
82
|
-
* headers: scenarist.getHeaders(context.req),
|
|
83
|
-
* });
|
|
84
|
-
* };
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
getHeaders: (req: RequestWithHeaders) => Record<string, string>;
|
|
88
51
|
};
|
|
89
52
|
/**
|
|
90
53
|
* Create a Scenarist instance for Next.js Pages Router (implementation).
|
|
@@ -120,5 +83,4 @@ export type PagesScenarist = Omit<ScenaristAdapter<never>, 'middleware'> & {
|
|
|
120
83
|
* ```
|
|
121
84
|
*/
|
|
122
85
|
export declare const createScenaristImpl: (options: PagesAdapterOptions) => PagesScenarist;
|
|
123
|
-
export {};
|
|
124
86
|
//# sourceMappingURL=impl.d.ts.map
|
package/dist/pages/impl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl.d.ts","sourceRoot":"","sources":["../../src/pages/impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"impl.d.ts","sourceRoot":"","sources":["../../src/pages/impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACd,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,6BAA6B,EAAE,OAAO,GAAG,SAAS,CAAC;IAEvD,IAAI,0BAA0B,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAE7D,IAAI,uBAAuB,EAAE,aAAa,GAAG,SAAS,CAAC;IAEvD,IAAI,0BAA0B,EAAE,cAAc,GAAG,SAAS,CAAC;CAC5D;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,GAAG;IACzE;;;;;;;;;;OAUG;IACH,sBAAsB,EAAE,MAAM,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,mBAAmB,KAC3B,cAsDF,CAAC"}
|
package/dist/pages/impl.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InMemoryScenarioRegistry, InMemoryScenarioStore,
|
|
2
|
-
import { createScenaristBase } from
|
|
3
|
-
import { createScenarioEndpoint } from
|
|
1
|
+
import { InMemoryScenarioRegistry, InMemoryScenarioStore, } from "@scenarist/core";
|
|
2
|
+
import { createScenaristBase } from "../common/create-scenarist-base.js";
|
|
3
|
+
import { createScenarioEndpoint } from "./endpoints.js";
|
|
4
4
|
/**
|
|
5
5
|
* Create a Scenarist instance for Next.js Pages Router (implementation).
|
|
6
6
|
*
|
|
@@ -65,13 +65,6 @@ export const createScenaristImpl = (options) => {
|
|
|
65
65
|
listScenarios: () => manager.listScenarios(),
|
|
66
66
|
clearScenario: (testId) => manager.clearScenario(testId),
|
|
67
67
|
createScenarioEndpoint: () => createScenarioEndpoint(manager, config),
|
|
68
|
-
getHeaders: (req) => {
|
|
69
|
-
const headerValue = req.headers[SCENARIST_TEST_ID_HEADER];
|
|
70
|
-
const testId = (Array.isArray(headerValue) ? headerValue[0] : headerValue) || config.defaultTestId;
|
|
71
|
-
return {
|
|
72
|
-
[SCENARIST_TEST_ID_HEADER]: testId,
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
68
|
start: () => {
|
|
76
69
|
// Singleton guard - prevents duplicate MSW initialization
|
|
77
70
|
// Next.js dev mode with HMR creates multiple module instances, so this ensures
|
package/dist/pages/index.d.ts
CHANGED
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
* afterAll(() => scenarist.stop());
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export { createScenarist } from
|
|
31
|
-
export { PagesRequestContext } from
|
|
32
|
-
export { createScenarioEndpoint } from
|
|
33
|
-
export { getScenaristHeaders } from
|
|
34
|
-
export type { PagesAdapterOptions, PagesScenarist } from
|
|
35
|
-
export { SCENARIST_TEST_ID_HEADER } from
|
|
36
|
-
export type { ScenaristScenario, ScenaristMock, ScenaristResponse, ScenaristSequence, ScenaristMatch, ScenaristCaptureConfig, ScenaristScenarios, ScenaristConfig, ScenaristResult, } from
|
|
30
|
+
export { createScenarist } from "./setup.js";
|
|
31
|
+
export { PagesRequestContext } from "./context.js";
|
|
32
|
+
export { createScenarioEndpoint } from "./endpoints.js";
|
|
33
|
+
export { getScenaristHeaders } from "./helpers.js";
|
|
34
|
+
export type { PagesAdapterOptions, PagesScenarist } from "./setup.js";
|
|
35
|
+
export { SCENARIST_TEST_ID_HEADER } from "@scenarist/core";
|
|
36
|
+
export type { ScenaristScenario, ScenaristMock, ScenaristResponse, ScenaristSequence, ScenaristMatch, ScenaristCaptureConfig, ScenaristScenarios, ScenaristConfig, ScenaristResult, } from "@scenarist/core";
|
|
37
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/pages/index.js
CHANGED
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
* afterAll(() => scenarist.stop());
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export { createScenarist } from
|
|
31
|
-
export { PagesRequestContext } from
|
|
32
|
-
export { createScenarioEndpoint } from
|
|
33
|
-
export { getScenaristHeaders } from
|
|
30
|
+
export { createScenarist } from "./setup.js";
|
|
31
|
+
export { PagesRequestContext } from "./context.js";
|
|
32
|
+
export { createScenarioEndpoint } from "./endpoints.js";
|
|
33
|
+
export { getScenaristHeaders } from "./helpers.js";
|
|
34
34
|
// Re-export core types and constants for user convenience (users should only install this adapter)
|
|
35
|
-
export { SCENARIST_TEST_ID_HEADER } from
|
|
35
|
+
export { SCENARIST_TEST_ID_HEADER } from "@scenarist/core";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { PagesAdapterOptions, PagesScenarist } from
|
|
1
|
+
export type { PagesAdapterOptions, PagesScenarist } from "./setup.js";
|
|
2
2
|
/**
|
|
3
3
|
* Production-only entry point that returns undefined without loading test dependencies.
|
|
4
4
|
*
|
|
@@ -14,5 +14,5 @@ export declare const createScenarist: (_options: import("./setup.js").PagesAdapt
|
|
|
14
14
|
/**
|
|
15
15
|
* Production stub: Returns empty object (no test headers needed in production)
|
|
16
16
|
*/
|
|
17
|
-
export declare function getScenaristHeaders(_req: import(
|
|
17
|
+
export declare function getScenaristHeaders(_req: import("next").NextApiRequest): Record<string, string>;
|
|
18
18
|
//# sourceMappingURL=production.d.ts.map
|