@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,2 @@
1
+ import type { Request } from '@playwright/test';
2
+ export declare function matchMethod(request: Request, method?: string): string | null;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchMethod = matchMethod;
4
+ const DiffPrinter_1 = require("./compare/DiffPrinter");
5
+ function matchMethod(request, method) {
6
+ if (method === undefined) {
7
+ return null;
8
+ }
9
+ const printer = new DiffPrinter_1.DiffPrinter({
10
+ left: request.method().toUpperCase(),
11
+ right: method.toUpperCase(),
12
+ });
13
+ return printer.printDiff({ side: 'left' }) || null;
14
+ }
@@ -0,0 +1,3 @@
1
+ import type { Request } from '@playwright/test';
2
+ import type { CommonMatcherOptions } from './types';
3
+ export declare function matchQuery(request: Request, query: string | Record<string, string | string[]> | undefined, { exact }: CommonMatcherOptions): string | null;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchQuery = matchQuery;
4
+ const node_url_1 = require("node:url");
5
+ const DiffPrinter_1 = require("./compare/DiffPrinter");
6
+ function matchQuery(request, query, { exact }) {
7
+ if (!query) {
8
+ return null;
9
+ }
10
+ const requestSearchParams = new URL(request.url()).searchParams;
11
+ const querySearchParams = new node_url_1.URLSearchParams(query);
12
+ const requestEntries = searchParamsToObject(requestSearchParams);
13
+ const queryEntries = searchParamsToObject(querySearchParams);
14
+ const printer = new DiffPrinter_1.DiffPrinter({ left: requestEntries, right: queryEntries });
15
+ return printer.printDiff({ side: 'left', exact }) || null;
16
+ }
17
+ function searchParamsToObject(searchParams) {
18
+ const result = {};
19
+ const entries = searchParams.entries();
20
+ for (const [key, value] of entries) {
21
+ if (result[key]) {
22
+ if (Array.isArray(result[key])) {
23
+ result[key].push(value);
24
+ }
25
+ else {
26
+ result[key] = [result[key], value];
27
+ }
28
+ }
29
+ else {
30
+ result[key] = value;
31
+ }
32
+ }
33
+ return result;
34
+ }
@@ -0,0 +1 @@
1
+ export declare function matchUrl(url: string, pattern: string | RegExp): boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchUrl = matchUrl;
4
+ const minimatch_1 = require("minimatch");
5
+ function matchUrl(url, pattern) {
6
+ if (pattern instanceof RegExp) {
7
+ return pattern.test(url);
8
+ }
9
+ else {
10
+ const expandedPattern = pattern.startsWith('/') ? `**${pattern}` : `**/${pattern}`;
11
+ return (0, minimatch_1.minimatch)(url, expandedPattern);
12
+ }
13
+ }
@@ -0,0 +1,3 @@
1
+ import type { Json } from '../types';
2
+ import type { CommonMatcherOptions } from './types';
3
+ export declare function match(actual: Json, expected: Json, options: CommonMatcherOptions): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.match = match;
4
+ const compare_1 = require("./compare");
5
+ function match(actual, expected, options) {
6
+ const { exact } = options;
7
+ const diffLog = (0, compare_1.compare)({ left: actual, right: expected, exactArrays: exact });
8
+ const diffLogForActual = diffLog.filter(({ side }) => side === 'left');
9
+ return exact ? diffLog.length === 0 : diffLogForActual.length === 0;
10
+ }
@@ -0,0 +1,3 @@
1
+ export type CommonMatcherOptions = {
2
+ exact: boolean;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function isObject(entry: unknown): entry is object;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = isObject;
4
+ function isObject(entry) {
5
+ const entryType = typeof entry;
6
+ return (entry !== null &&
7
+ !Array.isArray(entry) &&
8
+ (entryType === 'object' || entryType === 'function'));
9
+ }
@@ -0,0 +1,22 @@
1
+ interface PollWithTimeoutParams<T> {
2
+ /** Function to poll (should return a promise). */
3
+ callbackFn: () => Promise<T>;
4
+ /** Function that checks the result to determine if polling should stop. */
5
+ condition: (result: T) => boolean;
6
+ /** Time between polls in milliseconds; default value `1000ms`. */
7
+ interval?: number;
8
+ /** Maximum time to wait in milliseconds before rejecting; default value `15000ms`. */
9
+ timeout?: number;
10
+ /** Called when timeout occurs. */
11
+ onTimeout?: (params: {
12
+ /** Lets you resolve with a custom value */
13
+ resolve: (value: T | PromiseLike<T>) => void;
14
+ /** Lets you reject with custom error */
15
+ reject: (reason?: unknown) => void;
16
+ }) => void;
17
+ }
18
+ /**
19
+ * Polls a function at a specified interval until a condition is met or timeout is reached.
20
+ */
21
+ export declare function pollWithTimeout<T>(params: PollWithTimeoutParams<T>): Promise<T>;
22
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pollWithTimeout = pollWithTimeout;
4
+ /**
5
+ * Polls a function at a specified interval until a condition is met or timeout is reached.
6
+ */
7
+ async function pollWithTimeout(params) {
8
+ const { callbackFn, condition, interval = 1000, timeout = 5000, onTimeout } = params;
9
+ const startTime = Date.now();
10
+ return new Promise((resolve, reject) => {
11
+ const checkTimeout = () => {
12
+ if (timeout && Date.now() - startTime >= timeout) {
13
+ if (onTimeout) {
14
+ onTimeout({ resolve, reject });
15
+ }
16
+ else {
17
+ reject(new Error(`Request polling timed out after ${timeout}ms`));
18
+ }
19
+ return;
20
+ }
21
+ };
22
+ const executePoll = async () => {
23
+ try {
24
+ checkTimeout();
25
+ const result = await callbackFn();
26
+ if (condition(result)) {
27
+ resolve(result);
28
+ }
29
+ else {
30
+ setTimeout(executePoll, interval);
31
+ }
32
+ }
33
+ catch (error) {
34
+ reject(error);
35
+ }
36
+ };
37
+ void executePoll();
38
+ });
39
+ }
@@ -0,0 +1,18 @@
1
+ export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
2
+ export type QueryParams = Record<string, string | string[]>;
3
+ export type JsonPrimitive = string | number | boolean | null;
4
+ export type JsonArray = Json[];
5
+ export type JsonObject = {
6
+ [key: string]: Json;
7
+ };
8
+ export type JsonComposite = JsonArray | JsonObject;
9
+ export type Json = JsonPrimitive | JsonComposite;
10
+ export type ExpectRequestFnMatcher = {
11
+ method?: HttpMethod;
12
+ query?: string | QueryParams;
13
+ body?: Json;
14
+ };
15
+ export type ExpectRequestFnOptions = {
16
+ timeout?: number;
17
+ exact?: boolean;
18
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import type { BrowserContext } from '@playwright/test';
2
+ /**
3
+ * Return extra HTTP header value from internal extraHttpHeaders list
4
+ */
5
+ export declare function getExtraHttpHeader(browserContext: BrowserContext, headerName: string): string | undefined;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExtraHttpHeader = getExtraHttpHeader;
4
+ const extraHttpHeaders_1 = require("../data/extraHttpHeaders");
5
+ /**
6
+ * Return extra HTTP header value from internal extraHttpHeaders list
7
+ */
8
+ function getExtraHttpHeader(browserContext, headerName) {
9
+ if (!extraHttpHeaders_1.extraHttpHeaders.has(browserContext)) {
10
+ return undefined;
11
+ }
12
+ const headers = extraHttpHeaders_1.extraHttpHeaders.get(browserContext);
13
+ return headers.get(headerName.toLowerCase());
14
+ }
@@ -0,0 +1,7 @@
1
+ import type { BrowserContext } from '@playwright/test';
2
+ /**
3
+ * Return extra HTTP headers list from internal extraHttpHeaders list
4
+ */
5
+ export declare function getExtraHttpHeaders(browserContext: BrowserContext): {
6
+ [k: string]: string;
7
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExtraHttpHeaders = getExtraHttpHeaders;
4
+ const extraHttpHeaders_1 = require("../data/extraHttpHeaders");
5
+ /**
6
+ * Return extra HTTP headers list from internal extraHttpHeaders list
7
+ */
8
+ function getExtraHttpHeaders(browserContext) {
9
+ if (!extraHttpHeaders_1.extraHttpHeaders.has(browserContext)) {
10
+ return {};
11
+ }
12
+ const headers = extraHttpHeaders_1.extraHttpHeaders.get(browserContext);
13
+ return Object.fromEntries(headers.entries());
14
+ }
@@ -0,0 +1,5 @@
1
+ import type { GlobalSettings } from '../data/globalSettings';
2
+ /**
3
+ * Returns global settings for commands for a given section (command)
4
+ */
5
+ export declare function getGlobalSettings<TSection extends keyof GlobalSettings>(section: TSection): GlobalSettings[TSection];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGlobalSettings = getGlobalSettings;
4
+ const globalSettings_1 = require("../data/globalSettings");
5
+ /**
6
+ * Returns global settings for commands for a given section (command)
7
+ */
8
+ function getGlobalSettings(section) {
9
+ return globalSettings_1.globalSettings[section];
10
+ }
@@ -0,0 +1,5 @@
1
+ import type { Page } from '@playwright/test';
2
+ /**
3
+ * Returns the test slug
4
+ */
5
+ export declare function getTestSlug(page: Page): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTestSlug = getTestSlug;
4
+ const testSlugs_1 = require("../data/testSlugs");
5
+ /**
6
+ * Returns the test slug
7
+ */
8
+ function getTestSlug(page) {
9
+ if (testSlugs_1.testSlugs.has(page)) {
10
+ return testSlugs_1.testSlugs.get(page);
11
+ }
12
+ throw new Error("Can't find slug for test");
13
+ }
@@ -0,0 +1,5 @@
1
+ import type { BrowserContext } from '@playwright/test';
2
+ /**
3
+ * Check existence of the extra HTTP header in internal extraHttpHeaders list
4
+ */
5
+ export declare function hasExtraHttpHeader(browserContext: BrowserContext, headerName: string): boolean;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasExtraHttpHeader = hasExtraHttpHeader;
4
+ const extraHttpHeaders_1 = require("../data/extraHttpHeaders");
5
+ /**
6
+ * Check existence of the extra HTTP header in internal extraHttpHeaders list
7
+ */
8
+ function hasExtraHttpHeader(browserContext, headerName) {
9
+ if (!extraHttpHeaders_1.extraHttpHeaders.has(browserContext)) {
10
+ return false;
11
+ }
12
+ const headers = extraHttpHeaders_1.extraHttpHeaders.get(browserContext);
13
+ return headers.has(headerName.toLowerCase());
14
+ }
@@ -0,0 +1,18 @@
1
+ export { addExtraHttpHeader } from './addExtraHttpHeader';
2
+ export { addExtraHttpHeaders } from './addExtraHttpHeaders';
3
+ export { assertElementsHidden } from './assertElementsHidden';
4
+ export { clearExtraHttpHeaders } from './clearExtraHttpHeaders';
5
+ export { collectPageActivity } from './collectPageActivity';
6
+ export { disableAnimations } from './disableAnimation';
7
+ export { getExtraHttpHeader } from './getExtraHttpHeader';
8
+ export { getExtraHttpHeaders } from './getExtraHttpHeaders';
9
+ export { getGlobalSettings } from './getGlobalSettings';
10
+ export { getTestSlug } from './getTestSlug';
11
+ export { hasExtraHttpHeader } from './hasExtraHttpHeader';
12
+ export { matchScreenshot } from './matchScreenshot';
13
+ export { mockDate } from './mockDate';
14
+ export { removeExtraHttpHeader } from './removeExtraHttpHeader';
15
+ export { setCacheSettings } from './setCacheSettings';
16
+ export { setGlobalSettings } from './setGlobalSettings';
17
+ export { setTestSlug } from './setTestSlug';
18
+ export { waitForNetworkSettled } from './waitForNetworkSettled';
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForNetworkSettled = exports.setTestSlug = exports.setGlobalSettings = exports.setCacheSettings = exports.removeExtraHttpHeader = exports.mockDate = exports.matchScreenshot = exports.hasExtraHttpHeader = exports.getTestSlug = exports.getGlobalSettings = exports.getExtraHttpHeaders = exports.getExtraHttpHeader = exports.disableAnimations = exports.collectPageActivity = exports.clearExtraHttpHeaders = exports.assertElementsHidden = exports.addExtraHttpHeaders = exports.addExtraHttpHeader = void 0;
4
+ var addExtraHttpHeader_1 = require("./addExtraHttpHeader");
5
+ Object.defineProperty(exports, "addExtraHttpHeader", { enumerable: true, get: function () { return addExtraHttpHeader_1.addExtraHttpHeader; } });
6
+ var addExtraHttpHeaders_1 = require("./addExtraHttpHeaders");
7
+ Object.defineProperty(exports, "addExtraHttpHeaders", { enumerable: true, get: function () { return addExtraHttpHeaders_1.addExtraHttpHeaders; } });
8
+ var assertElementsHidden_1 = require("./assertElementsHidden");
9
+ Object.defineProperty(exports, "assertElementsHidden", { enumerable: true, get: function () { return assertElementsHidden_1.assertElementsHidden; } });
10
+ var clearExtraHttpHeaders_1 = require("./clearExtraHttpHeaders");
11
+ Object.defineProperty(exports, "clearExtraHttpHeaders", { enumerable: true, get: function () { return clearExtraHttpHeaders_1.clearExtraHttpHeaders; } });
12
+ var collectPageActivity_1 = require("./collectPageActivity");
13
+ Object.defineProperty(exports, "collectPageActivity", { enumerable: true, get: function () { return collectPageActivity_1.collectPageActivity; } });
14
+ var disableAnimation_1 = require("./disableAnimation");
15
+ Object.defineProperty(exports, "disableAnimations", { enumerable: true, get: function () { return disableAnimation_1.disableAnimations; } });
16
+ var getExtraHttpHeader_1 = require("./getExtraHttpHeader");
17
+ Object.defineProperty(exports, "getExtraHttpHeader", { enumerable: true, get: function () { return getExtraHttpHeader_1.getExtraHttpHeader; } });
18
+ var getExtraHttpHeaders_1 = require("./getExtraHttpHeaders");
19
+ Object.defineProperty(exports, "getExtraHttpHeaders", { enumerable: true, get: function () { return getExtraHttpHeaders_1.getExtraHttpHeaders; } });
20
+ var getGlobalSettings_1 = require("./getGlobalSettings");
21
+ Object.defineProperty(exports, "getGlobalSettings", { enumerable: true, get: function () { return getGlobalSettings_1.getGlobalSettings; } });
22
+ var getTestSlug_1 = require("./getTestSlug");
23
+ Object.defineProperty(exports, "getTestSlug", { enumerable: true, get: function () { return getTestSlug_1.getTestSlug; } });
24
+ var hasExtraHttpHeader_1 = require("./hasExtraHttpHeader");
25
+ Object.defineProperty(exports, "hasExtraHttpHeader", { enumerable: true, get: function () { return hasExtraHttpHeader_1.hasExtraHttpHeader; } });
26
+ var matchScreenshot_1 = require("./matchScreenshot");
27
+ Object.defineProperty(exports, "matchScreenshot", { enumerable: true, get: function () { return matchScreenshot_1.matchScreenshot; } });
28
+ var mockDate_1 = require("./mockDate");
29
+ Object.defineProperty(exports, "mockDate", { enumerable: true, get: function () { return mockDate_1.mockDate; } });
30
+ var removeExtraHttpHeader_1 = require("./removeExtraHttpHeader");
31
+ Object.defineProperty(exports, "removeExtraHttpHeader", { enumerable: true, get: function () { return removeExtraHttpHeader_1.removeExtraHttpHeader; } });
32
+ var setCacheSettings_1 = require("./setCacheSettings");
33
+ Object.defineProperty(exports, "setCacheSettings", { enumerable: true, get: function () { return setCacheSettings_1.setCacheSettings; } });
34
+ var setGlobalSettings_1 = require("./setGlobalSettings");
35
+ Object.defineProperty(exports, "setGlobalSettings", { enumerable: true, get: function () { return setGlobalSettings_1.setGlobalSettings; } });
36
+ var setTestSlug_1 = require("./setTestSlug");
37
+ Object.defineProperty(exports, "setTestSlug", { enumerable: true, get: function () { return setTestSlug_1.setTestSlug; } });
38
+ var waitForNetworkSettled_1 = require("./waitForNetworkSettled");
39
+ Object.defineProperty(exports, "waitForNetworkSettled", { enumerable: true, get: function () { return waitForNetworkSettled_1.waitForNetworkSettled; } });
@@ -0,0 +1,90 @@
1
+ import type { Locator, Page, PageScreenshotOptions } from '@playwright/test';
2
+ export type Theme = 'light' | 'dark';
3
+ export type OnSwitchThemeCallback = (theme: Theme, page: Page) => Promise<void>;
4
+ export type OnBeforeScreenshotCallback = (page: Page) => Promise<void>;
5
+ export type ScreenshotOptions = Omit<PageScreenshotOptions, 'type' | 'quality' | 'path'> & {
6
+ /**
7
+ * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is
8
+ * configurable with `TestConfig.expect`. Unset by default.
9
+ */
10
+ maxDiffPixelRatio?: number;
11
+ /**
12
+ * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by
13
+ * default.
14
+ */
15
+ maxDiffPixels?: number;
16
+ /**
17
+ * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the same
18
+ * pixel in compared images, between zero (strict) and one (lax), default is configurable with `TestConfig.expect`.
19
+ * Defaults to `0.2`.
20
+ */
21
+ threshold?: number;
22
+ };
23
+ export type MatchScreenshotOptions = {
24
+ /**
25
+ * The element or page to be screenshotted
26
+ * @defaultValue `page`
27
+ */
28
+ locator?: Locator | Page;
29
+ /**
30
+ * The name of the screenshot in the test, it is not necessary to specify it for a single screenshot
31
+ * @defaultValue globalSettings.matchScreenshot.name
32
+ */
33
+ name?: string;
34
+ /**
35
+ * Screenshot creation and comparison parameters (parameters of `toHaveScreenshot` call)
36
+ * @defaultValue globalSettings.matchScreenshot.options
37
+ */
38
+ options?: ScreenshotOptions;
39
+ /**
40
+ * CSS selectors (pure CSS) of elements to hide
41
+ * @defaultValue globalSettings.matchScreenshot.hideBySelector
42
+ */
43
+ hideBySelector?: string[];
44
+ /**
45
+ * Pause before screenshot (ms)
46
+ * @defaultValue globalSettings.matchScreenshot.pause
47
+ */
48
+ pause?: number;
49
+ /**
50
+ * Use soft assertion
51
+ * @defaultValue globalSettings.matchScreenshot.soft
52
+ */
53
+ soft?: boolean;
54
+ /**
55
+ * Move the mouse cursor to the specified coordinates (to avoid unnecessary hover in the screenshot)
56
+ */
57
+ moveMouse?: {
58
+ x: number;
59
+ y: number;
60
+ } | [x: number, y: number] | number;
61
+ /**
62
+ * Should I add a slug to the screenshot file name?
63
+ * @defaultValue globalSettings.matchScreenshot.shouldPrependSlugToName
64
+ */
65
+ shouldPrependSlugToName?: boolean;
66
+ /**
67
+ * Topics that require a screenshot
68
+ * By default, screenshots are taken for the current theme. Switching does not occur
69
+ * @defaultValue globalSettings.matchScreenshot.themes
70
+ */
71
+ themes?: Theme[];
72
+ /**
73
+ * Callback before taking a screenshot. Useful for any special stabilizing actions
74
+ * @param page Page current page
75
+ * @defaultValue globalSettings.matchScreenshot.onBeforeScreenshot
76
+ */
77
+ onBeforeScreenshot?: OnBeforeScreenshotCallback;
78
+ /**
79
+ * Callback to switch theme to pages before taking screenshot
80
+ * By default, switches the theme using `page.emulateMedia({ colorScheme: theme });`
81
+ * @param theme Theme The theme for which the screenshot will be taken
82
+ * @param page Page current page
83
+ * @defaultValue globalSettings.matchScreenshot.onSwitchTheme
84
+ */
85
+ onSwitchTheme?: OnSwitchThemeCallback;
86
+ };
87
+ /**
88
+ * Performs a check on a screenshot, with a prefix of the test slug in the name
89
+ */
90
+ export declare function matchScreenshot(page: Page, { locator, name, options, hideBySelector, pause, soft, moveMouse, shouldPrependSlugToName, themes, onBeforeScreenshot, onSwitchTheme, }?: MatchScreenshotOptions): Promise<void>;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchScreenshot = matchScreenshot;
4
+ const test_1 = require("@playwright/test");
5
+ const globalSettings_1 = require("../data/globalSettings");
6
+ const getTestSlug_1 = require("./getTestSlug");
7
+ const stylesForHide = /* css */ `{
8
+ visibility: hidden !important;
9
+ opacity: 0 !important;
10
+ }`;
11
+ /**
12
+ * Performs a check on a screenshot, with a prefix of the test slug in the name
13
+ */
14
+ async function matchScreenshot(page, { locator = page, name = globalSettings_1.globalSettings.matchScreenshot.name, options = {}, hideBySelector, pause = globalSettings_1.globalSettings.matchScreenshot.pause, soft = globalSettings_1.globalSettings.matchScreenshot.soft, moveMouse, shouldPrependSlugToName = globalSettings_1.globalSettings.matchScreenshot.shouldPrependSlugToName, themes = globalSettings_1.globalSettings.matchScreenshot.themes, onBeforeScreenshot = globalSettings_1.globalSettings.matchScreenshot.onBeforeScreenshot, onSwitchTheme = globalSettings_1.globalSettings.matchScreenshot.onSwitchTheme, } = {}) {
15
+ const combinedOptions = {
16
+ ...globalSettings_1.globalSettings.matchScreenshot.options,
17
+ ...options,
18
+ };
19
+ const styleElements = [];
20
+ const combinedHideBySelector = [
21
+ ...(globalSettings_1.globalSettings.matchScreenshot.hideBySelector || []),
22
+ ...(hideBySelector || []),
23
+ ];
24
+ if (combinedHideBySelector.length !== 0) {
25
+ const selector = combinedHideBySelector.join(',');
26
+ const styles = selector + stylesForHide;
27
+ styleElements.push(await appendStylesToPage(page, styles));
28
+ }
29
+ if (options.style) {
30
+ styleElements.push(await appendStylesToPage(page, options.style));
31
+ }
32
+ if (moveMouse) {
33
+ let x = 0;
34
+ let y = 0;
35
+ if (typeof moveMouse === 'number') {
36
+ x = y = moveMouse;
37
+ }
38
+ else if (Array.isArray(moveMouse)) {
39
+ x = moveMouse[0];
40
+ y = moveMouse[1];
41
+ }
42
+ else {
43
+ x = moveMouse.x;
44
+ y = moveMouse.y;
45
+ }
46
+ await page.mouse.move(x, y);
47
+ }
48
+ await onBeforeScreenshot?.(page);
49
+ const slug = (0, getTestSlug_1.getTestSlug)(page);
50
+ await page.waitForTimeout(pause);
51
+ if (themes && themes.length) {
52
+ for (const theme of themes) {
53
+ await onSwitchTheme?.(theme, page);
54
+ const resolvedName = name ? `${name}-${theme}` : undefined;
55
+ await doMatchScreenshot({
56
+ locator,
57
+ name: resolvedName,
58
+ slug,
59
+ options: combinedOptions,
60
+ shouldPrependSlugToName,
61
+ soft,
62
+ });
63
+ }
64
+ }
65
+ else {
66
+ await doMatchScreenshot({
67
+ locator,
68
+ name,
69
+ slug,
70
+ options: combinedOptions,
71
+ shouldPrependSlugToName,
72
+ soft,
73
+ });
74
+ }
75
+ for (const styleElement of styleElements) {
76
+ await styleElement.evaluate((element) => element.remove());
77
+ await styleElement.dispose();
78
+ }
79
+ }
80
+ async function doMatchScreenshot(params) {
81
+ const { locator, name, slug, options, shouldPrependSlugToName, soft } = params;
82
+ const resolvedName = resolveScreenshotName({ name, slug, shouldPrependSlugToName });
83
+ const resolvedExpect = soft ? test_1.expect.soft : test_1.expect;
84
+ if (resolvedName) {
85
+ await resolvedExpect(locator).toHaveScreenshot(resolvedName, options);
86
+ }
87
+ else {
88
+ await resolvedExpect(locator).toHaveScreenshot(options);
89
+ }
90
+ }
91
+ function resolveScreenshotName(params) {
92
+ const { name, slug, shouldPrependSlugToName } = params;
93
+ if (!name) {
94
+ return undefined;
95
+ }
96
+ const resolvedName = [name + '.png'];
97
+ if (shouldPrependSlugToName) {
98
+ resolvedName.unshift(slug);
99
+ }
100
+ return resolvedName;
101
+ }
102
+ async function appendStylesToPage(page, styles) {
103
+ return await page.addStyleTag({ content: styles });
104
+ }
@@ -0,0 +1,10 @@
1
+ import type { Page } from '@playwright/test';
2
+ /**
3
+ * NOTE:
4
+ * Replaces the Date object with an object in which the date is set to the specified one.
5
+ *
6
+ * The date and time are not fixed, but go at the usual speed, but starting from the specified one.
7
+ *
8
+ * Use playwright API Clock https://playwright.dev/docs/clock
9
+ */
10
+ export declare function mockDate(page: Page, year?: number, month?: number, day?: number, hour?: number, min?: number, sec?: number): Promise<void>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockDate = mockDate;
4
+ const path_1 = require("path");
5
+ const globalSettings_1 = require("../data/globalSettings");
6
+ /**
7
+ * NOTE:
8
+ * Replaces the Date object with an object in which the date is set to the specified one.
9
+ *
10
+ * The date and time are not fixed, but go at the usual speed, but starting from the specified one.
11
+ *
12
+ * Use playwright API Clock https://playwright.dev/docs/clock
13
+ */
14
+ async function mockDate(page, year = globalSettings_1.globalSettings.mockDate.defaultDate.year, month = globalSettings_1.globalSettings.mockDate.defaultDate.month, day = globalSettings_1.globalSettings.mockDate.defaultDate.day, hour = globalSettings_1.globalSettings.mockDate.defaultDate.hour, min = globalSettings_1.globalSettings.mockDate.defaultDate.min, sec = globalSettings_1.globalSettings.mockDate.defaultDate.sec) {
15
+ await page.addInitScript({ path: (0, path_1.resolve)(require.resolve('timekeeper')) });
16
+ await page.addInitScript(({ year, month, day, hour, min, sec, }) => {
17
+ const date = new Date(year, month, day, hour, min, sec);
18
+ window.timekeeper.travel(date);
19
+ }, { year, month, day, hour, min, sec });
20
+ }
@@ -0,0 +1,5 @@
1
+ import type { BrowserContext } from '@playwright/test';
2
+ /**
3
+ * Remove header from internal extraHttpHeaders list and extra HTTP headers in browser context
4
+ */
5
+ export declare function removeExtraHttpHeader(browserContext: BrowserContext, headerName: string): Promise<void>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeExtraHttpHeader = removeExtraHttpHeader;
4
+ const extraHttpHeaders_1 = require("../data/extraHttpHeaders");
5
+ /**
6
+ * Remove header from internal extraHttpHeaders list and extra HTTP headers in browser context
7
+ */
8
+ async function removeExtraHttpHeader(browserContext, headerName) {
9
+ if (!extraHttpHeaders_1.extraHttpHeaders.has(browserContext)) {
10
+ return;
11
+ }
12
+ const headers = extraHttpHeaders_1.extraHttpHeaders.get(browserContext);
13
+ headers.delete(headerName.toLowerCase());
14
+ await browserContext.setExtraHTTPHeaders(Object.fromEntries(headers.entries()));
15
+ }
@@ -0,0 +1,7 @@
1
+ import type { CacheSettings } from '../data/cacheSettings';
2
+ /**
3
+ * Sets caching options on the file system
4
+ * @param key Caching object
5
+ * @param options Caching options
6
+ */
7
+ export declare function setCacheSettings<TKey extends keyof CacheSettings>(key: TKey, options: Partial<CacheSettings[TKey]>): void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setCacheSettings = setCacheSettings;
4
+ const cacheSettings_1 = require("../data/cacheSettings");
5
+ /**
6
+ * Sets caching options on the file system
7
+ * @param key Caching object
8
+ * @param options Caching options
9
+ */
10
+ function setCacheSettings(key, options) {
11
+ Object.assign(cacheSettings_1.cacheSettings[key], options);
12
+ }