ftmocks-utils 1.0.9 → 1.1.1
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 +22 -20
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -110,7 +110,7 @@ const isSameRequest = (req1, req2) => {
|
|
|
110
110
|
let matched = true;
|
|
111
111
|
if(req1.url !== req2.url) {
|
|
112
112
|
matched = false;
|
|
113
|
-
} else if(req1.method !== req2.method) {
|
|
113
|
+
} else if(req1.method?.toLowerCase() !== req2.method?.toLowerCase()) {
|
|
114
114
|
matched = false;
|
|
115
115
|
} else if((!req1.postData && req2.postData) || (req1.postData && !req2.postData)) {
|
|
116
116
|
matched = areJsonEqual(req1.postData || {} , req2.postData || {});
|
|
@@ -216,26 +216,16 @@ async function initiatePlaywrightRoutes (page, ftmocksConifg, testName) {
|
|
|
216
216
|
let mockData = getMatchingMockData({testMockData, defaultMockData, url, options, testConfig: ftmocksConifg, testName});
|
|
217
217
|
if (mockData) {
|
|
218
218
|
console.debug('mocked', url, options);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const { content, headers, status } = mockData.response;
|
|
229
|
-
|
|
230
|
-
const json = {
|
|
231
|
-
status,
|
|
232
|
-
headers,
|
|
233
|
-
json: () => Promise.resolve(JSON.parse(content)),
|
|
234
|
-
};
|
|
219
|
+
const { content, headers, status } = mockData.response;
|
|
220
|
+
const json = {
|
|
221
|
+
status,
|
|
222
|
+
headers: new Map(Object.entries(headers)),
|
|
223
|
+
body: content,
|
|
224
|
+
};
|
|
235
225
|
|
|
236
|
-
if(json) {
|
|
237
226
|
await route.fulfill(json);
|
|
238
227
|
} else {
|
|
228
|
+
console.debug('missing mock data', url, options);
|
|
239
229
|
await route.fallback();
|
|
240
230
|
}
|
|
241
231
|
});
|
|
@@ -264,7 +254,7 @@ async function initiateJestFetch (jest, ftmocksConifg, testName) {
|
|
|
264
254
|
|
|
265
255
|
return Promise.resolve({
|
|
266
256
|
status,
|
|
267
|
-
headers,
|
|
257
|
+
headers: new Map(Object.entries(headers)),
|
|
268
258
|
json: () => Promise.resolve(JSON.parse(content)),
|
|
269
259
|
});
|
|
270
260
|
});
|
|
@@ -429,6 +419,17 @@ const deleteAllLogs = async (ftmocksConifg, testName) => {
|
|
|
429
419
|
fs.rmSync(logFilePath, { recursive: true, force: true });
|
|
430
420
|
};
|
|
431
421
|
|
|
422
|
+
function initiateJestEventSnaps(jest, ftmocksConifg, testName) {
|
|
423
|
+
const mouseEvents = ftmocksConifg.snapEvents || ['click', 'change', 'url', 'dblclick', 'contextmenu'];
|
|
424
|
+
mouseEvents.forEach(event => {
|
|
425
|
+
jest.spyOn(document, 'addEventListener').mockImplementation((e, callback) => {
|
|
426
|
+
if (mouseEvents.includes(e)) {
|
|
427
|
+
saveSnap(document.outerHTML, ftmocksConifg, testName);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
432
433
|
|
|
433
434
|
|
|
434
435
|
// Export functions as a module
|
|
@@ -447,5 +448,6 @@ module.exports = {
|
|
|
447
448
|
deleteAllSnaps,
|
|
448
449
|
deleteAllLogs,
|
|
449
450
|
initiateConsoleLogs,
|
|
450
|
-
initiatePlaywrightRoutes
|
|
451
|
+
initiatePlaywrightRoutes,
|
|
452
|
+
initiateJestEventSnaps
|
|
451
453
|
};
|