@sgedda/mockifyer-fetch 1.8.98 → 1.8.100
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/dist/index.js +2 -2
- package/dist/react-native.d.ts +4 -2
- package/dist/react-native.js +13 -10
- package/package.json +2 -2
- package/src/index.ts +3 -3
- package/src/react-native.ts +18 -14
package/dist/index.js
CHANGED
|
@@ -165,7 +165,7 @@ class MockifyerClass {
|
|
|
165
165
|
*/
|
|
166
166
|
prepareStoredResponseBody(mockData, filename, scenarioPath) {
|
|
167
167
|
const joinPath = path && typeof path.join === 'function' ? path.join.bind(path) : null;
|
|
168
|
-
return (0, mockifyer_core_1.prepareMockResponseBody)(mockData, mockifyer_core_1.
|
|
168
|
+
return (0, mockifyer_core_1.prepareMockResponseBody)(mockData, (0, mockifyer_core_1.createServeTimeClock)(this.config), {
|
|
169
169
|
loadPoolResponse: (0, mockifyer_core_1.createServeTimePoolResponseLoader)({
|
|
170
170
|
mockDataPath: this.config.mockDataPath,
|
|
171
171
|
nodeFs: (0, mockifyer_core_1.isUsableNodeLikePoolFs)(fs) ? fs : null,
|
|
@@ -895,7 +895,7 @@ class MockifyerClass {
|
|
|
895
895
|
if (liveScenarioPath) {
|
|
896
896
|
(0, mockifyer_core_1.ensureOverrideGroupRuntimeForScenarioPath)(liveScenarioPath, { clientId: this.config.clientId });
|
|
897
897
|
}
|
|
898
|
-
const clientResponse = (0, mockifyer_core_1.buildClientResponseFromLiveCapture)(matchedMock.mockData, capturedResponse, mockifyer_core_1.
|
|
898
|
+
const clientResponse = (0, mockifyer_core_1.buildClientResponseFromLiveCapture)(matchedMock.mockData, capturedResponse, (0, mockifyer_core_1.createServeTimeClock)(this.config), { filename: matchedMock.filename, scenarioPath: liveScenarioPath });
|
|
899
899
|
response.data = clientResponse.data;
|
|
900
900
|
response.status = clientResponse.status;
|
|
901
901
|
delete response.config.__mockifyer_matchedMock;
|
package/dist/react-native.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface MockifyerInstance extends HTTPClient {
|
|
|
22
22
|
/**
|
|
23
23
|
* Outcome of {@link setupMockifyerForReactNative}.
|
|
24
24
|
*
|
|
25
|
-
* - **`not_activated`** — `fetch` was not patched this run (see **`MOCKIFYER_MODE`** / `runtimeMode`: `off`, or `launch_client` without a launch-arg lane).
|
|
25
|
+
* - **`not_activated`** — `fetch` was not patched this run (see **`MOCKIFYER_MODE`** / `runtimeMode`: `off`, or `launch_client` without a launch-arg lane or scenario).
|
|
26
26
|
* Not the same as “permanently off” unless mode is **`off`** (then launch args do not activate).
|
|
27
27
|
* - **`active`** — Mockifyer initialized and patched `global.fetch`.
|
|
28
28
|
* - **`failed_no_bundled_mocks`** — Activation criteria were met and `isDev` was false, but bundled mock data was missing or empty.
|
|
@@ -72,7 +72,9 @@ export interface ReactNativeMockifyerConfig {
|
|
|
72
72
|
/**
|
|
73
73
|
* When true, reads `scenario` from `react-native-launch-arguments` (optional peer).
|
|
74
74
|
* Highest priority over MOCKIFYER_SCENARIO, config.scenarios, Metro scenario sync, and scenario-config.json.
|
|
75
|
-
* When a launch `scenario` is present, Mockifyer
|
|
75
|
+
* When a launch `scenario` is present, Mockifyer **activates** (also under `launch_client`, no lane needed),
|
|
76
|
+
* **starts enabled** (even with `runtimeMode: 'manual'`), and sends it as the dashboard proxy scenario
|
|
77
|
+
* (unless `proxyScenario` is set). `runtimeMode: 'off'` still wins.
|
|
76
78
|
* Set to `false` to ignore launch scenario args entirely.
|
|
77
79
|
* Default: auto-detect when a non-empty launch `scenario` is present.
|
|
78
80
|
*/
|
package/dist/react-native.js
CHANGED
|
@@ -41,26 +41,26 @@ function isMockifyerReactNativeActive(result) {
|
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Apply scenario from launch arguments and/or defaultScenario (highest priority in getCurrentScenario).
|
|
44
|
-
* @returns
|
|
44
|
+
* @returns The native launch-argument `scenario` when one was applied (activates Mockifyer, forces runtime toggle on,
|
|
45
|
+
* and is sent as the proxy scenario); otherwise `undefined`.
|
|
45
46
|
*/
|
|
46
47
|
function applyReactNativeScenarioOptions(options) {
|
|
47
|
-
let appliedFromLaunchArgs = false;
|
|
48
48
|
// Auto-detect launch `scenario` when present (E2E). Opt out with useLaunchArgumentsScenario: false.
|
|
49
49
|
if (options.useLaunchArgumentsScenario !== false) {
|
|
50
50
|
const scenarioFromLaunch = (0, mockifyer_core_2.tryGetScenarioFromLaunchArguments)();
|
|
51
51
|
if (scenarioFromLaunch) {
|
|
52
52
|
(0, mockifyer_core_1.setScenarioLaunchOverride)(scenarioFromLaunch, { fromLaunchArguments: true });
|
|
53
|
-
|
|
53
|
+
return scenarioFromLaunch;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
if (
|
|
56
|
+
if (options.defaultScenario !== undefined && options.defaultScenario !== null) {
|
|
57
57
|
const t = String(options.defaultScenario).trim();
|
|
58
58
|
if (t !== '') {
|
|
59
59
|
// App config default — not a native launch arg; do not force runtime toggle on.
|
|
60
60
|
(0, mockifyer_core_1.setScenarioLaunchOverride)(t);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
return
|
|
63
|
+
return undefined;
|
|
64
64
|
}
|
|
65
65
|
// Lazy load bundled data (only used in production builds)
|
|
66
66
|
let bundledMockData = null;
|
|
@@ -138,7 +138,11 @@ async function setupMockifyerForReactNative(options) {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
// Apply scenario launch override early so we know if E2E forced a scenario.
|
|
141
|
-
const
|
|
141
|
+
const launchScenario = applyReactNativeScenarioOptions(options);
|
|
142
|
+
const launchScenarioApplied = launchScenario !== undefined;
|
|
143
|
+
// Launch `scenario` travels on every dashboard proxy request (body override wins over lane / global scenario),
|
|
144
|
+
// so E2E does not need a lane mapped in the dashboard. An explicit `proxyScenario` still wins.
|
|
145
|
+
const effectiveProxyScenario = proxyScenario ?? launchScenario;
|
|
142
146
|
if (launchScenarioApplied) {
|
|
143
147
|
// Launch `scenario` arg → start enabled (wins over persisted off for this session).
|
|
144
148
|
initialRuntimeEnabled = true;
|
|
@@ -164,8 +168,7 @@ async function setupMockifyerForReactNative(options) {
|
|
|
164
168
|
}
|
|
165
169
|
return 'React Native dev · hybrid (device + Metro)';
|
|
166
170
|
};
|
|
167
|
-
// Patch fetch for on / manual; launch_client
|
|
168
|
-
// Launch `scenario` forces runtime toggle on after activation — it does not replace client id.
|
|
171
|
+
// Patch fetch for on / manual; launch_client when a launch lane id or launch scenario is present.
|
|
169
172
|
const isEnabled = (0, mockifyer_core_2.shouldActivateMockifyerForReactNative)({
|
|
170
173
|
runtimeMode: resolvedRuntimeMode,
|
|
171
174
|
hasLaunchClientId: Boolean(clientIdFromLaunchArgs),
|
|
@@ -230,7 +233,7 @@ async function setupMockifyerForReactNative(options) {
|
|
|
230
233
|
proxy: strictProxyEnabled && proxyBaseUrl
|
|
231
234
|
? {
|
|
232
235
|
baseUrl: proxyBaseUrl,
|
|
233
|
-
scenario:
|
|
236
|
+
scenario: effectiveProxyScenario,
|
|
234
237
|
recordOnMiss: proxyShouldRecordOnMiss,
|
|
235
238
|
recordResponses: proxyShouldRecordResponses,
|
|
236
239
|
}
|
|
@@ -292,7 +295,7 @@ async function setupMockifyerForReactNative(options) {
|
|
|
292
295
|
proxy: proxyBaseUrl
|
|
293
296
|
? {
|
|
294
297
|
baseUrl: proxyBaseUrl,
|
|
295
|
-
scenario:
|
|
298
|
+
scenario: effectiveProxyScenario,
|
|
296
299
|
recordOnMiss: proxyShouldRecordOnMiss,
|
|
297
300
|
recordResponses: proxyShouldRecordResponses,
|
|
298
301
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgedda/mockifyer-fetch",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.100",
|
|
4
4
|
"description": "Mockifyer for Fetch - API mocking and logging utility for storing and replaying API responses",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@sgedda/mockifyer-core": "^1.10.
|
|
52
|
+
"@sgedda/mockifyer-core": "^1.10.181"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^20.11.24",
|
package/src/index.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
TestGenerationOptions,
|
|
37
37
|
checkRequestLimit,
|
|
38
38
|
prepareMockResponseBody,
|
|
39
|
-
|
|
39
|
+
createServeTimeClock,
|
|
40
40
|
createServeTimePoolResponseLoader,
|
|
41
41
|
collectPoolRefIds,
|
|
42
42
|
arePoolRefsEnabled,
|
|
@@ -309,7 +309,7 @@ class MockifyerClass {
|
|
|
309
309
|
private prepareStoredResponseBody(mockData: MockData, filename?: string, scenarioPath?: string): unknown {
|
|
310
310
|
const joinPath =
|
|
311
311
|
path && typeof path.join === 'function' ? path.join.bind(path) : null;
|
|
312
|
-
return prepareMockResponseBody(mockData,
|
|
312
|
+
return prepareMockResponseBody(mockData, createServeTimeClock(this.config), {
|
|
313
313
|
loadPoolResponse: createServeTimePoolResponseLoader({
|
|
314
314
|
mockDataPath: this.config.mockDataPath,
|
|
315
315
|
nodeFs: isUsableNodeLikePoolFs(fs) ? fs : null,
|
|
@@ -1198,7 +1198,7 @@ class MockifyerClass {
|
|
|
1198
1198
|
const clientResponse = buildClientResponseFromLiveCapture(
|
|
1199
1199
|
matchedMock.mockData,
|
|
1200
1200
|
capturedResponse,
|
|
1201
|
-
|
|
1201
|
+
createServeTimeClock(this.config),
|
|
1202
1202
|
{ filename: matchedMock.filename, scenarioPath: liveScenarioPath }
|
|
1203
1203
|
);
|
|
1204
1204
|
response.data = clientResponse.data;
|
package/src/react-native.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface MockifyerInstance extends HTTPClient {
|
|
|
44
44
|
/**
|
|
45
45
|
* Outcome of {@link setupMockifyerForReactNative}.
|
|
46
46
|
*
|
|
47
|
-
* - **`not_activated`** — `fetch` was not patched this run (see **`MOCKIFYER_MODE`** / `runtimeMode`: `off`, or `launch_client` without a launch-arg lane).
|
|
47
|
+
* - **`not_activated`** — `fetch` was not patched this run (see **`MOCKIFYER_MODE`** / `runtimeMode`: `off`, or `launch_client` without a launch-arg lane or scenario).
|
|
48
48
|
* Not the same as “permanently off” unless mode is **`off`** (then launch args do not activate).
|
|
49
49
|
* - **`active`** — Mockifyer initialized and patched `global.fetch`.
|
|
50
50
|
* - **`failed_no_bundled_mocks`** — Activation criteria were met and `isDev` was false, but bundled mock data was missing or empty.
|
|
@@ -95,7 +95,9 @@ export interface ReactNativeMockifyerConfig {
|
|
|
95
95
|
/**
|
|
96
96
|
* When true, reads `scenario` from `react-native-launch-arguments` (optional peer).
|
|
97
97
|
* Highest priority over MOCKIFYER_SCENARIO, config.scenarios, Metro scenario sync, and scenario-config.json.
|
|
98
|
-
* When a launch `scenario` is present, Mockifyer
|
|
98
|
+
* When a launch `scenario` is present, Mockifyer **activates** (also under `launch_client`, no lane needed),
|
|
99
|
+
* **starts enabled** (even with `runtimeMode: 'manual'`), and sends it as the dashboard proxy scenario
|
|
100
|
+
* (unless `proxyScenario` is set). `runtimeMode: 'off'` still wins.
|
|
99
101
|
* Set to `false` to ignore launch scenario args entirely.
|
|
100
102
|
* Default: auto-detect when a non-empty launch `scenario` is present.
|
|
101
103
|
*/
|
|
@@ -147,21 +149,20 @@ export interface ReactNativeMockifyerConfig {
|
|
|
147
149
|
|
|
148
150
|
/**
|
|
149
151
|
* Apply scenario from launch arguments and/or defaultScenario (highest priority in getCurrentScenario).
|
|
150
|
-
* @returns
|
|
152
|
+
* @returns The native launch-argument `scenario` when one was applied (activates Mockifyer, forces runtime toggle on,
|
|
153
|
+
* and is sent as the proxy scenario); otherwise `undefined`.
|
|
151
154
|
*/
|
|
152
|
-
function applyReactNativeScenarioOptions(options: ReactNativeMockifyerConfig):
|
|
153
|
-
let appliedFromLaunchArgs = false;
|
|
154
|
-
|
|
155
|
+
function applyReactNativeScenarioOptions(options: ReactNativeMockifyerConfig): string | undefined {
|
|
155
156
|
// Auto-detect launch `scenario` when present (E2E). Opt out with useLaunchArgumentsScenario: false.
|
|
156
157
|
if (options.useLaunchArgumentsScenario !== false) {
|
|
157
158
|
const scenarioFromLaunch = tryGetScenarioFromLaunchArguments();
|
|
158
159
|
if (scenarioFromLaunch) {
|
|
159
160
|
setScenarioLaunchOverride(scenarioFromLaunch, { fromLaunchArguments: true });
|
|
160
|
-
|
|
161
|
+
return scenarioFromLaunch;
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
if (
|
|
165
|
+
if (options.defaultScenario !== undefined && options.defaultScenario !== null) {
|
|
165
166
|
const t = String(options.defaultScenario).trim();
|
|
166
167
|
if (t !== '') {
|
|
167
168
|
// App config default — not a native launch arg; do not force runtime toggle on.
|
|
@@ -169,7 +170,7 @@ function applyReactNativeScenarioOptions(options: ReactNativeMockifyerConfig): b
|
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
return
|
|
173
|
+
return undefined;
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
// Lazy load bundled data (only used in production builds)
|
|
@@ -279,7 +280,11 @@ export async function setupMockifyerForReactNative(
|
|
|
279
280
|
}
|
|
280
281
|
|
|
281
282
|
// Apply scenario launch override early so we know if E2E forced a scenario.
|
|
282
|
-
const
|
|
283
|
+
const launchScenario = applyReactNativeScenarioOptions(options);
|
|
284
|
+
const launchScenarioApplied = launchScenario !== undefined;
|
|
285
|
+
// Launch `scenario` travels on every dashboard proxy request (body override wins over lane / global scenario),
|
|
286
|
+
// so E2E does not need a lane mapped in the dashboard. An explicit `proxyScenario` still wins.
|
|
287
|
+
const effectiveProxyScenario = proxyScenario ?? launchScenario;
|
|
283
288
|
if (launchScenarioApplied) {
|
|
284
289
|
// Launch `scenario` arg → start enabled (wins over persisted off for this session).
|
|
285
290
|
initialRuntimeEnabled = true;
|
|
@@ -309,8 +314,7 @@ export async function setupMockifyerForReactNative(
|
|
|
309
314
|
return 'React Native dev · hybrid (device + Metro)';
|
|
310
315
|
};
|
|
311
316
|
|
|
312
|
-
// Patch fetch for on / manual; launch_client
|
|
313
|
-
// Launch `scenario` forces runtime toggle on after activation — it does not replace client id.
|
|
317
|
+
// Patch fetch for on / manual; launch_client when a launch lane id or launch scenario is present.
|
|
314
318
|
const isEnabled = shouldActivateMockifyerForReactNative({
|
|
315
319
|
runtimeMode: resolvedRuntimeMode,
|
|
316
320
|
hasLaunchClientId: Boolean(clientIdFromLaunchArgs),
|
|
@@ -387,7 +391,7 @@ export async function setupMockifyerForReactNative(
|
|
|
387
391
|
strictProxyEnabled && proxyBaseUrl
|
|
388
392
|
? {
|
|
389
393
|
baseUrl: proxyBaseUrl,
|
|
390
|
-
scenario:
|
|
394
|
+
scenario: effectiveProxyScenario,
|
|
391
395
|
recordOnMiss: proxyShouldRecordOnMiss,
|
|
392
396
|
recordResponses: proxyShouldRecordResponses,
|
|
393
397
|
}
|
|
@@ -457,7 +461,7 @@ export async function setupMockifyerForReactNative(
|
|
|
457
461
|
proxy: proxyBaseUrl
|
|
458
462
|
? {
|
|
459
463
|
baseUrl: proxyBaseUrl,
|
|
460
|
-
scenario:
|
|
464
|
+
scenario: effectiveProxyScenario,
|
|
461
465
|
recordOnMiss: proxyShouldRecordOnMiss,
|
|
462
466
|
recordResponses: proxyShouldRecordResponses,
|
|
463
467
|
}
|