@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
|
@@ -115,107 +115,107 @@
|
|
|
115
115
|
* 3. Helper functions can be called without errors
|
|
116
116
|
* 4. No imports from test dependencies (tree-shaking verification)
|
|
117
117
|
*/
|
|
118
|
-
import { describe, it, expect } from
|
|
119
|
-
import * as production from
|
|
120
|
-
describe(
|
|
121
|
-
describe(
|
|
122
|
-
it(
|
|
118
|
+
import { describe, it, expect } from "vitest";
|
|
119
|
+
import * as production from "./production.js";
|
|
120
|
+
describe("Pages Router production entry point", () => {
|
|
121
|
+
describe("createScenarist", () => {
|
|
122
|
+
it("should return undefined (Scenarist disabled in production)", () => {
|
|
123
123
|
// In production builds, Scenarist should not exist at all
|
|
124
124
|
// API routes check: if (scenarist) { return scenarist.createScenarioEndpoint() }
|
|
125
125
|
const scenarist = production.createScenarist({
|
|
126
126
|
enabled: true,
|
|
127
127
|
scenarios: {
|
|
128
128
|
test: {
|
|
129
|
-
id:
|
|
130
|
-
name:
|
|
131
|
-
description:
|
|
129
|
+
id: "test",
|
|
130
|
+
name: "Test Scenario",
|
|
131
|
+
description: "A test scenario",
|
|
132
132
|
mocks: [],
|
|
133
133
|
},
|
|
134
134
|
},
|
|
135
135
|
});
|
|
136
136
|
expect(scenarist).toBeUndefined();
|
|
137
137
|
});
|
|
138
|
-
it(
|
|
138
|
+
it("should accept same options as development version (type safety)", () => {
|
|
139
139
|
// This ensures the production stub has the same TypeScript signature
|
|
140
140
|
// as the real implementation, preventing type errors in user code
|
|
141
141
|
const scenarist = production.createScenarist({
|
|
142
142
|
enabled: false,
|
|
143
143
|
scenarios: {
|
|
144
144
|
default: {
|
|
145
|
-
id:
|
|
146
|
-
name:
|
|
147
|
-
description:
|
|
145
|
+
id: "default",
|
|
146
|
+
name: "Default Scenario",
|
|
147
|
+
description: "Default test scenario",
|
|
148
148
|
mocks: [],
|
|
149
149
|
},
|
|
150
150
|
},
|
|
151
|
-
defaultTestId:
|
|
151
|
+
defaultTestId: "test-123",
|
|
152
152
|
});
|
|
153
153
|
expect(scenarist).toBeUndefined();
|
|
154
154
|
});
|
|
155
155
|
});
|
|
156
|
-
describe(
|
|
157
|
-
it(
|
|
156
|
+
describe("getScenaristHeaders", () => {
|
|
157
|
+
it("should return empty object (no test headers in production)", () => {
|
|
158
158
|
const mockRequest = {
|
|
159
159
|
headers: {
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
"x-scenarist-test-id": "test-123",
|
|
161
|
+
"x-user-id": "user-456",
|
|
162
162
|
},
|
|
163
|
-
method:
|
|
164
|
-
url:
|
|
163
|
+
method: "GET",
|
|
164
|
+
url: "/api/test",
|
|
165
165
|
};
|
|
166
166
|
const headers = production.getScenaristHeaders(mockRequest);
|
|
167
167
|
// Production: No test infrastructure headers added
|
|
168
168
|
expect(headers).toEqual({});
|
|
169
169
|
expect(Object.keys(headers)).toHaveLength(0);
|
|
170
170
|
});
|
|
171
|
-
it(
|
|
171
|
+
it("should be safe to spread in fetch headers", () => {
|
|
172
172
|
const mockRequest = {
|
|
173
173
|
headers: {},
|
|
174
|
-
method:
|
|
175
|
-
url:
|
|
174
|
+
method: "GET",
|
|
175
|
+
url: "/api/test",
|
|
176
176
|
};
|
|
177
177
|
const headers = production.getScenaristHeaders(mockRequest);
|
|
178
178
|
// This pattern works in all environments without guards
|
|
179
179
|
const fetchHeaders = {
|
|
180
|
-
|
|
180
|
+
"content-type": "application/json",
|
|
181
181
|
...headers, // Spreading {} is a no-op
|
|
182
182
|
};
|
|
183
183
|
expect(fetchHeaders).toEqual({
|
|
184
|
-
|
|
184
|
+
"content-type": "application/json",
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
|
-
it(
|
|
187
|
+
it("should ignore NextApiRequest properties in production", () => {
|
|
188
188
|
const mockRequest = {
|
|
189
189
|
headers: {
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
"x-scenarist-test-id": "test-abc",
|
|
191
|
+
"x-scenario": "premium",
|
|
192
192
|
},
|
|
193
|
-
method:
|
|
194
|
-
url:
|
|
195
|
-
body: { item:
|
|
193
|
+
method: "POST",
|
|
194
|
+
url: "/api/cart/add",
|
|
195
|
+
body: { item: "product-1" },
|
|
196
196
|
};
|
|
197
197
|
const headers = production.getScenaristHeaders(mockRequest);
|
|
198
198
|
// Production stub doesn't read request properties, just returns {}
|
|
199
199
|
expect(headers).toEqual({});
|
|
200
200
|
});
|
|
201
201
|
});
|
|
202
|
-
describe(
|
|
203
|
-
it(
|
|
202
|
+
describe("tree-shaking verification", () => {
|
|
203
|
+
it("should export only stub functions with no test dependencies", () => {
|
|
204
204
|
// Verify all expected exports exist
|
|
205
205
|
expect(production.createScenarist).toBeDefined();
|
|
206
206
|
expect(production.getScenaristHeaders).toBeDefined();
|
|
207
207
|
// Verify stubs are simple functions (not complex objects)
|
|
208
|
-
expect(typeof production.createScenarist).toBe(
|
|
209
|
-
expect(typeof production.getScenaristHeaders).toBe(
|
|
208
|
+
expect(typeof production.createScenarist).toBe("function");
|
|
209
|
+
expect(typeof production.getScenaristHeaders).toBe("function");
|
|
210
210
|
});
|
|
211
|
-
it(
|
|
211
|
+
it("should not have any Scenarist instance methods", () => {
|
|
212
212
|
const scenarist = production.createScenarist({
|
|
213
213
|
enabled: true,
|
|
214
214
|
scenarios: {
|
|
215
215
|
default: {
|
|
216
|
-
id:
|
|
217
|
-
name:
|
|
218
|
-
description:
|
|
216
|
+
id: "default",
|
|
217
|
+
name: "Default",
|
|
218
|
+
description: "Default scenario",
|
|
219
219
|
mocks: [],
|
|
220
220
|
},
|
|
221
221
|
},
|
|
@@ -228,30 +228,30 @@ describe('Pages Router production entry point', () => {
|
|
|
228
228
|
expect(scenarist?.stop).toBeUndefined();
|
|
229
229
|
expect(scenarist?.createScenarioEndpoint).toBeUndefined();
|
|
230
230
|
});
|
|
231
|
-
it(
|
|
231
|
+
it("should have fewer exports than App Router (simpler API surface)", () => {
|
|
232
232
|
const exports = Object.keys(production);
|
|
233
233
|
// Pages Router only needs:
|
|
234
234
|
// - createScenarist
|
|
235
235
|
// - getScenaristHeaders
|
|
236
236
|
// (No ReadonlyHeaders variants, no getTestId variants)
|
|
237
|
-
expect(exports).toContain(
|
|
238
|
-
expect(exports).toContain(
|
|
237
|
+
expect(exports).toContain("createScenarist");
|
|
238
|
+
expect(exports).toContain("getScenaristHeaders");
|
|
239
239
|
// App Router has these additional exports:
|
|
240
240
|
// - getScenaristHeadersFromReadonlyHeaders
|
|
241
241
|
// - getScenaristTestId
|
|
242
242
|
// - getScenaristTestIdFromReadonlyHeaders
|
|
243
|
-
expect(exports).not.toContain(
|
|
244
|
-
expect(exports).not.toContain(
|
|
245
|
-
expect(exports).not.toContain(
|
|
243
|
+
expect(exports).not.toContain("getScenaristHeadersFromReadonlyHeaders");
|
|
244
|
+
expect(exports).not.toContain("getScenaristTestId");
|
|
245
|
+
expect(exports).not.toContain("getScenaristTestIdFromReadonlyHeaders");
|
|
246
246
|
});
|
|
247
247
|
});
|
|
248
|
-
describe(
|
|
249
|
-
it(
|
|
248
|
+
describe("production safety", () => {
|
|
249
|
+
it("should handle being called multiple times without errors", () => {
|
|
250
250
|
// Production code might call these helpers frequently
|
|
251
251
|
const mockRequest = {
|
|
252
252
|
headers: {},
|
|
253
|
-
method:
|
|
254
|
-
url:
|
|
253
|
+
method: "GET",
|
|
254
|
+
url: "/api/test",
|
|
255
255
|
};
|
|
256
256
|
expect(() => {
|
|
257
257
|
for (let i = 0; i < 100; i++) {
|
|
@@ -259,57 +259,65 @@ describe('Pages Router production entry point', () => {
|
|
|
259
259
|
}
|
|
260
260
|
}).not.toThrow();
|
|
261
261
|
});
|
|
262
|
-
it(
|
|
262
|
+
it("should return consistent results for same inputs", () => {
|
|
263
263
|
const mockRequest = {
|
|
264
|
-
headers: {
|
|
265
|
-
method:
|
|
266
|
-
url:
|
|
264
|
+
headers: { "x-scenarist-test-id": "test-123" },
|
|
265
|
+
method: "GET",
|
|
266
|
+
url: "/api/test",
|
|
267
267
|
};
|
|
268
268
|
const headers1 = production.getScenaristHeaders(mockRequest);
|
|
269
269
|
const headers2 = production.getScenaristHeaders(mockRequest);
|
|
270
270
|
expect(headers1).toEqual(headers2);
|
|
271
271
|
});
|
|
272
|
-
it(
|
|
272
|
+
it("should work with various NextApiRequest shapes", () => {
|
|
273
273
|
// Different request shapes should all work safely
|
|
274
274
|
const requests = [
|
|
275
|
-
{ headers: {}, method:
|
|
276
|
-
{
|
|
277
|
-
|
|
275
|
+
{ headers: {}, method: "GET", url: "/" },
|
|
276
|
+
{
|
|
277
|
+
headers: { "x-scenarist-test-id": "abc" },
|
|
278
|
+
method: "POST",
|
|
279
|
+
url: "/api/test",
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
headers: { "x-custom": "value" },
|
|
283
|
+
method: "PUT",
|
|
284
|
+
url: "/api/update",
|
|
285
|
+
},
|
|
278
286
|
];
|
|
279
287
|
requests.forEach((req) => {
|
|
280
288
|
expect(production.getScenaristHeaders(req)).toEqual({});
|
|
281
289
|
});
|
|
282
290
|
});
|
|
283
291
|
});
|
|
284
|
-
describe(
|
|
285
|
-
it(
|
|
292
|
+
describe("Pages Router specific behavior", () => {
|
|
293
|
+
it("should be compatible with Pages Router API route pattern", () => {
|
|
286
294
|
// Typical Pages Router API route usage
|
|
287
295
|
const mockRequest = {
|
|
288
296
|
headers: {
|
|
289
|
-
|
|
297
|
+
"content-type": "application/json",
|
|
290
298
|
},
|
|
291
|
-
method:
|
|
292
|
-
url:
|
|
299
|
+
method: "POST",
|
|
300
|
+
url: "/api/cart/add",
|
|
293
301
|
body: { productId: 1 },
|
|
294
302
|
};
|
|
295
303
|
const scenaristHeaders = production.getScenaristHeaders(mockRequest);
|
|
296
304
|
// In production, this should be a no-op
|
|
297
305
|
const requestHeaders = {
|
|
298
|
-
|
|
306
|
+
"content-type": "application/json",
|
|
299
307
|
...scenaristHeaders,
|
|
300
308
|
};
|
|
301
309
|
expect(requestHeaders).toEqual({
|
|
302
|
-
|
|
310
|
+
"content-type": "application/json",
|
|
303
311
|
});
|
|
304
312
|
});
|
|
305
|
-
it(
|
|
313
|
+
it("should not interfere with existing headers", () => {
|
|
306
314
|
const mockRequest = {
|
|
307
315
|
headers: {
|
|
308
|
-
authorization:
|
|
309
|
-
|
|
316
|
+
authorization: "Bearer token123",
|
|
317
|
+
"x-api-key": "secret",
|
|
310
318
|
},
|
|
311
|
-
method:
|
|
312
|
-
url:
|
|
319
|
+
method: "GET",
|
|
320
|
+
url: "/api/protected",
|
|
313
321
|
};
|
|
314
322
|
const scenaristHeaders = production.getScenaristHeaders(mockRequest);
|
|
315
323
|
const allHeaders = {
|
|
@@ -318,8 +326,8 @@ describe('Pages Router production entry point', () => {
|
|
|
318
326
|
};
|
|
319
327
|
// Production stub shouldn't modify or remove existing headers
|
|
320
328
|
expect(allHeaders).toEqual({
|
|
321
|
-
authorization:
|
|
322
|
-
|
|
329
|
+
authorization: "Bearer token123",
|
|
330
|
+
"x-api-key": "secret",
|
|
323
331
|
});
|
|
324
332
|
});
|
|
325
333
|
});
|
package/dist/pages/setup.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { PagesAdapterOptions, PagesScenarist } from
|
|
1
|
+
export type { PagesAdapterOptions, PagesScenarist } from "./impl.js";
|
|
2
2
|
/**
|
|
3
3
|
* Create a Scenarist instance for Next.js Pages Router.
|
|
4
4
|
*
|
|
@@ -25,5 +25,5 @@ export type { PagesAdapterOptions, PagesScenarist } from './impl.js';
|
|
|
25
25
|
* }
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export { createScenaristImpl as createScenarist } from
|
|
28
|
+
export { createScenaristImpl as createScenarist } from "./impl.js";
|
|
29
29
|
//# sourceMappingURL=setup.d.ts.map
|
package/dist/pages/setup.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenarist/nextjs-adapter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Next.js adapter for Scenarist (Pages Router and App Router)",
|
|
5
5
|
"author": "Paul Hammond (citypaul) <paul@packsoftware.co.uk>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"next": "^14.0.0",
|
|
75
75
|
"typescript": "^5.9.3",
|
|
76
76
|
"vitest": "^4.0.14",
|
|
77
|
-
"@scenarist/
|
|
78
|
-
"@scenarist/
|
|
77
|
+
"@scenarist/typescript-config": "0.0.0",
|
|
78
|
+
"@scenarist/eslint-config": "^0.0.0"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc",
|