@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,100 @@
1
+ import type { Config } from '../actions/collectPageActivity';
2
+ import type { OnBeforeScreenshotCallback, OnSwitchThemeCallback, ScreenshotOptions, Theme } from '../actions/matchScreenshot';
3
+ /**
4
+ * Global settings for commands
5
+ */
6
+ export declare const globalSettings: {
7
+ /**
8
+ * actions/assertElementsHidden
9
+ */
10
+ assertElementsHidden: {
11
+ defaultWaitForVisibleTimeout: number;
12
+ };
13
+ /**
14
+ * actions/matchScreenshot
15
+ */
16
+ matchScreenshot: {
17
+ /**
18
+ * Screenshot creation and comparison parameters.
19
+ * Will be merged with those passed during the call.
20
+ */
21
+ options: ScreenshotOptions;
22
+ /**
23
+ * CSS selectors (pure CSS) of elements to hide.
24
+ * Will be merged with those passed in the call.
25
+ */
26
+ hideBySelector: string[] | undefined;
27
+ /**
28
+ * Pause before screenshot (ms)
29
+ */
30
+ pause: number;
31
+ /**
32
+ * Use soft assertion
33
+ */
34
+ soft: boolean;
35
+ /**
36
+ * Default screenshot name
37
+ */
38
+ name: string | undefined;
39
+ /**
40
+ * Should I add a slug to the screenshot file name?
41
+ */
42
+ shouldPrependSlugToName: boolean;
43
+ /**
44
+ * Topics that require a screenshot
45
+ * By default, screenshots are taken for the current theme. Switching does not occur
46
+ */
47
+ themes: Theme[] | undefined;
48
+ /**
49
+ * Callback before taking a screenshot. Useful for any special stabilizing actions
50
+ * @param page Page Current page
51
+ */
52
+ onBeforeScreenshot: OnBeforeScreenshotCallback | undefined;
53
+ /**
54
+ * Callback to switch theme to pages before taking screenshot
55
+ * By default, switches the theme using `page.emulateMedia({ colorScheme: theme });`
56
+ * @param theme Theme The theme for which the screenshot will be taken
57
+ * @param page Page Current page
58
+ */
59
+ onSwitchTheme: undefined | OnSwitchThemeCallback;
60
+ };
61
+ /**
62
+ * actions/mockDate
63
+ */
64
+ mockDate: {
65
+ /**
66
+ * Default date
67
+ */
68
+ defaultDate: {
69
+ year: number;
70
+ month: number;
71
+ day: number;
72
+ hour: number;
73
+ min: number;
74
+ sec: number;
75
+ };
76
+ };
77
+ /**
78
+ * utils/waitForResolve
79
+ */
80
+ waitForResolve: {
81
+ /**
82
+ * Interval between checks (ms)
83
+ */
84
+ interval: number;
85
+ /**
86
+ * Timeout after which checks are aborted (ms)
87
+ * `0` — without timeout
88
+ */
89
+ timeout: number;
90
+ };
91
+ collectPageActivity: Pick<Required<Config>, "ignoredMessageTypes" | "expectedMessages" | "ignoredResponseStatuses" | "expectedResponses" | "requestIdHeader">;
92
+ waitForNetworkSettled: {
93
+ /** Timeout time after request */
94
+ delay: number;
95
+ };
96
+ };
97
+ export type GlobalSettings = typeof globalSettings;
98
+ export type PartialGlobalSettings = {
99
+ [Key in keyof GlobalSettings]?: Partial<GlobalSettings[Key]>;
100
+ };
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.globalSettings = void 0;
4
+ const constants_1 = require("../actions/collectPageActivity/constants");
5
+ const collectPageActivity = {
6
+ ignoredMessageTypes: constants_1.defaultIgnoredMessageTypes,
7
+ expectedMessages: [
8
+ {
9
+ type: 'error',
10
+ text: /^Failed to load resource: the server responded with a status of/,
11
+ },
12
+ ],
13
+ ignoredResponseStatuses: constants_1.defaultIgnoredResponseStatuses,
14
+ expectedResponses: [],
15
+ requestIdHeader: 'x-request-id',
16
+ };
17
+ /**
18
+ * Global settings for commands
19
+ */
20
+ exports.globalSettings = {
21
+ /**
22
+ * actions/assertElementsHidden
23
+ */
24
+ assertElementsHidden: {
25
+ defaultWaitForVisibleTimeout: 300,
26
+ },
27
+ /**
28
+ * actions/matchScreenshot
29
+ */
30
+ matchScreenshot: {
31
+ /**
32
+ * Screenshot creation and comparison parameters.
33
+ * Will be merged with those passed during the call.
34
+ */
35
+ options: {},
36
+ /**
37
+ * CSS selectors (pure CSS) of elements to hide.
38
+ * Will be merged with those passed in the call.
39
+ */
40
+ hideBySelector: undefined,
41
+ /**
42
+ * Pause before screenshot (ms)
43
+ */
44
+ pause: 1000,
45
+ /**
46
+ * Use soft assertion
47
+ */
48
+ soft: true,
49
+ /**
50
+ * Default screenshot name
51
+ */
52
+ name: 'plain',
53
+ /**
54
+ * Should I add a slug to the screenshot file name?
55
+ */
56
+ shouldPrependSlugToName: true,
57
+ /**
58
+ * Topics that require a screenshot
59
+ * By default, screenshots are taken for the current theme. Switching does not occur
60
+ */
61
+ themes: undefined,
62
+ /**
63
+ * Callback before taking a screenshot. Useful for any special stabilizing actions
64
+ * @param page Page Current page
65
+ */
66
+ onBeforeScreenshot: undefined,
67
+ /**
68
+ * Callback to switch theme to pages before taking screenshot
69
+ * By default, switches the theme using `page.emulateMedia({ colorScheme: theme });`
70
+ * @param theme Theme The theme for which the screenshot will be taken
71
+ * @param page Page Current page
72
+ */
73
+ onSwitchTheme: (async (theme, page) => {
74
+ await page.emulateMedia({ colorScheme: theme });
75
+ }),
76
+ },
77
+ /**
78
+ * actions/mockDate
79
+ */
80
+ mockDate: {
81
+ /**
82
+ * Default date
83
+ */
84
+ defaultDate: {
85
+ year: 2020,
86
+ month: 7,
87
+ day: 15,
88
+ hour: 12,
89
+ min: 0,
90
+ sec: 0,
91
+ },
92
+ },
93
+ /**
94
+ * utils/waitForResolve
95
+ */
96
+ waitForResolve: {
97
+ /**
98
+ * Interval between checks (ms)
99
+ */
100
+ interval: 100,
101
+ /**
102
+ * Timeout after which checks are aborted (ms)
103
+ * `0` — without timeout
104
+ */
105
+ timeout: 5000,
106
+ },
107
+ collectPageActivity,
108
+ waitForNetworkSettled: {
109
+ /** Timeout time after request */
110
+ delay: 0,
111
+ },
112
+ };
@@ -0,0 +1,36 @@
1
+ import type { BrowserContext } from '@playwright/test';
2
+ export type StorageState = Awaited<ReturnType<BrowserContext['storageState']>>;
3
+ /**
4
+ * Adds a snapshot to the repository
5
+ */
6
+ export declare function setState(key: string, state: StorageState): void;
7
+ /**
8
+ * Returns a snapshot from storage
9
+ */
10
+ export declare function getState(key: string): Promise<{
11
+ cookies: Array<{
12
+ name: string;
13
+ value: string;
14
+ domain: string;
15
+ path: string;
16
+ expires: number;
17
+ httpOnly: boolean;
18
+ secure: boolean;
19
+ sameSite: "Strict" | "Lax" | "None";
20
+ }>;
21
+ origins: Array<{
22
+ origin: string;
23
+ localStorage: Array<{
24
+ name: string;
25
+ value: string;
26
+ }>;
27
+ }>;
28
+ } | undefined>;
29
+ /**
30
+ * Checks if a snapshot is in the repository
31
+ */
32
+ export declare function hasState(key: string): Promise<boolean>;
33
+ /**
34
+ * Deletes a snapshot from storage
35
+ */
36
+ export declare function deleteState(key: string): void;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setState = setState;
4
+ exports.getState = getState;
5
+ exports.hasState = hasState;
6
+ exports.deleteState = deleteState;
7
+ const deleteCache_1 = require("../utils/deleteCache");
8
+ const readCache_1 = require("../utils/readCache");
9
+ const writeCache_1 = require("../utils/writeCache");
10
+ const cacheSettings_1 = require("./cacheSettings");
11
+ /**
12
+ * Browser Storage Snapshots
13
+ */
14
+ const storageStates = new Map();
15
+ /**
16
+ * Adds a snapshot to the repository
17
+ */
18
+ function setState(key, state) {
19
+ storageStates.set(key, state);
20
+ if (cacheSettings_1.cacheSettings.auth.path) {
21
+ void (0, writeCache_1.writeCache)(cacheSettings_1.cacheSettings.auth.path, key, state).catch((error) => console.warn(error));
22
+ }
23
+ }
24
+ /**
25
+ * Returns a snapshot from storage
26
+ */
27
+ async function getState(key) {
28
+ if (!storageStates.has(key) && cacheSettings_1.cacheSettings.auth.path) {
29
+ const state = await (0, readCache_1.readCache)(cacheSettings_1.cacheSettings.auth.path, key, cacheSettings_1.cacheSettings.auth.ttl);
30
+ if (state) {
31
+ storageStates.set(key, state);
32
+ }
33
+ }
34
+ return storageStates.get(key);
35
+ }
36
+ /**
37
+ * Checks if a snapshot is in the repository
38
+ */
39
+ async function hasState(key) {
40
+ return Boolean(await getState(key));
41
+ }
42
+ /**
43
+ * Deletes a snapshot from storage
44
+ */
45
+ function deleteState(key) {
46
+ storageStates.delete(key);
47
+ if (cacheSettings_1.cacheSettings.auth.path) {
48
+ void (0, deleteCache_1.deleteCache)(cacheSettings_1.cacheSettings.auth.path, key);
49
+ }
50
+ }
@@ -0,0 +1,5 @@
1
+ import type { Page } from '@playwright/test';
2
+ /**
3
+ * Storage of test slugs by test page
4
+ */
5
+ export declare const testSlugs: WeakMap<Page, string>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testSlugs = void 0;
4
+ /**
5
+ * Storage of test slugs by test page
6
+ */
7
+ exports.testSlugs = new WeakMap();
@@ -0,0 +1,8 @@
1
+ import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
2
+ import type { ExpectRequestFn } from './types';
3
+ export declare const expectRequestFixture: TestFixture<ExpectRequestFn, PlaywrightTestOptions & PlaywrightTestArgs>;
4
+ declare const fixtureOptions: {
5
+ readonly scope: "test";
6
+ };
7
+ export declare const expectRequest: [typeof expectRequestFixture, typeof fixtureOptions];
8
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expectRequest = exports.expectRequestFixture = void 0;
4
+ const expect_request_1 = require("../../actions/expect-request");
5
+ const expectRequestFixture = async ({ page, baseURL }, use) => {
6
+ if (!baseURL) {
7
+ throw new Error('Base URL required for requests matching!');
8
+ }
9
+ const requests = new Map();
10
+ page.on('request', (request) => {
11
+ const url = new URL(request.url());
12
+ const key = `${url.protocol}//${url.hostname}${url.pathname}`;
13
+ requests.set(key, request);
14
+ });
15
+ const boundExpectRequest = expect_request_1.expectRequest.bind(null, requests);
16
+ await use(boundExpectRequest);
17
+ requests.clear();
18
+ };
19
+ exports.expectRequestFixture = expectRequestFixture;
20
+ const fixtureOptions = {
21
+ scope: 'test',
22
+ };
23
+ exports.expectRequest = [
24
+ exports.expectRequestFixture,
25
+ fixtureOptions,
26
+ ];
@@ -0,0 +1,3 @@
1
+ export type { ExpectRequestFn, ExpectRequestTestArgs } from './types';
2
+ export type { ExpectRequestFnMatcher, ExpectRequestFnOptions } from '../../actions/expect-request';
3
+ export { expectRequest } from './expect-request-fixture';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expectRequest = void 0;
4
+ var expect_request_fixture_1 = require("./expect-request-fixture");
5
+ Object.defineProperty(exports, "expectRequest", { enumerable: true, get: function () { return expect_request_fixture_1.expectRequest; } });
@@ -0,0 +1,5 @@
1
+ import type { ExpectRequestFnMatcher, ExpectRequestFnOptions } from '../../actions/expect-request';
2
+ export type ExpectRequestFn = (url: string | RegExp, matcher?: ExpectRequestFnMatcher, options?: ExpectRequestFnOptions) => Promise<void>;
3
+ export interface ExpectRequestTestArgs {
4
+ expectRequest: ExpectRequestFn;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
2
+ import type { ExpectScreenshotFixtureBuilderParams, ExpectScreenshotFn } from './types';
3
+ export declare function expectScreenshotFixtureBuilder({ screenshotOptions, getDefaultMask, ...restDefaults }?: ExpectScreenshotFixtureBuilderParams): [TestFixture<ExpectScreenshotFn, PlaywrightTestArgs & PlaywrightTestOptions>, {
4
+ scope: "test";
5
+ }];
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expectScreenshotFixtureBuilder = expectScreenshotFixtureBuilder;
4
+ const matchScreenshot_1 = require("../../actions/matchScreenshot");
5
+ function expectScreenshotFixtureBuilder({ screenshotOptions, getDefaultMask, ...restDefaults } = {}) {
6
+ const expectScreenshotFixture = async ({ page }, use) => {
7
+ const expectScreenshot = ({ options = {}, shouldUseDefaultMask = true, ...restParams } = {}) => {
8
+ const { mask = [] } = options;
9
+ const defaultMask = shouldUseDefaultMask && getDefaultMask ? getDefaultMask(page) : [];
10
+ const maskToUse = [...mask, ...defaultMask];
11
+ const mergedOptions = {
12
+ options: { ...screenshotOptions, ...options, mask: maskToUse },
13
+ ...restDefaults,
14
+ ...restParams,
15
+ };
16
+ return (0, matchScreenshot_1.matchScreenshot)(page, mergedOptions);
17
+ };
18
+ await use(expectScreenshot);
19
+ };
20
+ const fixtureOptions = {
21
+ scope: 'test',
22
+ };
23
+ const expectScreenshot = [
24
+ expectScreenshotFixture,
25
+ fixtureOptions,
26
+ ];
27
+ return expectScreenshot;
28
+ }
@@ -0,0 +1,2 @@
1
+ export { expectScreenshotFixtureBuilder } from './expect-screenshot-fixture';
2
+ export type { ExpectScreenshotFixtureBuilderParams, ExpectScreenshotFn, ExpectScreenshotTestArgs, } from './types';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expectScreenshotFixtureBuilder = void 0;
4
+ var expect_screenshot_fixture_1 = require("./expect-screenshot-fixture");
5
+ Object.defineProperty(exports, "expectScreenshotFixtureBuilder", { enumerable: true, get: function () { return expect_screenshot_fixture_1.expectScreenshotFixtureBuilder; } });
@@ -0,0 +1,14 @@
1
+ import type { Locator, Page } from '@playwright/test';
2
+ import type { MatchScreenshotOptions, ScreenshotOptions } from '../../actions/matchScreenshot';
3
+ export type DefaultScreenshotOptions = Omit<ScreenshotOptions, 'mask'>;
4
+ export type ExpectScreenshotOptions = MatchScreenshotOptions & {
5
+ shouldUseDefaultMask?: boolean;
6
+ };
7
+ export type ExpectScreenshotFixtureBuilderParams = Pick<MatchScreenshotOptions, 'hideBySelector' | 'pause' | 'soft' | 'shouldPrependSlugToName' | 'themes' | 'onBeforeScreenshot' | 'onSwitchTheme'> & {
8
+ screenshotOptions?: DefaultScreenshotOptions;
9
+ getDefaultMask?: (page: Page) => Locator[];
10
+ };
11
+ export type ExpectScreenshotFn = (params?: ExpectScreenshotOptions) => Promise<void>;
12
+ export type ExpectScreenshotTestArgs = {
13
+ expectScreenshot: ExpectScreenshotFn;
14
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
2
+ import type { GlobalSettingsFixturesBuilderParams, GlobalSettingsTestArgs, GlobalSettingsWorkerArgs } from './types';
3
+ export declare function globalSettingsFixturesBuilder({ globalSettings }?: GlobalSettingsFixturesBuilderParams): Fixtures<GlobalSettingsTestArgs, GlobalSettingsWorkerArgs, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.globalSettingsFixturesBuilder = globalSettingsFixturesBuilder;
4
+ const actions_1 = require("../../actions");
5
+ function globalSettingsFixturesBuilder({ globalSettings } = { globalSettings: {} }) {
6
+ const initGlobalSettingsFixture = async ({}, use) => {
7
+ (0, actions_1.setGlobalSettings)(globalSettings);
8
+ await use();
9
+ };
10
+ const setGlobalSettingsFixture = async ({}, use) => {
11
+ await use(actions_1.setGlobalSettings);
12
+ };
13
+ const getGlobalSettingsFixture = async ({}, use) => {
14
+ await use(actions_1.getGlobalSettings);
15
+ };
16
+ const fixtures = {
17
+ initGlobalSettings: [initGlobalSettingsFixture, { scope: 'worker', auto: true }],
18
+ setGlobalSettings: [setGlobalSettingsFixture, { scope: 'test' }],
19
+ getGlobalSettings: [getGlobalSettingsFixture, { scope: 'test' }],
20
+ };
21
+ return fixtures;
22
+ }
@@ -0,0 +1,2 @@
1
+ export type { GlobalSettingsFixturesBuilderParams, GlobalSettingsTestArgs, GlobalSettingsWorkerArgs, } from './types';
2
+ export { globalSettingsFixturesBuilder } from './global-settings-fixture';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.globalSettingsFixturesBuilder = void 0;
4
+ var global_settings_fixture_1 = require("./global-settings-fixture");
5
+ Object.defineProperty(exports, "globalSettingsFixturesBuilder", { enumerable: true, get: function () { return global_settings_fixture_1.globalSettingsFixturesBuilder; } });
@@ -0,0 +1,15 @@
1
+ import type { getGlobalSettings, setGlobalSettings } from '../../actions';
2
+ import type { PartialGlobalSettings } from '../../data/globalSettings';
3
+ export type GlobalSettingsFixturesBuilderParams = {
4
+ /**
5
+ * Global settings that need to be overridden
6
+ */
7
+ globalSettings: PartialGlobalSettings;
8
+ };
9
+ export type GlobalSettingsWorkerArgs = {
10
+ initGlobalSettings: void;
11
+ };
12
+ export type GlobalSettingsTestArgs = {
13
+ setGlobalSettings: typeof setGlobalSettings;
14
+ getGlobalSettings: typeof getGlobalSettings;
15
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ export type { TestSlugResult } from './testSlug';
2
+ export { testSlug } from './testSlug';
3
+ export type { MockNetworkFixtureBuilderParams } from './mock-network';
4
+ export { mockNetworkFixtureBuilder } from './mock-network';
5
+ export type { ExpectRequestFn, ExpectRequestTestArgs, ExpectRequestFnMatcher, ExpectRequestFnOptions, } from './expect-request';
6
+ export { expectRequest } from './expect-request';
7
+ export type { ExpectScreenshotFn, ExpectScreenshotTestArgs, ExpectScreenshotFixtureBuilderParams, } from './expect-screenshot';
8
+ export { expectScreenshotFixtureBuilder } from './expect-screenshot';
9
+ export type { GlobalSettingsFixturesBuilderParams, GlobalSettingsTestArgs, GlobalSettingsWorkerArgs, } from './global-settings';
10
+ export { globalSettingsFixturesBuilder } from './global-settings';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.globalSettingsFixturesBuilder = exports.expectScreenshotFixtureBuilder = exports.expectRequest = exports.mockNetworkFixtureBuilder = exports.testSlug = void 0;
4
+ var testSlug_1 = require("./testSlug");
5
+ Object.defineProperty(exports, "testSlug", { enumerable: true, get: function () { return testSlug_1.testSlug; } });
6
+ var mock_network_1 = require("./mock-network");
7
+ Object.defineProperty(exports, "mockNetworkFixtureBuilder", { enumerable: true, get: function () { return mock_network_1.mockNetworkFixtureBuilder; } });
8
+ var expect_request_1 = require("./expect-request");
9
+ Object.defineProperty(exports, "expectRequest", { enumerable: true, get: function () { return expect_request_1.expectRequest; } });
10
+ var expect_screenshot_1 = require("./expect-screenshot");
11
+ Object.defineProperty(exports, "expectScreenshotFixtureBuilder", { enumerable: true, get: function () { return expect_screenshot_1.expectScreenshotFixtureBuilder; } });
12
+ var global_settings_1 = require("./global-settings");
13
+ Object.defineProperty(exports, "globalSettingsFixturesBuilder", { enumerable: true, get: function () { return global_settings_1.globalSettingsFixturesBuilder; } });
@@ -0,0 +1,8 @@
1
+ import type { MockNetworkFixtureBuilderParams } from './types';
2
+ export type HarPatcherParams = Pick<MockNetworkFixtureBuilderParams, 'headersToRemove' | 'setCookieToRemove' | 'onHarEntryWillRead' | 'onHarEntryWillWrite' | 'onTransformHarLookupParams' | 'onTransformHarLookupResult'> & {
3
+ /**
4
+ * Base url of the test
5
+ */
6
+ baseURL: string;
7
+ };
8
+ export declare function harPatcher({ baseURL, headersToRemove: additionalHeadersToRemove, setCookieToRemove: additionalSetCookieToRemove, onHarEntryWillWrite, onHarEntryWillRead, onTransformHarLookupParams, onTransformHarLookupResult, }: HarPatcherParams): void;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.harPatcher = harPatcher;
4
+ const har_1 = require("../../har");
5
+ const DEFAULT_REMOVE_HEADERS = new Set([
6
+ 'cookie',
7
+ 'x-csrf-token',
8
+ 'content-security-policy',
9
+ 'Session_id',
10
+ ]);
11
+ const DEFAULT_REMOVE_SET_COOKIE_FOR = new Set(['CSRF-TOKEN']);
12
+ const baseUrlPLaceholder = 'https://base.url.placeholder';
13
+ function harPatcher({ baseURL, headersToRemove: additionalHeadersToRemove = [], setCookieToRemove: additionalSetCookieToRemove = [], onHarEntryWillWrite, onHarEntryWillRead, onTransformHarLookupParams, onTransformHarLookupResult, }) {
14
+ const headersToRemove = new Set([...DEFAULT_REMOVE_HEADERS, ...additionalHeadersToRemove]);
15
+ const setCookieToRemove = new Set([
16
+ ...DEFAULT_REMOVE_SET_COOKIE_FOR,
17
+ ...additionalSetCookieToRemove,
18
+ ]);
19
+ (0, har_1.addHarRecorderTransform)((entry) => {
20
+ // eslint-disable-next-line no-param-reassign
21
+ entry.request.headers = (0, har_1.clearHeaders)(entry.request.headers, {
22
+ removeHeaders: headersToRemove,
23
+ });
24
+ // eslint-disable-next-line no-param-reassign
25
+ entry.response.headers = (0, har_1.clearHeaders)(entry.response.headers, {
26
+ removeHeaders: headersToRemove,
27
+ removeSetCookieFor: setCookieToRemove,
28
+ });
29
+ (0, har_1.replaceBaseUrlInEntry)(entry, baseURL, baseUrlPLaceholder);
30
+ onHarEntryWillWrite?.(entry);
31
+ });
32
+ (0, har_1.addHarOpenTransform)((harFile) => {
33
+ const entries = harFile.log.entries;
34
+ for (const entry of entries) {
35
+ (0, har_1.replaceBaseUrlInEntry)(entry, baseUrlPLaceholder, baseURL);
36
+ onHarEntryWillRead?.(entry);
37
+ }
38
+ });
39
+ (0, har_1.addHarLookupTransform)(onTransformHarLookupParams, onTransformHarLookupResult);
40
+ }
@@ -0,0 +1,2 @@
1
+ export { mockNetworkFixtureBuilder } from './mock-network-fixture';
2
+ export type { MockNetworkFixtureBuilderParams } from './types';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockNetworkFixtureBuilder = void 0;
4
+ var mock_network_fixture_1 = require("./mock-network-fixture");
5
+ Object.defineProperty(exports, "mockNetworkFixtureBuilder", { enumerable: true, get: function () { return mock_network_fixture_1.mockNetworkFixtureBuilder; } });
@@ -0,0 +1,6 @@
1
+ import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
2
+ import type { MockNetworkFixtureBuilderParams } from './types';
3
+ export declare function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip, url: urlMatcherBuilder, dumpsPath, dumpsFilePath, ...harPatcherParams }: MockNetworkFixtureBuilderParams): [TestFixture<boolean, PlaywrightTestArgs & PlaywrightTestOptions>, {
4
+ auto: boolean;
5
+ scope: "test";
6
+ }];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockNetworkFixtureBuilder = mockNetworkFixtureBuilder;
4
+ const har_1 = require("../../har");
5
+ const har_patcher_1 = require("./har-patcher");
6
+ function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url: urlMatcherBuilder, dumpsPath, dumpsFilePath, ...harPatcherParams }) {
7
+ const mockNetworkFixture = async ({ baseURL: rawBaseURL, page }, use, testInfo) => {
8
+ if (!rawBaseURL) {
9
+ throw new Error('baseURL should be specified in playwright config');
10
+ }
11
+ const baseURL = rawBaseURL.replace(/\/+$/, '');
12
+ (0, har_patcher_1.harPatcher)({
13
+ baseURL,
14
+ ...harPatcherParams,
15
+ });
16
+ const update = Boolean(shouldUpdate);
17
+ const url = urlMatcherBuilder(baseURL);
18
+ await (0, har_1.initDumps)(page, testInfo, {
19
+ dumpsPath,
20
+ dumpsFilePath,
21
+ forceUpdateIfHarMissing,
22
+ updateTimeout,
23
+ update,
24
+ url,
25
+ zip,
26
+ });
27
+ await use(!update);
28
+ };
29
+ const fixtureOptions = {
30
+ auto: true,
31
+ scope: 'test',
32
+ };
33
+ const mockNetwork = [
34
+ mockNetworkFixture,
35
+ fixtureOptions,
36
+ ];
37
+ return mockNetwork;
38
+ }