@sgedda/mockifyer-fetch 1.8.86 → 1.8.87
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/metro-sync-middleware.js +22 -22
- package/package.json +1 -1
- package/src/metro-sync-middleware.ts +26 -29
|
@@ -961,6 +961,8 @@ function createMockSyncMiddleware(options) {
|
|
|
961
961
|
const testConfig = getTestGenerationConfig(options);
|
|
962
962
|
// Log the resolved paths for debugging
|
|
963
963
|
mockifyer_core_1.logger.info(`[MetroSyncMiddleware] Initialized with projectRoot: ${projectRoot}, mockDataPath: ${mockDataPath}`);
|
|
964
|
+
/** Last scenario announced at info. Polls of an unchanged scenario stay quiet. */
|
|
965
|
+
let announcedScenario;
|
|
964
966
|
(0, metro_atlas_key_handlers_1.attachMetroAtlasKeyHandler)({
|
|
965
967
|
atlasKey: options?.atlasKey,
|
|
966
968
|
dashboardKey: options?.dashboardKey,
|
|
@@ -1603,41 +1605,39 @@ function createMockSyncMiddleware(options) {
|
|
|
1603
1605
|
}
|
|
1604
1606
|
// Handle GET endpoint for scenario config
|
|
1605
1607
|
if (url === "/mockifyer-scenario-config" && req.method === "GET") {
|
|
1608
|
+
const writeScenarioResponse = (scenario) => {
|
|
1609
|
+
if (announcedScenario !== scenario) {
|
|
1610
|
+
mockifyer_core_1.logger.info(`[MetroSyncMiddleware] Active scenario: ${scenario}`);
|
|
1611
|
+
announcedScenario = scenario;
|
|
1612
|
+
}
|
|
1613
|
+
res.setHeader("Content-Type", "application/json");
|
|
1614
|
+
res.end(JSON.stringify({
|
|
1615
|
+
success: true,
|
|
1616
|
+
currentScenario: scenario,
|
|
1617
|
+
}));
|
|
1618
|
+
};
|
|
1606
1619
|
try {
|
|
1607
1620
|
// Check environment variable first (highest priority)
|
|
1608
1621
|
if (process.env.MOCKIFYER_SCENARIO) {
|
|
1609
|
-
mockifyer_core_1.logger.
|
|
1610
|
-
|
|
1611
|
-
res.end(JSON.stringify({
|
|
1612
|
-
success: true,
|
|
1613
|
-
currentScenario: process.env.MOCKIFYER_SCENARIO,
|
|
1614
|
-
}));
|
|
1622
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Using scenario from MOCKIFYER_SCENARIO env var: ${process.env.MOCKIFYER_SCENARIO}`);
|
|
1623
|
+
writeScenarioResponse(process.env.MOCKIFYER_SCENARIO);
|
|
1615
1624
|
return;
|
|
1616
1625
|
}
|
|
1617
1626
|
const configPath = path.join(mockDataPath, "scenario-config.json");
|
|
1618
1627
|
const resolvedPath = path.resolve(configPath);
|
|
1619
|
-
mockifyer_core_1.logger.
|
|
1620
|
-
mockifyer_core_1.logger.
|
|
1628
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Reading scenario config from: ${resolvedPath}`);
|
|
1629
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] mockDataPath: ${mockDataPath}, projectRoot: ${projectRoot}`);
|
|
1621
1630
|
if (fs.existsSync(configPath)) {
|
|
1622
1631
|
const fileContent = fs.readFileSync(configPath, "utf-8");
|
|
1623
|
-
mockifyer_core_1.logger.
|
|
1632
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] File content: ${fileContent}`);
|
|
1624
1633
|
const config = JSON.parse(fileContent);
|
|
1625
1634
|
const scenario = config.currentScenario || DEFAULT_SCENARIO;
|
|
1626
|
-
mockifyer_core_1.logger.
|
|
1627
|
-
|
|
1628
|
-
// Return format expected by ExpoFileSystemProvider: { success: true, currentScenario: ... }
|
|
1629
|
-
res.end(JSON.stringify({
|
|
1630
|
-
success: true,
|
|
1631
|
-
currentScenario: scenario,
|
|
1632
|
-
}));
|
|
1635
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Found scenario in config: ${scenario} (from file: ${JSON.stringify(config)})`);
|
|
1636
|
+
writeScenarioResponse(scenario);
|
|
1633
1637
|
}
|
|
1634
1638
|
else {
|
|
1635
|
-
mockifyer_core_1.logger.
|
|
1636
|
-
|
|
1637
|
-
res.end(JSON.stringify({
|
|
1638
|
-
success: true,
|
|
1639
|
-
currentScenario: DEFAULT_SCENARIO,
|
|
1640
|
-
}));
|
|
1639
|
+
mockifyer_core_1.logger.debug(`[MetroSyncMiddleware] Config file not found at ${resolvedPath}, returning default scenario`);
|
|
1640
|
+
writeScenarioResponse(DEFAULT_SCENARIO);
|
|
1641
1641
|
}
|
|
1642
1642
|
}
|
|
1643
1643
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1274,6 +1274,9 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
|
|
|
1274
1274
|
`[MetroSyncMiddleware] Initialized with projectRoot: ${projectRoot}, mockDataPath: ${mockDataPath}`,
|
|
1275
1275
|
);
|
|
1276
1276
|
|
|
1277
|
+
/** Last scenario announced at info. Polls of an unchanged scenario stay quiet. */
|
|
1278
|
+
let announcedScenario: string | undefined;
|
|
1279
|
+
|
|
1277
1280
|
attachMetroAtlasKeyHandler({
|
|
1278
1281
|
atlasKey: options?.atlasKey,
|
|
1279
1282
|
dashboardKey: options?.dashboardKey,
|
|
@@ -2084,59 +2087,53 @@ export function createMockSyncMiddleware(options?: MetroSyncMiddlewareOptions) {
|
|
|
2084
2087
|
|
|
2085
2088
|
// Handle GET endpoint for scenario config
|
|
2086
2089
|
if (url === "/mockifyer-scenario-config" && req.method === "GET") {
|
|
2090
|
+
const writeScenarioResponse = (scenario: string): void => {
|
|
2091
|
+
if (announcedScenario !== scenario) {
|
|
2092
|
+
logger.info(`[MetroSyncMiddleware] Active scenario: ${scenario}`);
|
|
2093
|
+
announcedScenario = scenario;
|
|
2094
|
+
}
|
|
2095
|
+
res.setHeader("Content-Type", "application/json");
|
|
2096
|
+
res.end(
|
|
2097
|
+
JSON.stringify({
|
|
2098
|
+
success: true,
|
|
2099
|
+
currentScenario: scenario,
|
|
2100
|
+
}),
|
|
2101
|
+
);
|
|
2102
|
+
};
|
|
2103
|
+
|
|
2087
2104
|
try {
|
|
2088
2105
|
// Check environment variable first (highest priority)
|
|
2089
2106
|
if (process.env.MOCKIFYER_SCENARIO) {
|
|
2090
|
-
logger.
|
|
2107
|
+
logger.debug(
|
|
2091
2108
|
`[MetroSyncMiddleware] Using scenario from MOCKIFYER_SCENARIO env var: ${process.env.MOCKIFYER_SCENARIO}`,
|
|
2092
2109
|
);
|
|
2093
|
-
|
|
2094
|
-
res.end(
|
|
2095
|
-
JSON.stringify({
|
|
2096
|
-
success: true,
|
|
2097
|
-
currentScenario: process.env.MOCKIFYER_SCENARIO,
|
|
2098
|
-
}),
|
|
2099
|
-
);
|
|
2110
|
+
writeScenarioResponse(process.env.MOCKIFYER_SCENARIO);
|
|
2100
2111
|
return;
|
|
2101
2112
|
}
|
|
2102
2113
|
|
|
2103
2114
|
const configPath = path.join(mockDataPath, "scenario-config.json");
|
|
2104
2115
|
const resolvedPath = path.resolve(configPath);
|
|
2105
|
-
logger.
|
|
2116
|
+
logger.debug(
|
|
2106
2117
|
`[MetroSyncMiddleware] Reading scenario config from: ${resolvedPath}`,
|
|
2107
2118
|
);
|
|
2108
|
-
logger.
|
|
2119
|
+
logger.debug(
|
|
2109
2120
|
`[MetroSyncMiddleware] mockDataPath: ${mockDataPath}, projectRoot: ${projectRoot}`,
|
|
2110
2121
|
);
|
|
2111
2122
|
|
|
2112
2123
|
if (fs.existsSync(configPath)) {
|
|
2113
2124
|
const fileContent = fs.readFileSync(configPath, "utf-8");
|
|
2114
|
-
logger.
|
|
2125
|
+
logger.debug(`[MetroSyncMiddleware] File content: ${fileContent}`);
|
|
2115
2126
|
const config = JSON.parse(fileContent);
|
|
2116
2127
|
const scenario = config.currentScenario || DEFAULT_SCENARIO;
|
|
2117
|
-
logger.
|
|
2128
|
+
logger.debug(
|
|
2118
2129
|
`[MetroSyncMiddleware] Found scenario in config: ${scenario} (from file: ${JSON.stringify(config)})`,
|
|
2119
2130
|
);
|
|
2120
|
-
|
|
2121
|
-
res.setHeader("Content-Type", "application/json");
|
|
2122
|
-
// Return format expected by ExpoFileSystemProvider: { success: true, currentScenario: ... }
|
|
2123
|
-
res.end(
|
|
2124
|
-
JSON.stringify({
|
|
2125
|
-
success: true,
|
|
2126
|
-
currentScenario: scenario,
|
|
2127
|
-
}),
|
|
2128
|
-
);
|
|
2131
|
+
writeScenarioResponse(scenario);
|
|
2129
2132
|
} else {
|
|
2130
|
-
logger.
|
|
2133
|
+
logger.debug(
|
|
2131
2134
|
`[MetroSyncMiddleware] Config file not found at ${resolvedPath}, returning default scenario`,
|
|
2132
2135
|
);
|
|
2133
|
-
|
|
2134
|
-
res.end(
|
|
2135
|
-
JSON.stringify({
|
|
2136
|
-
success: true,
|
|
2137
|
-
currentScenario: DEFAULT_SCENARIO,
|
|
2138
|
-
}),
|
|
2139
|
-
);
|
|
2136
|
+
writeScenarioResponse(DEFAULT_SCENARIO);
|
|
2140
2137
|
}
|
|
2141
2138
|
} catch (error) {
|
|
2142
2139
|
logger.error(
|