@sgedda/mockifyer-fetch 1.8.97 → 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/metro-config.d.ts +6 -0
- package/dist/metro-config.js +29 -2
- package/dist/metro-sync-middleware.d.ts +10 -1
- package/dist/metro-sync-middleware.js +16 -49
- 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/metro-config.ts +42 -2
- package/src/metro-sync-middleware.ts +18 -71
- 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/metro-config.d.ts
CHANGED
|
@@ -53,12 +53,18 @@ export interface MetroConfig {
|
|
|
53
53
|
} | null | undefined;
|
|
54
54
|
extraNodeModules?: Record<string, string>;
|
|
55
55
|
nodeModulesPaths?: string[];
|
|
56
|
+
blockList?: RegExp | RegExp[];
|
|
56
57
|
};
|
|
57
58
|
watchFolders?: string[];
|
|
58
59
|
transformer?: any;
|
|
59
60
|
server?: any;
|
|
60
61
|
[key: string]: any;
|
|
61
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Regex for `<projectRoot>/<mockDataPath>/atlas-html/…`. Atlas renders and snapshots
|
|
65
|
+
* write there; without the block every write makes Metro send a fast-refresh update.
|
|
66
|
+
*/
|
|
67
|
+
export declare function atlasHtmlBlockListPattern(projectRoot: string, mockDataPath: string): RegExp;
|
|
62
68
|
/**
|
|
63
69
|
* Options for configuring Metro for Mockifyer
|
|
64
70
|
*/
|
package/dist/metro-config.js
CHANGED
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.atlasHtmlBlockListPattern = atlasHtmlBlockListPattern;
|
|
49
50
|
exports.configureMetroForMockifyer = configureMetroForMockifyer;
|
|
50
51
|
const mockifyer_core_1 = require("@sgedda/mockifyer-core");
|
|
51
52
|
/**
|
|
@@ -96,6 +97,27 @@ function resolveMockifyerCoreReactNativeEntry(moduleName, platform) {
|
|
|
96
97
|
return null;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
const ATLAS_HTML_DIR_NAME = 'atlas-html';
|
|
101
|
+
const DEFAULT_MOCK_DATA_PATH = 'mock-data';
|
|
102
|
+
function escapeRegExp(value) {
|
|
103
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Regex for `<projectRoot>/<mockDataPath>/atlas-html/…`. Atlas renders and snapshots
|
|
107
|
+
* write there; without the block every write makes Metro send a fast-refresh update.
|
|
108
|
+
*/
|
|
109
|
+
function atlasHtmlBlockListPattern(projectRoot, mockDataPath) {
|
|
110
|
+
const path = require('path');
|
|
111
|
+
const dir = path.resolve(projectRoot, mockDataPath, ATLAS_HTML_DIR_NAME);
|
|
112
|
+
const separators = '[\\\\/]';
|
|
113
|
+
const body = dir.split(/[\\/]+/).map(escapeRegExp).join(separators);
|
|
114
|
+
return new RegExp(`^${body}${separators}.*$`);
|
|
115
|
+
}
|
|
116
|
+
function appendBlockList(existing, pattern) {
|
|
117
|
+
if (!existing)
|
|
118
|
+
return [pattern];
|
|
119
|
+
return [...(Array.isArray(existing) ? existing : [existing]), pattern];
|
|
120
|
+
}
|
|
99
121
|
/**
|
|
100
122
|
* Configure Metro bundler for Mockifyer
|
|
101
123
|
*
|
|
@@ -212,7 +234,7 @@ function configureMetroForMockifyer(config, options) {
|
|
|
212
234
|
const { createMockSyncMiddleware } = require('./metro-sync-middleware');
|
|
213
235
|
const syncMiddleware = createMockSyncMiddleware({
|
|
214
236
|
projectRoot: options.syncMiddleware.projectRoot || process.cwd(),
|
|
215
|
-
mockDataPath: options.syncMiddleware.mockDataPath ||
|
|
237
|
+
mockDataPath: options.syncMiddleware.mockDataPath || DEFAULT_MOCK_DATA_PATH,
|
|
216
238
|
testGeneration: options.syncMiddleware.testGeneration,
|
|
217
239
|
atlasKey: options.syncMiddleware.atlasKey,
|
|
218
240
|
dashboardKey: options.syncMiddleware.dashboardKey,
|
|
@@ -253,7 +275,7 @@ function configureMetroForMockifyer(config, options) {
|
|
|
253
275
|
const { startAutoSync } = require('./metro-sync-middleware');
|
|
254
276
|
const intervalMs = options.autoSync.intervalMs || 5000;
|
|
255
277
|
const projectRoot = options.autoSync.projectRoot || process.cwd();
|
|
256
|
-
const mockDataPath = options.autoSync.mockDataPath ||
|
|
278
|
+
const mockDataPath = options.autoSync.mockDataPath || DEFAULT_MOCK_DATA_PATH;
|
|
257
279
|
startAutoSync(intervalMs, {
|
|
258
280
|
projectRoot,
|
|
259
281
|
mockDataPath,
|
|
@@ -264,11 +286,16 @@ function configureMetroForMockifyer(config, options) {
|
|
|
264
286
|
mockifyer_core_1.logger.warn('[Metro] Could not set up Mockifyer auto-sync:', e);
|
|
265
287
|
}
|
|
266
288
|
}
|
|
289
|
+
const syncOptions = options?.syncMiddleware;
|
|
290
|
+
const blockList = syncOptions
|
|
291
|
+
? appendBlockList(existingResolver.blockList, atlasHtmlBlockListPattern(syncOptions.projectRoot || process.cwd(), syncOptions.mockDataPath || DEFAULT_MOCK_DATA_PATH))
|
|
292
|
+
: existingResolver.blockList;
|
|
267
293
|
// Merge config with new resolver
|
|
268
294
|
return {
|
|
269
295
|
...config,
|
|
270
296
|
resolver: {
|
|
271
297
|
...existingResolver,
|
|
298
|
+
...(blockList ? { blockList } : {}),
|
|
272
299
|
resolveRequest: newResolveRequest,
|
|
273
300
|
},
|
|
274
301
|
};
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 8. GET /atlas-html[/…] (legacy: /mockifyer-atlas-html[/…]) — serve atlas-html static files (index.html, pages, incidents, screenshots)
|
|
13
13
|
* 9. POST /mockifyer-atlas-screenshot — write screen image (png/jpg/webp) under mock-data/atlas-html/screenshots/
|
|
14
14
|
* 10. POST /mockifyer-atlas-render — write full interactive Atlas HTML under mock-data/atlas-html/
|
|
15
|
-
* 11. POST /mockifyer-atlas-body-spill —
|
|
15
|
+
* 11. POST /mockifyer-atlas-body-spill — hold full hop body text in Metro memory (written to mock-data/atlas-html/bodies/ on Render)
|
|
16
16
|
* 12. POST/GET /mockifyer-network-events — live hop ring buffer for `mockifyer-atlas` CLI
|
|
17
17
|
* 13. GET /mockifyer-network-events/stream — SSE hop stream
|
|
18
18
|
* 14. GET /mockifyer-network-events/analyze — hop summary JSON
|
|
@@ -82,6 +82,15 @@ declare function syncFromIOSSimulator(projectRoot: string, mockDataPath: string)
|
|
|
82
82
|
syncedFiles?: string[];
|
|
83
83
|
error?: string;
|
|
84
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Hold a full hop body from the device (RN) in Metro memory.
|
|
87
|
+
* Written under atlas-html/bodies/ only when Atlas HTML is rendered.
|
|
88
|
+
*/
|
|
89
|
+
export declare function bufferAtlasBodySpill(relativePath: string, text: string): {
|
|
90
|
+
success: boolean;
|
|
91
|
+
relativePath?: string;
|
|
92
|
+
error?: string;
|
|
93
|
+
};
|
|
85
94
|
/**
|
|
86
95
|
* Metro middleware function
|
|
87
96
|
*/
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* 8. GET /atlas-html[/…] (legacy: /mockifyer-atlas-html[/…]) — serve atlas-html static files (index.html, pages, incidents, screenshots)
|
|
14
14
|
* 9. POST /mockifyer-atlas-screenshot — write screen image (png/jpg/webp) under mock-data/atlas-html/screenshots/
|
|
15
15
|
* 10. POST /mockifyer-atlas-render — write full interactive Atlas HTML under mock-data/atlas-html/
|
|
16
|
-
* 11. POST /mockifyer-atlas-body-spill —
|
|
16
|
+
* 11. POST /mockifyer-atlas-body-spill — hold full hop body text in Metro memory (written to mock-data/atlas-html/bodies/ on Render)
|
|
17
17
|
* 12. POST/GET /mockifyer-network-events — live hop ring buffer for `mockifyer-atlas` CLI
|
|
18
18
|
* 13. GET /mockifyer-network-events/stream — SSE hop stream
|
|
19
19
|
* 14. GET /mockifyer-network-events/analyze — hop summary JSON
|
|
@@ -66,6 +66,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
66
66
|
};
|
|
67
67
|
})();
|
|
68
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
+
exports.bufferAtlasBodySpill = bufferAtlasBodySpill;
|
|
69
70
|
exports.createMockSyncMiddleware = createMockSyncMiddleware;
|
|
70
71
|
exports.startAutoSync = startAutoSync;
|
|
71
72
|
exports.stopAutoSync = stopAutoSync;
|
|
@@ -145,8 +146,7 @@ async function enrichMetroBufferFromDashboard(options) {
|
|
|
145
146
|
});
|
|
146
147
|
let added = 0;
|
|
147
148
|
for (const child of children) {
|
|
148
|
-
|
|
149
|
-
appendNetworkEventNdjson(options.mockDataPath, stored);
|
|
149
|
+
buffer.append(child);
|
|
150
150
|
added += 1;
|
|
151
151
|
}
|
|
152
152
|
return added;
|
|
@@ -948,9 +948,8 @@ function candidateBodyRelPaths(event, side) {
|
|
|
948
948
|
}
|
|
949
949
|
const BODY_SPILL_REL_PATTERN = /^bodies\/[A-Za-z0-9._-]+-(req|res)\.(json|txt)$/;
|
|
950
950
|
/**
|
|
951
|
-
* Locate a full body
|
|
952
|
-
*
|
|
953
|
-
* (that blocked Metro for seconds on every req/res/trace click).
|
|
951
|
+
* Locate a full body in the Metro spill buffer or on disk (after a Render).
|
|
952
|
+
* Never writes: files under the project tree trigger Metro fast refresh.
|
|
954
953
|
*/
|
|
955
954
|
function findExistingBodyFile(options) {
|
|
956
955
|
const outDir = path.join(options.mockDataPath, "atlas-html");
|
|
@@ -970,15 +969,7 @@ function findExistingBodyFile(options) {
|
|
|
970
969
|
}
|
|
971
970
|
const fromBuffer = snapshot[rel];
|
|
972
971
|
if (typeof fromBuffer === "string" && fromBuffer.length > 0) {
|
|
973
|
-
|
|
974
|
-
if (saved.success && saved.filePath) {
|
|
975
|
-
return { abs: saved.filePath, rel, text: fromBuffer };
|
|
976
|
-
}
|
|
977
|
-
return {
|
|
978
|
-
abs,
|
|
979
|
-
rel,
|
|
980
|
-
text: fromBuffer,
|
|
981
|
-
};
|
|
972
|
+
return { abs, rel, text: fromBuffer };
|
|
982
973
|
}
|
|
983
974
|
if (fs.existsSync(abs)) {
|
|
984
975
|
return { abs, rel };
|
|
@@ -1052,11 +1043,12 @@ function formatCapturedTraceLines(events, root) {
|
|
|
1052
1043
|
return lines;
|
|
1053
1044
|
}
|
|
1054
1045
|
/**
|
|
1055
|
-
*
|
|
1046
|
+
* Hold a full hop body from the device (RN) in Metro memory.
|
|
1047
|
+
* Written under atlas-html/bodies/ only when Atlas HTML is rendered.
|
|
1056
1048
|
*/
|
|
1057
|
-
function
|
|
1049
|
+
function bufferAtlasBodySpill(relativePath, text) {
|
|
1058
1050
|
const rel = relativePath.trim().replace(/^\/+/, "").replace(/\\/g, "/");
|
|
1059
|
-
if (!rel || typeof text !== "string") {
|
|
1051
|
+
if (!rel || typeof text !== "string" || !text) {
|
|
1060
1052
|
return { success: false, error: "relativePath and text are required" };
|
|
1061
1053
|
}
|
|
1062
1054
|
if (rel.includes("..") || !BODY_SPILL_REL_PATTERN.test(rel)) {
|
|
@@ -1065,21 +1057,11 @@ function saveAtlasBodySpill(projectRoot, mockDataPath, relativePath, text) {
|
|
|
1065
1057
|
error: "relativePath must be bodies/<id>-req.json or bodies/<id>-res.json",
|
|
1066
1058
|
};
|
|
1067
1059
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
const body = rel.endsWith(".json") ? (0, mockifyer_core_2.prettyPrintJsonText)(text) : text;
|
|
1072
|
-
fs.writeFileSync(filePath, body, "utf8");
|
|
1073
|
-
const relativeFromRoot = path.relative(projectRoot, filePath);
|
|
1074
|
-
return {
|
|
1075
|
-
success: true,
|
|
1076
|
-
filePath,
|
|
1077
|
-
relativePath: relativeFromRoot.split(path.sep).join("/"),
|
|
1078
|
-
};
|
|
1079
|
-
}
|
|
1080
|
-
catch (error) {
|
|
1081
|
-
return { success: false, error: error.message };
|
|
1060
|
+
const buffered = (0, mockifyer_core_2.bufferNetworkBodySpill)(rel, text);
|
|
1061
|
+
if (!buffered) {
|
|
1062
|
+
return { success: false, error: "body could not be buffered" };
|
|
1082
1063
|
}
|
|
1064
|
+
return { success: true, relativePath: buffered };
|
|
1083
1065
|
}
|
|
1084
1066
|
const ATLAS_HTML_CONTENT_TYPES = {
|
|
1085
1067
|
".html": "text/html; charset=utf-8",
|
|
@@ -1163,17 +1145,6 @@ function serveAtlasHtmlStatic(mockDataPath, relativeUrlPath, res) {
|
|
|
1163
1145
|
res.end(fs.readFileSync(filePath));
|
|
1164
1146
|
return true;
|
|
1165
1147
|
}
|
|
1166
|
-
const NETWORK_STREAM_NDJSON_REL = path.join("atlas-html", "atlas.ndjson");
|
|
1167
|
-
function appendNetworkEventNdjson(mockDataPath, event) {
|
|
1168
|
-
try {
|
|
1169
|
-
const filePath = path.join(mockDataPath, NETWORK_STREAM_NDJSON_REL);
|
|
1170
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
1171
|
-
fs.appendFileSync(filePath, `${JSON.stringify(event)}\n`, "utf8");
|
|
1172
|
-
}
|
|
1173
|
-
catch {
|
|
1174
|
-
// disk append is best-effort
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
1148
|
function writeNetworkEventsSnapshot(mockDataPath, events) {
|
|
1178
1149
|
const dir = path.join(mockDataPath, "atlas-html");
|
|
1179
1150
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -1441,11 +1412,7 @@ function createMockSyncMiddleware(options) {
|
|
|
1441
1412
|
return;
|
|
1442
1413
|
}
|
|
1443
1414
|
const buffer = (0, mockifyer_core_2.getMetroNetworkEventBuffer)();
|
|
1444
|
-
const saved = incoming.map((e) =>
|
|
1445
|
-
const stored = buffer.append(e);
|
|
1446
|
-
appendNetworkEventNdjson(mockDataPath, stored);
|
|
1447
|
-
return stored;
|
|
1448
|
-
});
|
|
1415
|
+
const saved = incoming.map((e) => buffer.append(e));
|
|
1449
1416
|
const dashboardBaseUrl = resolveAtlasEnrichmentDashboardUrl(options?.dashboardUrl, parsed.dashboardBaseUrl);
|
|
1450
1417
|
if (dashboardBaseUrl) {
|
|
1451
1418
|
scheduleDashboardTraceEnrichment({ dashboardBaseUrl, mockDataPath });
|
|
@@ -1875,7 +1842,7 @@ function createMockSyncMiddleware(options) {
|
|
|
1875
1842
|
const parsed = JSON.parse(body);
|
|
1876
1843
|
const relativePath = typeof parsed.relativePath === "string" ? parsed.relativePath : "";
|
|
1877
1844
|
const text = typeof parsed.text === "string" ? parsed.text : "";
|
|
1878
|
-
const result =
|
|
1845
|
+
const result = bufferAtlasBodySpill(relativePath, text);
|
|
1879
1846
|
res.setHeader("Content-Type", "application/json");
|
|
1880
1847
|
res.statusCode = result.success ? 201 : 400;
|
|
1881
1848
|
res.end(JSON.stringify(result));
|
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/metro-config.ts
CHANGED
|
@@ -58,6 +58,7 @@ export interface MetroConfig {
|
|
|
58
58
|
) => { filePath: string; type: string } | null | undefined;
|
|
59
59
|
extraNodeModules?: Record<string, string>;
|
|
60
60
|
nodeModulesPaths?: string[];
|
|
61
|
+
blockList?: RegExp | RegExp[];
|
|
61
62
|
};
|
|
62
63
|
watchFolders?: string[];
|
|
63
64
|
transformer?: any;
|
|
@@ -121,6 +122,33 @@ function resolveMockifyerCoreReactNativeEntry(
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
const ATLAS_HTML_DIR_NAME = 'atlas-html';
|
|
126
|
+
const DEFAULT_MOCK_DATA_PATH = 'mock-data';
|
|
127
|
+
|
|
128
|
+
function escapeRegExp(value: string): string {
|
|
129
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Regex for `<projectRoot>/<mockDataPath>/atlas-html/…`. Atlas renders and snapshots
|
|
134
|
+
* write there; without the block every write makes Metro send a fast-refresh update.
|
|
135
|
+
*/
|
|
136
|
+
export function atlasHtmlBlockListPattern(projectRoot: string, mockDataPath: string): RegExp {
|
|
137
|
+
const path = require('path') as typeof import('path');
|
|
138
|
+
const dir = path.resolve(projectRoot, mockDataPath, ATLAS_HTML_DIR_NAME);
|
|
139
|
+
const separators = '[\\\\/]';
|
|
140
|
+
const body = dir.split(/[\\/]+/).map(escapeRegExp).join(separators);
|
|
141
|
+
return new RegExp(`^${body}${separators}.*$`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function appendBlockList(
|
|
145
|
+
existing: RegExp | RegExp[] | undefined,
|
|
146
|
+
pattern: RegExp
|
|
147
|
+
): RegExp[] {
|
|
148
|
+
if (!existing) return [pattern];
|
|
149
|
+
return [...(Array.isArray(existing) ? existing : [existing]), pattern];
|
|
150
|
+
}
|
|
151
|
+
|
|
124
152
|
/**
|
|
125
153
|
* Options for configuring Metro for Mockifyer
|
|
126
154
|
*/
|
|
@@ -268,7 +296,7 @@ export function configureMetroForMockifyer(
|
|
|
268
296
|
const { createMockSyncMiddleware } = require('./metro-sync-middleware');
|
|
269
297
|
const syncMiddleware = createMockSyncMiddleware({
|
|
270
298
|
projectRoot: options.syncMiddleware.projectRoot || process.cwd(),
|
|
271
|
-
mockDataPath: options.syncMiddleware.mockDataPath ||
|
|
299
|
+
mockDataPath: options.syncMiddleware.mockDataPath || DEFAULT_MOCK_DATA_PATH,
|
|
272
300
|
testGeneration: options.syncMiddleware.testGeneration,
|
|
273
301
|
atlasKey: options.syncMiddleware.atlasKey,
|
|
274
302
|
dashboardKey: options.syncMiddleware.dashboardKey,
|
|
@@ -311,7 +339,7 @@ export function configureMetroForMockifyer(
|
|
|
311
339
|
const { startAutoSync } = require('./metro-sync-middleware');
|
|
312
340
|
const intervalMs = options.autoSync.intervalMs || 5000;
|
|
313
341
|
const projectRoot = options.autoSync.projectRoot || process.cwd();
|
|
314
|
-
const mockDataPath = options.autoSync.mockDataPath ||
|
|
342
|
+
const mockDataPath = options.autoSync.mockDataPath || DEFAULT_MOCK_DATA_PATH;
|
|
315
343
|
|
|
316
344
|
startAutoSync(intervalMs, {
|
|
317
345
|
projectRoot,
|
|
@@ -323,11 +351,23 @@ export function configureMetroForMockifyer(
|
|
|
323
351
|
}
|
|
324
352
|
}
|
|
325
353
|
|
|
354
|
+
const syncOptions = options?.syncMiddleware;
|
|
355
|
+
const blockList = syncOptions
|
|
356
|
+
? appendBlockList(
|
|
357
|
+
existingResolver.blockList,
|
|
358
|
+
atlasHtmlBlockListPattern(
|
|
359
|
+
syncOptions.projectRoot || process.cwd(),
|
|
360
|
+
syncOptions.mockDataPath || DEFAULT_MOCK_DATA_PATH
|
|
361
|
+
)
|
|
362
|
+
)
|
|
363
|
+
: existingResolver.blockList;
|
|
364
|
+
|
|
326
365
|
// Merge config with new resolver
|
|
327
366
|
return {
|
|
328
367
|
...config,
|
|
329
368
|
resolver: {
|
|
330
369
|
...existingResolver,
|
|
370
|
+
...(blockList ? { blockList } : {}),
|
|
331
371
|
resolveRequest: newResolveRequest,
|
|
332
372
|
},
|
|
333
373
|
};
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 8. GET /atlas-html[/…] (legacy: /mockifyer-atlas-html[/…]) — serve atlas-html static files (index.html, pages, incidents, screenshots)
|
|
13
13
|
* 9. POST /mockifyer-atlas-screenshot — write screen image (png/jpg/webp) under mock-data/atlas-html/screenshots/
|
|
14
14
|
* 10. POST /mockifyer-atlas-render — write full interactive Atlas HTML under mock-data/atlas-html/
|
|
15
|
-
* 11. POST /mockifyer-atlas-body-spill —
|
|
15
|
+
* 11. POST /mockifyer-atlas-body-spill — hold full hop body text in Metro memory (written to mock-data/atlas-html/bodies/ on Render)
|
|
16
16
|
* 12. POST/GET /mockifyer-network-events — live hop ring buffer for `mockifyer-atlas` CLI
|
|
17
17
|
* 13. GET /mockifyer-network-events/stream — SSE hop stream
|
|
18
18
|
* 14. GET /mockifyer-network-events/analyze — hop summary JSON
|
|
@@ -55,10 +55,10 @@ import {
|
|
|
55
55
|
flushAtlasDocHtmlRewrite,
|
|
56
56
|
setAtlasDocHtmlOutputPath,
|
|
57
57
|
writeAtlasDocHtml,
|
|
58
|
-
|
|
58
|
+
bufferNetworkBodySpill,
|
|
59
59
|
flushNetworkBodySpillsToDir,
|
|
60
|
+
writeNetworkBodySpillMap,
|
|
60
61
|
getNetworkBodySpillSnapshot,
|
|
61
|
-
prettyPrintJsonText,
|
|
62
62
|
setAtlasDocMap,
|
|
63
63
|
type AtlasDocMap,
|
|
64
64
|
type NetworkEvent,
|
|
@@ -226,8 +226,7 @@ async function enrichMetroBufferFromDashboard(options: {
|
|
|
226
226
|
|
|
227
227
|
let added = 0;
|
|
228
228
|
for (const child of children) {
|
|
229
|
-
|
|
230
|
-
appendNetworkEventNdjson(options.mockDataPath, stored);
|
|
229
|
+
buffer.append(child);
|
|
231
230
|
added += 1;
|
|
232
231
|
}
|
|
233
232
|
return added;
|
|
@@ -1259,9 +1258,8 @@ const BODY_SPILL_REL_PATTERN =
|
|
|
1259
1258
|
/^bodies\/[A-Za-z0-9._-]+-(req|res)\.(json|txt)$/;
|
|
1260
1259
|
|
|
1261
1260
|
/**
|
|
1262
|
-
* Locate a full body
|
|
1263
|
-
*
|
|
1264
|
-
* (that blocked Metro for seconds on every req/res/trace click).
|
|
1261
|
+
* Locate a full body in the Metro spill buffer or on disk (after a Render).
|
|
1262
|
+
* Never writes: files under the project tree trigger Metro fast refresh.
|
|
1265
1263
|
*/
|
|
1266
1264
|
function findExistingBodyFile(options: {
|
|
1267
1265
|
projectRoot: string;
|
|
@@ -1288,20 +1286,7 @@ function findExistingBodyFile(options: {
|
|
|
1288
1286
|
|
|
1289
1287
|
const fromBuffer = snapshot[rel];
|
|
1290
1288
|
if (typeof fromBuffer === "string" && fromBuffer.length > 0) {
|
|
1291
|
-
|
|
1292
|
-
options.projectRoot,
|
|
1293
|
-
options.mockDataPath,
|
|
1294
|
-
rel,
|
|
1295
|
-
fromBuffer,
|
|
1296
|
-
);
|
|
1297
|
-
if (saved.success && saved.filePath) {
|
|
1298
|
-
return { abs: saved.filePath, rel, text: fromBuffer };
|
|
1299
|
-
}
|
|
1300
|
-
return {
|
|
1301
|
-
abs,
|
|
1302
|
-
rel,
|
|
1303
|
-
text: fromBuffer,
|
|
1304
|
-
};
|
|
1289
|
+
return { abs, rel, text: fromBuffer };
|
|
1305
1290
|
}
|
|
1306
1291
|
if (fs.existsSync(abs)) {
|
|
1307
1292
|
return { abs, rel };
|
|
@@ -1383,21 +1368,19 @@ function formatCapturedTraceLines(
|
|
|
1383
1368
|
}
|
|
1384
1369
|
|
|
1385
1370
|
/**
|
|
1386
|
-
*
|
|
1371
|
+
* Hold a full hop body from the device (RN) in Metro memory.
|
|
1372
|
+
* Written under atlas-html/bodies/ only when Atlas HTML is rendered.
|
|
1387
1373
|
*/
|
|
1388
|
-
function
|
|
1389
|
-
projectRoot: string,
|
|
1390
|
-
mockDataPath: string,
|
|
1374
|
+
export function bufferAtlasBodySpill(
|
|
1391
1375
|
relativePath: string,
|
|
1392
1376
|
text: string,
|
|
1393
1377
|
): {
|
|
1394
1378
|
success: boolean;
|
|
1395
|
-
filePath?: string;
|
|
1396
1379
|
relativePath?: string;
|
|
1397
1380
|
error?: string;
|
|
1398
1381
|
} {
|
|
1399
1382
|
const rel = relativePath.trim().replace(/^\/+/, "").replace(/\\/g, "/");
|
|
1400
|
-
if (!rel || typeof text !== "string") {
|
|
1383
|
+
if (!rel || typeof text !== "string" || !text) {
|
|
1401
1384
|
return { success: false, error: "relativePath and text are required" };
|
|
1402
1385
|
}
|
|
1403
1386
|
if (rel.includes("..") || !BODY_SPILL_REL_PATTERN.test(rel)) {
|
|
@@ -1407,20 +1390,11 @@ function saveAtlasBodySpill(
|
|
|
1407
1390
|
"relativePath must be bodies/<id>-req.json or bodies/<id>-res.json",
|
|
1408
1391
|
};
|
|
1409
1392
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
const body = rel.endsWith(".json") ? prettyPrintJsonText(text) : text;
|
|
1414
|
-
fs.writeFileSync(filePath, body, "utf8");
|
|
1415
|
-
const relativeFromRoot = path.relative(projectRoot, filePath);
|
|
1416
|
-
return {
|
|
1417
|
-
success: true,
|
|
1418
|
-
filePath,
|
|
1419
|
-
relativePath: relativeFromRoot.split(path.sep).join("/"),
|
|
1420
|
-
};
|
|
1421
|
-
} catch (error) {
|
|
1422
|
-
return { success: false, error: (error as Error).message };
|
|
1393
|
+
const buffered = bufferNetworkBodySpill(rel, text);
|
|
1394
|
+
if (!buffered) {
|
|
1395
|
+
return { success: false, error: "body could not be buffered" };
|
|
1423
1396
|
}
|
|
1397
|
+
return { success: true, relativePath: buffered };
|
|
1424
1398
|
}
|
|
1425
1399
|
|
|
1426
1400
|
const ATLAS_HTML_CONTENT_TYPES: Record<string, string> = {
|
|
@@ -1522,21 +1496,6 @@ function serveAtlasHtmlStatic(
|
|
|
1522
1496
|
return true;
|
|
1523
1497
|
}
|
|
1524
1498
|
|
|
1525
|
-
const NETWORK_STREAM_NDJSON_REL = path.join("atlas-html", "atlas.ndjson");
|
|
1526
|
-
|
|
1527
|
-
function appendNetworkEventNdjson(
|
|
1528
|
-
mockDataPath: string,
|
|
1529
|
-
event: NetworkEvent,
|
|
1530
|
-
): void {
|
|
1531
|
-
try {
|
|
1532
|
-
const filePath = path.join(mockDataPath, NETWORK_STREAM_NDJSON_REL);
|
|
1533
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
1534
|
-
fs.appendFileSync(filePath, `${JSON.stringify(event)}\n`, "utf8");
|
|
1535
|
-
} catch {
|
|
1536
|
-
// disk append is best-effort
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
1499
|
function writeNetworkEventsSnapshot(
|
|
1541
1500
|
mockDataPath: string,
|
|
1542
1501
|
events: NetworkEvent[],
|
|
@@ -1881,11 +1840,7 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
|
|
|
1881
1840
|
return;
|
|
1882
1841
|
}
|
|
1883
1842
|
const buffer = getMetroNetworkEventBuffer();
|
|
1884
|
-
const saved = incoming.map((e) =>
|
|
1885
|
-
const stored = buffer.append(e);
|
|
1886
|
-
appendNetworkEventNdjson(mockDataPath, stored);
|
|
1887
|
-
return stored;
|
|
1888
|
-
});
|
|
1843
|
+
const saved = incoming.map((e) => buffer.append(e));
|
|
1889
1844
|
const dashboardBaseUrl = resolveAtlasEnrichmentDashboardUrl(
|
|
1890
1845
|
options?.dashboardUrl,
|
|
1891
1846
|
parsed.dashboardBaseUrl,
|
|
@@ -2430,12 +2385,7 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
|
|
|
2430
2385
|
const relativePath =
|
|
2431
2386
|
typeof parsed.relativePath === "string" ? parsed.relativePath : "";
|
|
2432
2387
|
const text = typeof parsed.text === "string" ? parsed.text : "";
|
|
2433
|
-
const result =
|
|
2434
|
-
projectRoot,
|
|
2435
|
-
mockDataPath,
|
|
2436
|
-
relativePath,
|
|
2437
|
-
text,
|
|
2438
|
-
);
|
|
2388
|
+
const result = bufferAtlasBodySpill(relativePath, text);
|
|
2439
2389
|
res.setHeader("Content-Type", "application/json");
|
|
2440
2390
|
res.statusCode = result.success ? 201 : 400;
|
|
2441
2391
|
res.end(JSON.stringify(result));
|
|
@@ -2497,10 +2447,7 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
|
|
|
2497
2447
|
}
|
|
2498
2448
|
setAtlasDocMap(doc);
|
|
2499
2449
|
setAtlasDocHtmlOutputPath(outDir);
|
|
2500
|
-
const spillWritten = writeNetworkBodySpillMap(
|
|
2501
|
-
outDir,
|
|
2502
|
-
parsed.bodySpills,
|
|
2503
|
-
);
|
|
2450
|
+
const spillWritten = writeNetworkBodySpillMap(outDir, parsed.bodySpills);
|
|
2504
2451
|
const events = Array.isArray(parsed.events) ? parsed.events : [];
|
|
2505
2452
|
const written = writeAtlasDocHtml(outDir, doc, events);
|
|
2506
2453
|
const relativeFromRoot = path
|
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
|
}
|