ftmocks-utils 1.2.5 → 1.3.0
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/package.json +1 -1
- package/src/index.js +23 -4
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -15,7 +15,11 @@ const {
|
|
|
15
15
|
} = require("./common-utils");
|
|
16
16
|
|
|
17
17
|
const getDefaultMockDataFromConfig = (testConfig) => {
|
|
18
|
-
const defaultPath = path.join(
|
|
18
|
+
const defaultPath = path.join(
|
|
19
|
+
getMockDir(testConfig),
|
|
20
|
+
"defaultMocks",
|
|
21
|
+
"_mock_list.json"
|
|
22
|
+
);
|
|
19
23
|
|
|
20
24
|
try {
|
|
21
25
|
const defaultData = fs.readFileSync(defaultPath, "utf8");
|
|
@@ -38,7 +42,7 @@ const getDefaultMockDataFromConfig = (testConfig) => {
|
|
|
38
42
|
});
|
|
39
43
|
return parsedData;
|
|
40
44
|
} catch (error) {
|
|
41
|
-
console.error(`Error reading or parsing default
|
|
45
|
+
console.error(`Error reading or parsing default mocks:`, error);
|
|
42
46
|
return [];
|
|
43
47
|
}
|
|
44
48
|
};
|
|
@@ -272,11 +276,18 @@ function getMatchingMockData({
|
|
|
272
276
|
}
|
|
273
277
|
// updating stats to mock file
|
|
274
278
|
if (foundMock) {
|
|
275
|
-
|
|
279
|
+
let mockFilePath = path.join(
|
|
276
280
|
getMockDir(testConfig),
|
|
277
281
|
`test_${nameToFolder(testName)}`,
|
|
278
282
|
`mock_${foundMock.id}.json`
|
|
279
283
|
);
|
|
284
|
+
if (!fs.existsSync(mockFilePath)) {
|
|
285
|
+
mockFilePath = path.join(
|
|
286
|
+
getMockDir(testConfig),
|
|
287
|
+
"defaultMocks",
|
|
288
|
+
`mock_${foundMock.id}.json`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
280
291
|
foundMock.fileContent.served = true;
|
|
281
292
|
fs.writeFileSync(
|
|
282
293
|
mockFilePath,
|
|
@@ -351,12 +362,20 @@ async function initiatePlaywrightRoutes(
|
|
|
351
362
|
};
|
|
352
363
|
|
|
353
364
|
if (file) {
|
|
354
|
-
|
|
365
|
+
let filePath = path.join(
|
|
355
366
|
getMockDir(ftmocksConifg),
|
|
356
367
|
`test_${nameToFolder(testName)}`,
|
|
357
368
|
"_files",
|
|
358
369
|
file
|
|
359
370
|
);
|
|
371
|
+
if (!fs.existsSync(filePath)) {
|
|
372
|
+
filePath = path.join(
|
|
373
|
+
getMockDir(ftmocksConifg),
|
|
374
|
+
"defaultMocks",
|
|
375
|
+
"_files",
|
|
376
|
+
file
|
|
377
|
+
);
|
|
378
|
+
}
|
|
360
379
|
if (fs.existsSync(filePath) && fs.lstatSync(filePath).isFile()) {
|
|
361
380
|
const fileContent = fs.readFileSync(filePath);
|
|
362
381
|
json.body = fileContent;
|