ftmocks-utils 1.1.0 → 1.1.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +18 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ftmocks-utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Util functions for FtMocks",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
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 || {});
@@ -198,12 +198,12 @@ async function resetAllMockStats({testMockData, testConfig, testName}) {
198
198
  }
199
199
  }
200
200
 
201
- async function initiatePlaywrightRoutes (page, ftmocksConifg, testName) {
201
+ async function initiatePlaywrightRoutes (page, ftmocksConifg, testName, path = '**/*') {
202
202
  const testMockData = testName ? loadMockDataFromConfig(ftmocksConifg, testName) : [];
203
203
  resetAllMockStats({testMockData, testConfig: ftmocksConifg, testName});
204
204
  const defaultMockData = getDefaultMockDataFromConfig(ftmocksConifg);
205
205
  console.debug('calling initiatePlaywrightRoutes fetch');
206
- await page.route('**/*', async (route, request) => {
206
+ await page.route(path, async (route, request) => {
207
207
  const url = request.url();
208
208
  const options = {
209
209
  options: {
@@ -219,7 +219,7 @@ async function initiatePlaywrightRoutes (page, ftmocksConifg, testName) {
219
219
  const { content, headers, status } = mockData.response;
220
220
  const json = {
221
221
  status,
222
- headers,
222
+ headers: new Map(Object.entries(headers)),
223
223
  body: content,
224
224
  };
225
225
 
@@ -254,7 +254,7 @@ async function initiateJestFetch (jest, ftmocksConifg, testName) {
254
254
 
255
255
  return Promise.resolve({
256
256
  status,
257
- headers,
257
+ headers: new Map(Object.entries(headers)),
258
258
  json: () => Promise.resolve(JSON.parse(content)),
259
259
  });
260
260
  });
@@ -419,6 +419,17 @@ const deleteAllLogs = async (ftmocksConifg, testName) => {
419
419
  fs.rmSync(logFilePath, { recursive: true, force: true });
420
420
  };
421
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
+
422
433
 
423
434
 
424
435
  // Export functions as a module
@@ -437,5 +448,6 @@ module.exports = {
437
448
  deleteAllSnaps,
438
449
  deleteAllLogs,
439
450
  initiateConsoleLogs,
440
- initiatePlaywrightRoutes
451
+ initiatePlaywrightRoutes,
452
+ initiateJestEventSnaps
441
453
  };