@gravity-ui/playwright-tools 0.4.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.
Files changed (199) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/actions/addExtraHttpHeader.d.ts +5 -0
  4. package/actions/addExtraHttpHeader.js +15 -0
  5. package/actions/addExtraHttpHeaders.d.ts +5 -0
  6. package/actions/addExtraHttpHeaders.js +17 -0
  7. package/actions/assertElementsHidden.d.ts +13 -0
  8. package/actions/assertElementsHidden.js +33 -0
  9. package/actions/clearExtraHttpHeaders.d.ts +5 -0
  10. package/actions/clearExtraHttpHeaders.js +15 -0
  11. package/actions/collectPageActivity/collectPageActivity.d.ts +11 -0
  12. package/actions/collectPageActivity/collectPageActivity.js +74 -0
  13. package/actions/collectPageActivity/constants.d.ts +2 -0
  14. package/actions/collectPageActivity/constants.js +17 -0
  15. package/actions/collectPageActivity/index.d.ts +2 -0
  16. package/actions/collectPageActivity/index.js +5 -0
  17. package/actions/collectPageActivity/isSameMessage.d.ts +2 -0
  18. package/actions/collectPageActivity/isSameMessage.js +10 -0
  19. package/actions/collectPageActivity/isSameResponse.d.ts +2 -0
  20. package/actions/collectPageActivity/isSameResponse.js +17 -0
  21. package/actions/collectPageActivity/normalizePathname.d.ts +1 -0
  22. package/actions/collectPageActivity/normalizePathname.js +8 -0
  23. package/actions/collectPageActivity/types.d.ts +23 -0
  24. package/actions/collectPageActivity/types.js +2 -0
  25. package/actions/disableAnimation.d.ts +8 -0
  26. package/actions/disableAnimation.js +35 -0
  27. package/actions/expect-request/expect-request.d.ts +3 -0
  28. package/actions/expect-request/expect-request.js +62 -0
  29. package/actions/expect-request/index.d.ts +2 -0
  30. package/actions/expect-request/index.js +5 -0
  31. package/actions/expect-request/matchers/compare/DiffLogger.d.ts +9 -0
  32. package/actions/expect-request/matchers/compare/DiffLogger.js +20 -0
  33. package/actions/expect-request/matchers/compare/DiffPrinter.d.ts +16 -0
  34. package/actions/expect-request/matchers/compare/DiffPrinter.js +80 -0
  35. package/actions/expect-request/matchers/compare/compare.d.ts +6 -0
  36. package/actions/expect-request/matchers/compare/compare.js +129 -0
  37. package/actions/expect-request/matchers/compare/constants.d.ts +20 -0
  38. package/actions/expect-request/matchers/compare/constants.js +23 -0
  39. package/actions/expect-request/matchers/compare/index.d.ts +4 -0
  40. package/actions/expect-request/matchers/compare/index.js +23 -0
  41. package/actions/expect-request/matchers/compare/print-json-diff.d.ts +6 -0
  42. package/actions/expect-request/matchers/compare/print-json-diff.js +366 -0
  43. package/actions/expect-request/matchers/compare/types.d.ts +59 -0
  44. package/actions/expect-request/matchers/compare/types.js +2 -0
  45. package/actions/expect-request/matchers/compare/utils.d.ts +5 -0
  46. package/actions/expect-request/matchers/compare/utils.js +19 -0
  47. package/actions/expect-request/matchers/match-body.d.ts +4 -0
  48. package/actions/expect-request/matchers/match-body.js +12 -0
  49. package/actions/expect-request/matchers/match-method.d.ts +2 -0
  50. package/actions/expect-request/matchers/match-method.js +14 -0
  51. package/actions/expect-request/matchers/match-query.d.ts +3 -0
  52. package/actions/expect-request/matchers/match-query.js +34 -0
  53. package/actions/expect-request/matchers/match-url.d.ts +1 -0
  54. package/actions/expect-request/matchers/match-url.js +13 -0
  55. package/actions/expect-request/matchers/match.d.ts +3 -0
  56. package/actions/expect-request/matchers/match.js +10 -0
  57. package/actions/expect-request/matchers/types.d.ts +3 -0
  58. package/actions/expect-request/matchers/types.js +2 -0
  59. package/actions/expect-request/matchers/utils.d.ts +1 -0
  60. package/actions/expect-request/matchers/utils.js +9 -0
  61. package/actions/expect-request/poll-with-timeout.d.ts +22 -0
  62. package/actions/expect-request/poll-with-timeout.js +39 -0
  63. package/actions/expect-request/types.d.ts +18 -0
  64. package/actions/expect-request/types.js +2 -0
  65. package/actions/getExtraHttpHeader.d.ts +5 -0
  66. package/actions/getExtraHttpHeader.js +14 -0
  67. package/actions/getExtraHttpHeaders.d.ts +7 -0
  68. package/actions/getExtraHttpHeaders.js +14 -0
  69. package/actions/getGlobalSettings.d.ts +5 -0
  70. package/actions/getGlobalSettings.js +10 -0
  71. package/actions/getTestSlug.d.ts +5 -0
  72. package/actions/getTestSlug.js +13 -0
  73. package/actions/hasExtraHttpHeader.d.ts +5 -0
  74. package/actions/hasExtraHttpHeader.js +14 -0
  75. package/actions/index.d.ts +18 -0
  76. package/actions/index.js +39 -0
  77. package/actions/matchScreenshot.d.ts +90 -0
  78. package/actions/matchScreenshot.js +104 -0
  79. package/actions/mockDate.d.ts +10 -0
  80. package/actions/mockDate.js +20 -0
  81. package/actions/removeExtraHttpHeader.d.ts +5 -0
  82. package/actions/removeExtraHttpHeader.js +15 -0
  83. package/actions/setCacheSettings.d.ts +7 -0
  84. package/actions/setCacheSettings.js +12 -0
  85. package/actions/setGlobalSettings.d.ts +12 -0
  86. package/actions/setGlobalSettings.js +19 -0
  87. package/actions/setTestSlug.d.ts +9 -0
  88. package/actions/setTestSlug.js +22 -0
  89. package/actions/waitForNetworkSettled.d.ts +7 -0
  90. package/actions/waitForNetworkSettled.js +48 -0
  91. package/auth/storage/applyStorageState.d.ts +10 -0
  92. package/auth/storage/applyStorageState.js +16 -0
  93. package/auth/storage/applyStorageStateFor.d.ts +9 -0
  94. package/auth/storage/applyStorageStateFor.js +19 -0
  95. package/auth/storage/deleteStorageStateFor.d.ts +6 -0
  96. package/auth/storage/deleteStorageStateFor.js +12 -0
  97. package/auth/storage/getStorageState.d.ts +27 -0
  98. package/auth/storage/getStorageState.js +18 -0
  99. package/auth/storage/getStorageStateFor.d.ts +24 -0
  100. package/auth/storage/getStorageStateFor.js +12 -0
  101. package/auth/storage/hasStorageStateFor.d.ts +6 -0
  102. package/auth/storage/hasStorageStateFor.js +12 -0
  103. package/auth/storage/index.d.ts +9 -0
  104. package/auth/storage/index.js +21 -0
  105. package/auth/storage/restoreCookies.d.ts +10 -0
  106. package/auth/storage/restoreCookies.js +16 -0
  107. package/auth/storage/restoreLocalStorage.d.ts +10 -0
  108. package/auth/storage/restoreLocalStorage.js +26 -0
  109. package/auth/storage/saveStorageStateFor.d.ts +8 -0
  110. package/auth/storage/saveStorageStateFor.js +15 -0
  111. package/config/browsers.d.ts +24 -0
  112. package/config/browsers.js +7 -0
  113. package/config/browsersDesktop.d.ts +14 -0
  114. package/config/browsersDesktop.js +28 -0
  115. package/config/browsersMobile.d.ts +14 -0
  116. package/config/browsersMobile.js +21 -0
  117. package/data/cacheSettings.d.ts +19 -0
  118. package/data/cacheSettings.js +21 -0
  119. package/data/extraHttpHeaders.d.ts +5 -0
  120. package/data/extraHttpHeaders.js +7 -0
  121. package/data/globalSettings.d.ts +100 -0
  122. package/data/globalSettings.js +112 -0
  123. package/data/storageStates.d.ts +36 -0
  124. package/data/storageStates.js +50 -0
  125. package/data/testSlugs.d.ts +5 -0
  126. package/data/testSlugs.js +7 -0
  127. package/fixtures/expect-request/expect-request-fixture.d.ts +8 -0
  128. package/fixtures/expect-request/expect-request-fixture.js +26 -0
  129. package/fixtures/expect-request/index.d.ts +3 -0
  130. package/fixtures/expect-request/index.js +5 -0
  131. package/fixtures/expect-request/types.d.ts +5 -0
  132. package/fixtures/expect-request/types.js +2 -0
  133. package/fixtures/expect-screenshot/expect-screenshot-fixture.d.ts +5 -0
  134. package/fixtures/expect-screenshot/expect-screenshot-fixture.js +28 -0
  135. package/fixtures/expect-screenshot/index.d.ts +2 -0
  136. package/fixtures/expect-screenshot/index.js +5 -0
  137. package/fixtures/expect-screenshot/types.d.ts +14 -0
  138. package/fixtures/expect-screenshot/types.js +2 -0
  139. package/fixtures/global-settings/global-settings-fixture.d.ts +3 -0
  140. package/fixtures/global-settings/global-settings-fixture.js +22 -0
  141. package/fixtures/global-settings/index.d.ts +2 -0
  142. package/fixtures/global-settings/index.js +5 -0
  143. package/fixtures/global-settings/types.d.ts +15 -0
  144. package/fixtures/global-settings/types.js +2 -0
  145. package/fixtures/index.d.ts +10 -0
  146. package/fixtures/index.js +13 -0
  147. package/fixtures/mock-network/har-patcher.d.ts +8 -0
  148. package/fixtures/mock-network/har-patcher.js +40 -0
  149. package/fixtures/mock-network/index.d.ts +2 -0
  150. package/fixtures/mock-network/index.js +5 -0
  151. package/fixtures/mock-network/mock-network-fixture.d.ts +6 -0
  152. package/fixtures/mock-network/mock-network-fixture.js +38 -0
  153. package/fixtures/mock-network/types.d.ts +86 -0
  154. package/fixtures/mock-network/types.js +2 -0
  155. package/fixtures/testSlug.d.ts +12 -0
  156. package/fixtures/testSlug.js +19 -0
  157. package/fixtures/types.d.ts +4 -0
  158. package/fixtures/types.js +2 -0
  159. package/har/addHarLookupTransform.d.ts +9 -0
  160. package/har/addHarLookupTransform.js +44 -0
  161. package/har/addHarOpenTransform.d.ts +6 -0
  162. package/har/addHarOpenTransform.js +41 -0
  163. package/har/addHarRecorderTransform.d.ts +6 -0
  164. package/har/addHarRecorderTransform.js +36 -0
  165. package/har/clearHeaders.d.ts +11 -0
  166. package/har/clearHeaders.js +25 -0
  167. package/har/getPlaywrightCoreModule.d.ts +4 -0
  168. package/har/getPlaywrightCoreModule.js +33 -0
  169. package/har/index.d.ts +11 -0
  170. package/har/index.js +17 -0
  171. package/har/initDumps.d.ts +66 -0
  172. package/har/initDumps.js +54 -0
  173. package/har/replaceBaseUrlInEntry.d.ts +9 -0
  174. package/har/replaceBaseUrlInEntry.js +29 -0
  175. package/har/setExtraHash.d.ts +5 -0
  176. package/har/setExtraHash.js +18 -0
  177. package/har/types.d.ts +175 -0
  178. package/har/types.js +3 -0
  179. package/package.json +74 -0
  180. package/utils/NeverError.d.ts +6 -0
  181. package/utils/NeverError.js +12 -0
  182. package/utils/deleteCache.d.ts +7 -0
  183. package/utils/deleteCache.js +15 -0
  184. package/utils/extractTestSlug.d.ts +12 -0
  185. package/utils/extractTestSlug.js +24 -0
  186. package/utils/fetchWithoutRejectUnauthorized.d.ts +4 -0
  187. package/utils/fetchWithoutRejectUnauthorized.js +28 -0
  188. package/utils/getCookieDomain.d.ts +4 -0
  189. package/utils/getCookieDomain.js +13 -0
  190. package/utils/index.d.ts +9 -0
  191. package/utils/index.js +21 -0
  192. package/utils/readCache.d.ts +8 -0
  193. package/utils/readCache.js +32 -0
  194. package/utils/waitForResolve.d.ts +24 -0
  195. package/utils/waitForResolve.js +40 -0
  196. package/utils/waitHttpService.d.ts +28 -0
  197. package/utils/waitHttpService.js +25 -0
  198. package/utils/writeCache.d.ts +8 -0
  199. package/utils/writeCache.js +18 -0
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compare = compare;
4
+ const utils_1 = require("../utils");
5
+ const DiffLogger_1 = require("./DiffLogger");
6
+ const constants_1 = require("./constants");
7
+ function compare(params) {
8
+ const { left, right, exactArrays } = params;
9
+ const logger = new DiffLogger_1.DiffLogger();
10
+ compareInner({
11
+ left,
12
+ right,
13
+ exactArrays,
14
+ logger: logger,
15
+ });
16
+ compareInner({
17
+ left: right,
18
+ right: left,
19
+ forwardComparison: false,
20
+ exactArrays,
21
+ logger: logger,
22
+ });
23
+ return logger.diffLog;
24
+ }
25
+ function compareInner(params) {
26
+ const { left, right, exactArrays, logger, forwardComparison = true } = params;
27
+ const innerLogger = logger ? logger : new DiffLogger_1.DiffLogger();
28
+ if (left === right) {
29
+ return innerLogger;
30
+ }
31
+ if (left === null) {
32
+ innerLogger.addDiffItem({
33
+ type: constants_1.DiffType.ValueMismatch,
34
+ side: forwardComparison ? 'left' : 'right',
35
+ expected: right,
36
+ received: left,
37
+ });
38
+ return innerLogger;
39
+ }
40
+ if (Array.isArray(left) && Array.isArray(right)) {
41
+ if (exactArrays) {
42
+ if (left.length === right.length) {
43
+ for (let i = 0; i < left.length; ++i) {
44
+ const leftItem = left[i] ?? null;
45
+ const rightItem = right[i] ?? null;
46
+ innerLogger.addContext({ arrayIndex: i });
47
+ compareInner({
48
+ left: leftItem,
49
+ right: rightItem,
50
+ forwardComparison: forwardComparison,
51
+ exactArrays,
52
+ logger: innerLogger,
53
+ });
54
+ innerLogger.removeContext();
55
+ }
56
+ }
57
+ else {
58
+ innerLogger.addDiffItem({
59
+ type: constants_1.DiffType.ValueMismatch,
60
+ side: forwardComparison ? 'left' : 'right',
61
+ expected: right,
62
+ received: left,
63
+ });
64
+ }
65
+ }
66
+ else {
67
+ const rightCopy = [...right];
68
+ for (const leftItem of left) {
69
+ const index = rightCopy.findIndex((rightItem) => {
70
+ const logger = compareInner({
71
+ left: leftItem,
72
+ right: rightItem,
73
+ exactArrays,
74
+ forwardComparison,
75
+ });
76
+ return logger.diffLog.length === 0;
77
+ });
78
+ if (index >= 0) {
79
+ rightCopy.splice(index, 1);
80
+ }
81
+ if (rightCopy.length === 0) {
82
+ break;
83
+ }
84
+ }
85
+ for (const item of rightCopy) {
86
+ innerLogger.addDiffItem({
87
+ type: constants_1.DiffType.ArrayMissingValue,
88
+ side: forwardComparison ? 'left' : 'right',
89
+ expected: item,
90
+ });
91
+ }
92
+ }
93
+ }
94
+ else if ((0, utils_1.isObject)(left) && (0, utils_1.isObject)(right)) {
95
+ for (const [rightKey, rightValue] of Object.entries(right)) {
96
+ innerLogger.addContext({ objectField: rightKey });
97
+ if (!Object.hasOwn(left, rightKey)) {
98
+ innerLogger.removeContext();
99
+ innerLogger.addDiffItem({
100
+ type: constants_1.DiffType.ObjectMissingProperty,
101
+ side: forwardComparison ? 'left' : 'right',
102
+ expected: {
103
+ key: rightKey,
104
+ value: rightValue,
105
+ },
106
+ });
107
+ continue;
108
+ }
109
+ const leftValue = left[rightKey] ?? null;
110
+ compareInner({
111
+ left: leftValue,
112
+ right: rightValue,
113
+ forwardComparison,
114
+ exactArrays,
115
+ logger: innerLogger,
116
+ });
117
+ innerLogger.removeContext();
118
+ }
119
+ }
120
+ else if (left !== right) {
121
+ innerLogger.addDiffItem({
122
+ type: constants_1.DiffType.ValueMismatch,
123
+ side: forwardComparison ? 'left' : 'right',
124
+ expected: right,
125
+ received: left,
126
+ });
127
+ }
128
+ return innerLogger;
129
+ }
@@ -0,0 +1,20 @@
1
+ export declare const DiffType: {
2
+ readonly ValueMismatch: "value-mismatch";
3
+ readonly ObjectMissingProperty: "object-missing-property";
4
+ readonly ArrayMissingValue: "array-missing-value";
5
+ };
6
+ export declare const DecoratedLineType: {
7
+ readonly ObjectOpen: "object-open";
8
+ readonly ObjectClose: "object-close";
9
+ readonly ArrayOpen: "array-open";
10
+ readonly ArrayClose: "array-close";
11
+ readonly PrimitiveValue: "primitive-value";
12
+ readonly EmptyObject: "empty-object";
13
+ readonly EmptyArray: "empty-array";
14
+ };
15
+ export declare const PathAnnotationType: {
16
+ readonly ValueMismatch: "value-mismatch";
17
+ readonly ObjectMissingProperty: "object-missing-property";
18
+ readonly ObjectExtraProperty: "object-extra-property";
19
+ readonly ArrayMissingValue: "array-missing-value";
20
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PathAnnotationType = exports.DecoratedLineType = exports.DiffType = void 0;
4
+ exports.DiffType = {
5
+ ValueMismatch: 'value-mismatch',
6
+ ObjectMissingProperty: 'object-missing-property',
7
+ ArrayMissingValue: 'array-missing-value',
8
+ };
9
+ exports.DecoratedLineType = {
10
+ ObjectOpen: 'object-open',
11
+ ObjectClose: 'object-close',
12
+ ArrayOpen: 'array-open',
13
+ ArrayClose: 'array-close',
14
+ PrimitiveValue: 'primitive-value',
15
+ EmptyObject: 'empty-object',
16
+ EmptyArray: 'empty-array',
17
+ };
18
+ exports.PathAnnotationType = {
19
+ ValueMismatch: 'value-mismatch',
20
+ ObjectMissingProperty: 'object-missing-property',
21
+ ObjectExtraProperty: 'object-extra-property',
22
+ ArrayMissingValue: 'array-missing-value',
23
+ };
@@ -0,0 +1,4 @@
1
+ export { compare } from './compare';
2
+ export * from './types';
3
+ export * from './utils';
4
+ export { printJsonDiff } from './print-json-diff';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.printJsonDiff = exports.compare = void 0;
18
+ var compare_1 = require("./compare");
19
+ Object.defineProperty(exports, "compare", { enumerable: true, get: function () { return compare_1.compare; } });
20
+ __exportStar(require("./types"), exports);
21
+ __exportStar(require("./utils"), exports);
22
+ var print_json_diff_1 = require("./print-json-diff");
23
+ Object.defineProperty(exports, "printJsonDiff", { enumerable: true, get: function () { return print_json_diff_1.printJsonDiff; } });
@@ -0,0 +1,6 @@
1
+ import type { Json } from '../../types';
2
+ import type { PathAnnotation } from './types';
3
+ export declare function printJsonDiff(params: {
4
+ json: Json;
5
+ pathAnnotations?: Record<string, PathAnnotation[]>;
6
+ }): string;
@@ -0,0 +1,366 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printJsonDiff = printJsonDiff;
4
+ const utils_1 = require("../utils");
5
+ const constants_1 = require("./constants");
6
+ const utils_2 = require("./utils");
7
+ function printJsonDiff(params) {
8
+ const { json, pathAnnotations } = params;
9
+ const lines = makeJsonDecoratedLines({ json, pathAnnotations, level: 0, path: '' });
10
+ const formattedLines = lines.map(formatDecoratedLine);
11
+ return formattedLines.join('\n');
12
+ }
13
+ function formatDecoratedLine(line) {
14
+ const { type, level, fieldName, diffMarker } = line;
15
+ let content;
16
+ switch (type) {
17
+ case constants_1.DecoratedLineType.PrimitiveValue:
18
+ content = `${fieldName ? formatPrimitive(fieldName) + ': ' : ''}${formatPrimitive(line.value)}${level === 0 ? '' : ','}`;
19
+ break;
20
+ case constants_1.DecoratedLineType.ObjectOpen:
21
+ content = `${fieldName ? formatPrimitive(fieldName) + ': ' : ''}{`;
22
+ break;
23
+ case constants_1.DecoratedLineType.ArrayOpen:
24
+ content = `${fieldName ? formatPrimitive(fieldName) + ': ' : ''}[`;
25
+ break;
26
+ case constants_1.DecoratedLineType.ObjectClose:
27
+ content = `}${level === 0 ? '' : ','}`;
28
+ break;
29
+ case constants_1.DecoratedLineType.ArrayClose:
30
+ content = `]${level === 0 ? '' : ','}`;
31
+ break;
32
+ case constants_1.DecoratedLineType.EmptyObject:
33
+ content = `${fieldName ? formatPrimitive(fieldName) + ': ' : ''}{}${level === 0 ? '' : ','}`;
34
+ break;
35
+ case constants_1.DecoratedLineType.EmptyArray:
36
+ content = `${fieldName ? formatPrimitive(fieldName) + ': ' : ''}[]${level === 0 ? '' : ','}`;
37
+ break;
38
+ }
39
+ let prefix = '';
40
+ if (diffMarker) {
41
+ prefix = diffMarker === 'expected' ? '-' : '+';
42
+ }
43
+ return `${prefix ? prefix + ' ' : ' '}${Array.from({ length: level })
44
+ .map(() => ' ')
45
+ .join('')}${content}`;
46
+ }
47
+ function formatPrimitive(jsonPrimitive) {
48
+ if (typeof jsonPrimitive === 'string') {
49
+ return `"${jsonPrimitive}"`;
50
+ }
51
+ return `${jsonPrimitive}`;
52
+ }
53
+ function makeJsonDecoratedLines(params) {
54
+ const { json, path, level, pathAnnotations, decoratedLines: paramsDecoratedLines, contentOnly, diffMarker, fieldName, } = params;
55
+ const decoratedLines = paramsDecoratedLines ? paramsDecoratedLines : [];
56
+ if (Array.isArray(json)) {
57
+ makeArrayDecoratedLines({
58
+ json,
59
+ path,
60
+ level,
61
+ pathAnnotations,
62
+ decoratedLines,
63
+ contentOnly,
64
+ diffMarker,
65
+ fieldName,
66
+ });
67
+ }
68
+ else if ((0, utils_1.isObject)(json)) {
69
+ makeObjectDecoratedLines({
70
+ json,
71
+ path,
72
+ level,
73
+ pathAnnotations,
74
+ decoratedLines,
75
+ contentOnly,
76
+ diffMarker,
77
+ fieldName,
78
+ });
79
+ }
80
+ else {
81
+ const currentPathAnnotations = pathAnnotations?.[path] || [];
82
+ const valueMismatchAnnotations = currentPathAnnotations.filter(utils_2.isValueMismatchAnnotation);
83
+ if (valueMismatchAnnotations.length) {
84
+ for (const { expected, received } of valueMismatchAnnotations) {
85
+ if (expected !== undefined) {
86
+ makeJsonDecoratedLines({
87
+ json: expected,
88
+ path,
89
+ level,
90
+ decoratedLines,
91
+ diffMarker: 'expected',
92
+ fieldName,
93
+ });
94
+ }
95
+ if (received !== undefined) {
96
+ makeJsonDecoratedLines({
97
+ json: received,
98
+ path,
99
+ level,
100
+ decoratedLines,
101
+ diffMarker: 'received',
102
+ fieldName,
103
+ });
104
+ }
105
+ }
106
+ }
107
+ else {
108
+ decoratedLines.push({
109
+ type: constants_1.DecoratedLineType.PrimitiveValue,
110
+ level,
111
+ value: json,
112
+ diffMarker,
113
+ fieldName,
114
+ });
115
+ }
116
+ }
117
+ return decoratedLines;
118
+ }
119
+ function makeObjectDecoratedLines(params) {
120
+ const { json, path, decoratedLines, pathAnnotations, contentOnly, diffMarker, level, fieldName, } = params;
121
+ let innerLevel = level;
122
+ const objectEntries = Object.entries(json);
123
+ const objectAnnotations = pathAnnotations?.[path] || [];
124
+ const missingValueAnnotations = objectAnnotations.filter(utils_2.isObjectMissingPropertyAnnotation);
125
+ const valueMismatchAnnotation = objectAnnotations.find(utils_2.isValueMismatchAnnotation);
126
+ if (valueMismatchAnnotation) {
127
+ const { expected, received } = valueMismatchAnnotation;
128
+ if (expected !== undefined) {
129
+ makeJsonDecoratedLines({
130
+ decoratedLines,
131
+ json: expected,
132
+ path,
133
+ level,
134
+ diffMarker: 'expected',
135
+ });
136
+ }
137
+ if (received !== undefined) {
138
+ makeJsonDecoratedLines({
139
+ decoratedLines,
140
+ json: received,
141
+ path,
142
+ level,
143
+ diffMarker: 'received',
144
+ });
145
+ }
146
+ return;
147
+ }
148
+ if (!missingValueAnnotations.length && !objectEntries.length) {
149
+ decoratedLines.push({ type: constants_1.DecoratedLineType.EmptyObject, level, diffMarker, fieldName });
150
+ return;
151
+ }
152
+ if (!contentOnly) {
153
+ decoratedLines.push({
154
+ type: constants_1.DecoratedLineType.ObjectOpen,
155
+ level: innerLevel,
156
+ diffMarker,
157
+ fieldName,
158
+ });
159
+ innerLevel++;
160
+ }
161
+ for (const { expected } of missingValueAnnotations) {
162
+ makeJsonDecoratedLines({
163
+ json: { [expected.key]: expected.value },
164
+ path,
165
+ level: innerLevel,
166
+ decoratedLines,
167
+ contentOnly: true,
168
+ diffMarker: 'expected',
169
+ });
170
+ }
171
+ for (const [key, value] of objectEntries) {
172
+ const currentPath = `${path ? path + '.' : ''}${key}`;
173
+ const currentPathAnnotations = pathAnnotations?.[currentPath] || [];
174
+ const extraPropertyAnnotation = currentPathAnnotations.find(utils_2.isObjectExtraPropertyAnnotation);
175
+ if (extraPropertyAnnotation) {
176
+ makeJsonDecoratedLines({
177
+ json: value,
178
+ path,
179
+ level: innerLevel,
180
+ decoratedLines,
181
+ diffMarker: 'received',
182
+ fieldName: key,
183
+ });
184
+ continue;
185
+ }
186
+ const valueMismatchAnnotation = currentPathAnnotations.find(utils_2.isValueMismatchAnnotation);
187
+ if (valueMismatchAnnotation) {
188
+ const { expected, received } = valueMismatchAnnotation;
189
+ if (expected !== undefined) {
190
+ makeJsonDecoratedLines({
191
+ json: expected,
192
+ path,
193
+ level: innerLevel,
194
+ decoratedLines,
195
+ diffMarker: 'expected',
196
+ fieldName: key,
197
+ });
198
+ }
199
+ if (received !== undefined) {
200
+ makeJsonDecoratedLines({
201
+ json: received,
202
+ path,
203
+ level: innerLevel,
204
+ decoratedLines,
205
+ diffMarker: 'received',
206
+ fieldName: key,
207
+ });
208
+ }
209
+ continue;
210
+ }
211
+ if (Array.isArray(value)) {
212
+ makeArrayDecoratedLines({
213
+ json: value,
214
+ path: currentPath,
215
+ level: innerLevel,
216
+ pathAnnotations,
217
+ decoratedLines,
218
+ diffMarker,
219
+ fieldName: key,
220
+ });
221
+ }
222
+ else if ((0, utils_1.isObject)(value)) {
223
+ makeObjectDecoratedLines({
224
+ json: value,
225
+ path: currentPath,
226
+ level: innerLevel,
227
+ pathAnnotations,
228
+ decoratedLines,
229
+ diffMarker,
230
+ fieldName: key,
231
+ });
232
+ }
233
+ else {
234
+ decoratedLines.push({
235
+ type: constants_1.DecoratedLineType.PrimitiveValue,
236
+ level: innerLevel,
237
+ value,
238
+ diffMarker,
239
+ fieldName: key,
240
+ });
241
+ }
242
+ }
243
+ if (!contentOnly) {
244
+ innerLevel--;
245
+ decoratedLines.push({
246
+ level: innerLevel,
247
+ type: constants_1.DecoratedLineType.ObjectClose,
248
+ diffMarker,
249
+ });
250
+ }
251
+ }
252
+ function makeArrayDecoratedLines(params) {
253
+ const { json, path, decoratedLines, pathAnnotations, contentOnly, diffMarker, level, fieldName, } = params;
254
+ let innerLevel = level;
255
+ const annotations = pathAnnotations?.[path] || [];
256
+ const missingValueAnnotations = annotations.filter(utils_2.isArrayMissingValueAnnotation);
257
+ if (!missingValueAnnotations.length && !json.length) {
258
+ decoratedLines.push({ level, type: constants_1.DecoratedLineType.EmptyArray, diffMarker, fieldName });
259
+ return;
260
+ }
261
+ const valueMismatchAnnotation = annotations.find(utils_2.isValueMismatchAnnotation);
262
+ if (valueMismatchAnnotation) {
263
+ const { expected, received } = valueMismatchAnnotation;
264
+ if (expected !== undefined) {
265
+ makeJsonDecoratedLines({
266
+ decoratedLines,
267
+ json: expected,
268
+ path,
269
+ level,
270
+ diffMarker: 'expected',
271
+ });
272
+ }
273
+ if (received !== undefined) {
274
+ makeJsonDecoratedLines({
275
+ decoratedLines,
276
+ json: received,
277
+ path,
278
+ level,
279
+ diffMarker: 'received',
280
+ });
281
+ }
282
+ return;
283
+ }
284
+ if (!contentOnly) {
285
+ decoratedLines.push({
286
+ level: innerLevel,
287
+ fieldName,
288
+ type: constants_1.DecoratedLineType.ArrayOpen,
289
+ diffMarker,
290
+ });
291
+ innerLevel++;
292
+ }
293
+ for (let i = 0; i < json.length; ++i) {
294
+ const currentPath = `${path ? path + '.' : ''}[${i}]`;
295
+ const currentPathAnnotations = pathAnnotations?.[currentPath] || [];
296
+ const valueMismatchAnnotation = currentPathAnnotations.find(utils_2.isValueMismatchAnnotation);
297
+ if (valueMismatchAnnotation) {
298
+ const { expected, received } = valueMismatchAnnotation;
299
+ if (expected !== undefined) {
300
+ makeJsonDecoratedLines({
301
+ decoratedLines,
302
+ json: expected,
303
+ path,
304
+ level: innerLevel,
305
+ diffMarker: 'expected',
306
+ });
307
+ }
308
+ if (received !== undefined) {
309
+ makeJsonDecoratedLines({
310
+ decoratedLines,
311
+ json: received,
312
+ path,
313
+ level: innerLevel,
314
+ diffMarker: 'received',
315
+ });
316
+ }
317
+ continue;
318
+ }
319
+ const value = json[i];
320
+ if (Array.isArray(value)) {
321
+ makeArrayDecoratedLines({
322
+ json: value,
323
+ decoratedLines,
324
+ level: innerLevel,
325
+ path: currentPath,
326
+ diffMarker,
327
+ pathAnnotations,
328
+ });
329
+ }
330
+ else if ((0, utils_1.isObject)(value)) {
331
+ makeObjectDecoratedLines({
332
+ json: value,
333
+ decoratedLines,
334
+ level: innerLevel,
335
+ path: currentPath,
336
+ diffMarker,
337
+ pathAnnotations,
338
+ });
339
+ }
340
+ else {
341
+ decoratedLines.push({
342
+ level: innerLevel,
343
+ type: constants_1.DecoratedLineType.PrimitiveValue,
344
+ value,
345
+ diffMarker,
346
+ });
347
+ }
348
+ }
349
+ for (const { expected } of missingValueAnnotations) {
350
+ makeJsonDecoratedLines({
351
+ decoratedLines,
352
+ json: expected,
353
+ path,
354
+ level: innerLevel,
355
+ diffMarker: 'expected',
356
+ });
357
+ }
358
+ if (!contentOnly) {
359
+ innerLevel--;
360
+ decoratedLines.push({
361
+ level: innerLevel,
362
+ type: constants_1.DecoratedLineType.ArrayClose,
363
+ diffMarker,
364
+ });
365
+ }
366
+ }
@@ -0,0 +1,59 @@
1
+ import type { Json, JsonPrimitive } from '../../types';
2
+ import type { DecoratedLineType, DiffType, PathAnnotationType } from './constants';
3
+ export type DiffType = (typeof DiffType)[keyof typeof DiffType];
4
+ export type DiffLog = DiffItem[];
5
+ export type DiffItem = DiffItemBase & {
6
+ context: DiffContextItem[];
7
+ };
8
+ export type DiffItemBase = {
9
+ side?: 'left' | 'right';
10
+ } & ({
11
+ type: typeof DiffType.ValueMismatch;
12
+ expected?: Json;
13
+ received?: Json;
14
+ } | {
15
+ type: typeof DiffType.ObjectMissingProperty;
16
+ expected: {
17
+ key: string;
18
+ value: Json;
19
+ };
20
+ } | {
21
+ type: typeof DiffType.ArrayMissingValue;
22
+ expected: Json;
23
+ });
24
+ export type DiffContextItem = {
25
+ objectField?: string;
26
+ arrayIndex?: number;
27
+ };
28
+ export type DecoratedLineType = (typeof DecoratedLineType)[keyof typeof DecoratedLineType];
29
+ export type DecoratedLine = {
30
+ fieldName?: string;
31
+ level: number;
32
+ diffMarker?: 'expected' | 'received';
33
+ } & ({
34
+ type: typeof DecoratedLineType.PrimitiveValue;
35
+ value: JsonPrimitive;
36
+ } | {
37
+ type: Exclude<DecoratedLineType, typeof DecoratedLineType.PrimitiveValue>;
38
+ });
39
+ export type PathAnnotation = ObjectMissingPropertyAnnotation | ObjectExtraPropertyAnnotation | ArrayMissingValueAnnotation | ValueMismatchAnnotation;
40
+ export type PathAnnotationType = (typeof PathAnnotationType)[keyof typeof PathAnnotationType];
41
+ export type ObjectMissingPropertyAnnotation = {
42
+ type: typeof PathAnnotationType.ObjectMissingProperty;
43
+ expected: {
44
+ key: string;
45
+ value: Json;
46
+ };
47
+ };
48
+ export type ObjectExtraPropertyAnnotation = {
49
+ type: typeof PathAnnotationType.ObjectExtraProperty;
50
+ };
51
+ export type ArrayMissingValueAnnotation = {
52
+ type: typeof PathAnnotationType.ArrayMissingValue;
53
+ expected: Json;
54
+ };
55
+ export type ValueMismatchAnnotation = {
56
+ type: typeof PathAnnotationType.ValueMismatch;
57
+ expected?: Json;
58
+ received?: Json;
59
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import type { ArrayMissingValueAnnotation, ObjectMissingPropertyAnnotation, PathAnnotation, ValueMismatchAnnotation } from './types';
2
+ export declare function isValueMismatchAnnotation(annotation: PathAnnotation): annotation is ValueMismatchAnnotation;
3
+ export declare function isObjectMissingPropertyAnnotation(annotation: PathAnnotation): annotation is ObjectMissingPropertyAnnotation;
4
+ export declare function isObjectExtraPropertyAnnotation(annotation: PathAnnotation): annotation is ArrayMissingValueAnnotation;
5
+ export declare function isArrayMissingValueAnnotation(annotation: PathAnnotation): annotation is ArrayMissingValueAnnotation;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValueMismatchAnnotation = isValueMismatchAnnotation;
4
+ exports.isObjectMissingPropertyAnnotation = isObjectMissingPropertyAnnotation;
5
+ exports.isObjectExtraPropertyAnnotation = isObjectExtraPropertyAnnotation;
6
+ exports.isArrayMissingValueAnnotation = isArrayMissingValueAnnotation;
7
+ const constants_1 = require("./constants");
8
+ function isValueMismatchAnnotation(annotation) {
9
+ return annotation.type === constants_1.PathAnnotationType.ValueMismatch;
10
+ }
11
+ function isObjectMissingPropertyAnnotation(annotation) {
12
+ return annotation.type === constants_1.PathAnnotationType.ObjectMissingProperty;
13
+ }
14
+ function isObjectExtraPropertyAnnotation(annotation) {
15
+ return annotation.type === constants_1.PathAnnotationType.ObjectExtraProperty;
16
+ }
17
+ function isArrayMissingValueAnnotation(annotation) {
18
+ return annotation.type === constants_1.PathAnnotationType.ArrayMissingValue;
19
+ }
@@ -0,0 +1,4 @@
1
+ import type { Request } from '@playwright/test';
2
+ import type { Json } from '../types';
3
+ import type { CommonMatcherOptions } from './types';
4
+ export declare function matchBody(request: Request, body: Json | undefined, { exact }: CommonMatcherOptions): string | null;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchBody = matchBody;
4
+ const DiffPrinter_1 = require("./compare/DiffPrinter");
5
+ function matchBody(request, body, { exact }) {
6
+ if (!body) {
7
+ return null;
8
+ }
9
+ const requestBody = request.postDataJSON();
10
+ const printer = new DiffPrinter_1.DiffPrinter({ left: requestBody, right: body });
11
+ return printer.printDiff({ side: 'left', exact }) || null;
12
+ }