@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
package/har/types.d.ts ADDED
@@ -0,0 +1,175 @@
1
+ export type HARFile = {
2
+ log: Log;
3
+ };
4
+ export type Log = {
5
+ version: string;
6
+ creator: Creator;
7
+ browser?: Browser;
8
+ pages?: Page[];
9
+ entries: Entry[];
10
+ comment?: string;
11
+ };
12
+ export type Creator = {
13
+ name: string;
14
+ version: string;
15
+ comment?: string;
16
+ };
17
+ export type Browser = {
18
+ name: string;
19
+ version: string;
20
+ comment?: string;
21
+ };
22
+ export type Page = {
23
+ startedDateTime: Date;
24
+ id: string;
25
+ title: string;
26
+ pageTimings: PageTimings;
27
+ comment?: string;
28
+ };
29
+ export type PageTimings = {
30
+ onContentLoad?: number;
31
+ onLoad?: number;
32
+ comment?: string;
33
+ };
34
+ export type Entry = {
35
+ pageref?: string;
36
+ startedDateTime: Date;
37
+ time: number;
38
+ request: Request;
39
+ response: Response;
40
+ cache: Cache;
41
+ timings: Timings;
42
+ serverIPAddress?: string;
43
+ connection?: string;
44
+ _frameref?: string;
45
+ _monotonicTime?: number;
46
+ _serverPort?: number;
47
+ _securityDetails?: SecurityDetails;
48
+ };
49
+ export type Request = {
50
+ method: string;
51
+ url: string;
52
+ httpVersion: string;
53
+ cookies: Cookie[];
54
+ headers: Header[];
55
+ queryString: QueryParameter[];
56
+ postData?: PostData;
57
+ headersSize: number;
58
+ bodySize: number;
59
+ comment?: string;
60
+ };
61
+ export type Response = {
62
+ status: number;
63
+ statusText: string;
64
+ httpVersion: string;
65
+ cookies: Cookie[];
66
+ headers: Header[];
67
+ content: Content;
68
+ redirectURL: string;
69
+ headersSize: number;
70
+ bodySize: number;
71
+ comment?: string;
72
+ _transferSize?: number;
73
+ _failureText?: string;
74
+ };
75
+ export type Cookie = {
76
+ name: string;
77
+ value: string;
78
+ path?: string;
79
+ domain?: string;
80
+ expires?: Date;
81
+ httpOnly?: boolean;
82
+ secure?: boolean;
83
+ sameSite?: string;
84
+ comment?: string;
85
+ };
86
+ export type Header = {
87
+ name: string;
88
+ value: string;
89
+ comment?: string;
90
+ };
91
+ export type QueryParameter = {
92
+ name: string;
93
+ value: string;
94
+ comment?: string;
95
+ };
96
+ export type PostData = {
97
+ mimeType: string;
98
+ params: Param[];
99
+ text: string;
100
+ comment?: string;
101
+ _sha1?: string;
102
+ _file?: string;
103
+ };
104
+ export type Param = {
105
+ name: string;
106
+ value?: string;
107
+ fileName?: string;
108
+ contentType?: string;
109
+ comment?: string;
110
+ };
111
+ export type Content = {
112
+ size: number;
113
+ compression?: number;
114
+ mimeType: string;
115
+ text?: string;
116
+ encoding?: string;
117
+ comment?: string;
118
+ _sha1?: string;
119
+ _file?: string;
120
+ };
121
+ export type Cache = {
122
+ beforeRequest?: CacheState | null;
123
+ afterRequest?: CacheState | null;
124
+ comment?: string;
125
+ };
126
+ export type CacheState = {
127
+ expires?: string;
128
+ lastAccess: string;
129
+ eTag: string;
130
+ hitCount: number;
131
+ comment?: string;
132
+ };
133
+ export type Timings = {
134
+ blocked?: number;
135
+ dns?: number;
136
+ connect?: number;
137
+ send: number;
138
+ wait: number;
139
+ receive: number;
140
+ ssl?: number;
141
+ comment?: string;
142
+ };
143
+ export type SecurityDetails = {
144
+ protocol?: string;
145
+ subjectName?: string;
146
+ issuer?: string;
147
+ validFrom?: number;
148
+ validTo?: number;
149
+ };
150
+ export type Metadata = {
151
+ location?: {
152
+ file: string;
153
+ line?: number;
154
+ column?: number;
155
+ };
156
+ apiName?: string;
157
+ internal?: boolean;
158
+ wallTime?: number;
159
+ };
160
+ export type LocalUtilsHarLookupParams = {
161
+ harId: string;
162
+ url: string;
163
+ method: string;
164
+ headers: Header[];
165
+ postData?: Buffer;
166
+ isNavigationRequest: boolean;
167
+ };
168
+ export type LocalUtilsHarLookupResult = {
169
+ action: 'error' | 'redirect' | 'fulfill' | 'noentry';
170
+ message?: string;
171
+ redirectURL?: string;
172
+ status?: number;
173
+ headers?: Header[];
174
+ body?: Buffer;
175
+ };
package/har/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // End of channels types
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@gravity-ui/playwright-tools",
3
+ "version": "0.4.1",
4
+ "description": "Tools for Playwright Test",
5
+ "keywords": [
6
+ "playwright",
7
+ "e2e",
8
+ "test",
9
+ "tests",
10
+ "integration"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/gravity-ui/playwright-tools"
15
+ },
16
+ "license": "MIT",
17
+ "author": "@Avol-V",
18
+ "files": [
19
+ "/actions/**/*.*(js|d.ts)",
20
+ "/auth/**/*.*(js|d.ts)",
21
+ "/config/**/*.*(js|d.ts)",
22
+ "/data/**/*.*(js|d.ts)",
23
+ "/fixtures/**/*.*(js|d.ts)",
24
+ "/har/**/*.*(js|d.ts)",
25
+ "/utils/**/*.*(js|d.ts)",
26
+ "!/**/__tests__"
27
+ ],
28
+ "exports": [
29
+ "./actions/**/*.*(js|d.ts)",
30
+ "./auth/**/*.*(js|d.ts)",
31
+ "./config/**/*.*(js|d.ts)",
32
+ "./data/**/*.*(js|d.ts)",
33
+ "./fixtures/**/*.*(js|d.ts)",
34
+ "./har/**/*.*(js|d.ts)",
35
+ "./utils/**/*.*(js|d.ts)"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "clean": "find actions auth config data fixtures har utils -type f ! -name '.eslintrc.js' \\( -name '*.js' -o -name '*.d.ts' \\) -delete",
40
+ "typecheck": "tsc --noEmit",
41
+ "lint": "eslint --ext .ts ./",
42
+ "test": "jest --colors --config=jest.config.js",
43
+ "prepublishOnly": "npm run clean && npm run lint && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "escape-string-regexp": "^4.0.0",
47
+ "minimatch": "^10.0.1",
48
+ "otplib": "^12.0.1",
49
+ "timekeeper": "^2.3.1"
50
+ },
51
+ "devDependencies": {
52
+ "@commitlint/cli": "^19.6.1",
53
+ "@commitlint/config-conventional": "^19.6.0",
54
+ "@gravity-ui/eslint-config": "^3.3.0",
55
+ "@gravity-ui/prettier-config": "^1.1.0",
56
+ "@jest/globals": "^29.7.0",
57
+ "@playwright/test": "^1.49.0",
58
+ "@swc/core": "^1.11.5",
59
+ "@swc/jest": "^0.2.37",
60
+ "@types/jest": "^29.5.14",
61
+ "@types/node": "^20.17.9",
62
+ "eslint": "^8.57.1",
63
+ "jest": "^29.7.0",
64
+ "prettier": "^3.4.2",
65
+ "ts-jest": "^29.3.1",
66
+ "typescript": "^5.7.2"
67
+ },
68
+ "peerDependencies": {
69
+ "@playwright/test": "^1.22"
70
+ },
71
+ "engines": {
72
+ "node": ">=20"
73
+ }
74
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Unreachable statement Error
3
+ */
4
+ export declare class NeverError extends Error {
5
+ constructor(value: never);
6
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NeverError = void 0;
4
+ /**
5
+ * Unreachable statement Error
6
+ */
7
+ class NeverError extends Error {
8
+ constructor(value) {
9
+ super(`Unreachable statement: ${value}`);
10
+ }
11
+ }
12
+ exports.NeverError = NeverError;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Remove file from cache
3
+ *
4
+ * @param path cache path
5
+ * @param name cache name (without extension)
6
+ */
7
+ export declare function deleteCache(path: string, name: string): Promise<void>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteCache = deleteCache;
4
+ const promises_1 = require("fs/promises");
5
+ const path_1 = require("path");
6
+ /**
7
+ * Remove file from cache
8
+ *
9
+ * @param path cache path
10
+ * @param name cache name (without extension)
11
+ */
12
+ function deleteCache(path, name) {
13
+ const fullPath = (0, path_1.resolve)(path, name + '.json');
14
+ return (0, promises_1.unlink)(fullPath).catch(() => { });
15
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Retrieves a test ID for use in the test artifact path.
3
+ *
4
+ * It is assumed that the identifier is written at the end of the test name in square brackets:
5
+ * `'My test title [my-test]'`
6
+ * Otherwise, it is formed from the name, excluding all special characters, for example:
7
+ * `'My test title 1 @test @tag'` -> `'my-test-title-1-test-tag'`
8
+ *
9
+ * @param title test name
10
+ * @param allowToUseTitle Requires the slug to be specified in a specific way in the title (otherwise the title itself will be used)
11
+ */
12
+ export declare function extractTestSlug(title: string, allowToUseTitle?: boolean): string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractTestSlug = extractTestSlug;
4
+ /**
5
+ * Retrieves a test ID for use in the test artifact path.
6
+ *
7
+ * It is assumed that the identifier is written at the end of the test name in square brackets:
8
+ * `'My test title [my-test]'`
9
+ * Otherwise, it is formed from the name, excluding all special characters, for example:
10
+ * `'My test title 1 @test @tag'` -> `'my-test-title-1-test-tag'`
11
+ *
12
+ * @param title test name
13
+ * @param allowToUseTitle Requires the slug to be specified in a specific way in the title (otherwise the title itself will be used)
14
+ */
15
+ function extractTestSlug(title, allowToUseTitle = true) {
16
+ const matches = /\[([^[\]]+)\]$/.exec(title);
17
+ if (matches) {
18
+ return matches[1];
19
+ }
20
+ if (allowToUseTitle) {
21
+ return title.match(/\w+/g)?.join('-').toLocaleLowerCase() || '';
22
+ }
23
+ return '';
24
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Native fetch with certificate verification disabled
3
+ */
4
+ export declare const fetchWithoutRejectUnauthorized: typeof fetch;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchWithoutRejectUnauthorized = void 0;
4
+ const unidiciGlobalDispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
5
+ let dispatcherWithoutRejectUnauthorized;
6
+ /**
7
+ * Native fetch with certificate verification disabled
8
+ */
9
+ const fetchWithoutRejectUnauthorized = async (input, init) => {
10
+ if (!dispatcherWithoutRejectUnauthorized) {
11
+ // Initialize fetch globals
12
+ await fetch('data:text/plain,');
13
+ // Getting the dispatcher from global is considered a public API
14
+ // https://github.com/nodejs/undici/discussions/2167#discussioncomment-6265039
15
+ const undiciGlobalDispatcher = global[unidiciGlobalDispatcherSymbol];
16
+ dispatcherWithoutRejectUnauthorized = new undiciGlobalDispatcher.constructor({
17
+ connect: {
18
+ rejectUnauthorized: false,
19
+ },
20
+ });
21
+ }
22
+ const fetchOptions = {
23
+ dispatcher: dispatcherWithoutRejectUnauthorized,
24
+ ...init,
25
+ };
26
+ return fetch(input, fetchOptions);
27
+ };
28
+ exports.fetchWithoutRejectUnauthorized = fetchWithoutRejectUnauthorized;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns the domain for cookies based on the baseURL from the config
3
+ */
4
+ export declare function getCookieDomain(baseURL: string): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCookieDomain = getCookieDomain;
4
+ const url_1 = require("url");
5
+ /**
6
+ * Returns the domain for cookies based on the baseURL from the config
7
+ */
8
+ function getCookieDomain(baseURL) {
9
+ const parsedBaseUrl = new url_1.URL(baseURL);
10
+ const baseHost = parsedBaseUrl.hostname.replace(/:\d+$/, '');
11
+ const domain = '.' + baseHost.split('.').slice(-2).join('.');
12
+ return domain;
13
+ }
@@ -0,0 +1,9 @@
1
+ export { deleteCache } from './deleteCache';
2
+ export { extractTestSlug } from './extractTestSlug';
3
+ export { fetchWithoutRejectUnauthorized } from './fetchWithoutRejectUnauthorized';
4
+ export { getCookieDomain } from './getCookieDomain';
5
+ export { NeverError } from './NeverError';
6
+ export { readCache } from './readCache';
7
+ export { waitForResolve } from './waitForResolve';
8
+ export { waitHttpService } from './waitHttpService';
9
+ export { writeCache } from './writeCache';
package/utils/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeCache = exports.waitHttpService = exports.waitForResolve = exports.readCache = exports.NeverError = exports.getCookieDomain = exports.fetchWithoutRejectUnauthorized = exports.extractTestSlug = exports.deleteCache = void 0;
4
+ var deleteCache_1 = require("./deleteCache");
5
+ Object.defineProperty(exports, "deleteCache", { enumerable: true, get: function () { return deleteCache_1.deleteCache; } });
6
+ var extractTestSlug_1 = require("./extractTestSlug");
7
+ Object.defineProperty(exports, "extractTestSlug", { enumerable: true, get: function () { return extractTestSlug_1.extractTestSlug; } });
8
+ var fetchWithoutRejectUnauthorized_1 = require("./fetchWithoutRejectUnauthorized");
9
+ Object.defineProperty(exports, "fetchWithoutRejectUnauthorized", { enumerable: true, get: function () { return fetchWithoutRejectUnauthorized_1.fetchWithoutRejectUnauthorized; } });
10
+ var getCookieDomain_1 = require("./getCookieDomain");
11
+ Object.defineProperty(exports, "getCookieDomain", { enumerable: true, get: function () { return getCookieDomain_1.getCookieDomain; } });
12
+ var NeverError_1 = require("./NeverError");
13
+ Object.defineProperty(exports, "NeverError", { enumerable: true, get: function () { return NeverError_1.NeverError; } });
14
+ var readCache_1 = require("./readCache");
15
+ Object.defineProperty(exports, "readCache", { enumerable: true, get: function () { return readCache_1.readCache; } });
16
+ var waitForResolve_1 = require("./waitForResolve");
17
+ Object.defineProperty(exports, "waitForResolve", { enumerable: true, get: function () { return waitForResolve_1.waitForResolve; } });
18
+ var waitHttpService_1 = require("./waitHttpService");
19
+ Object.defineProperty(exports, "waitHttpService", { enumerable: true, get: function () { return waitHttpService_1.waitHttpService; } });
20
+ var writeCache_1 = require("./writeCache");
21
+ Object.defineProperty(exports, "writeCache", { enumerable: true, get: function () { return writeCache_1.writeCache; } });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the contents of the cache file
3
+ *
4
+ * @param path Path to the directory with cache
5
+ * @param name cache name (without extension)
6
+ * @param ttl Cache Lifetime (ms)
7
+ */
8
+ export declare function readCache<TData = unknown>(path: string, name: string, ttl: number): Promise<TData | undefined>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readCache = readCache;
4
+ const promises_1 = require("fs/promises");
5
+ const path_1 = require("path");
6
+ const checkedPaths = new Set();
7
+ /**
8
+ * Returns the contents of the cache file
9
+ *
10
+ * @param path Path to the directory with cache
11
+ * @param name cache name (without extension)
12
+ * @param ttl Cache Lifetime (ms)
13
+ */
14
+ async function readCache(path, name, ttl) {
15
+ const fullPath = (0, path_1.resolve)(path, name + '.json');
16
+ if (checkedPaths.has(fullPath)) {
17
+ return undefined;
18
+ }
19
+ checkedPaths.add(fullPath);
20
+ try {
21
+ const { mtimeMs } = await (0, promises_1.stat)(fullPath);
22
+ if (mtimeMs + ttl < Date.now()) {
23
+ return undefined;
24
+ }
25
+ const json = await (0, promises_1.readFile)(fullPath, 'utf8');
26
+ const data = JSON.parse(json);
27
+ return data;
28
+ }
29
+ catch {
30
+ return undefined;
31
+ }
32
+ }
@@ -0,0 +1,24 @@
1
+ export type WaitForResolveOptions = {
2
+ /**
3
+ * Interval between checks (ms)
4
+ * @defaultValue `100`
5
+ */
6
+ interval?: number;
7
+ /**
8
+ * Timeout after which checks are aborted (ms)
9
+ * `0` — without limitation
10
+ * @defaultValue `5000`
11
+ */
12
+ timeout?: number;
13
+ };
14
+ /**
15
+ * Waits for the check function to return `true`
16
+ *
17
+ * The checking function is launched at a given interval and its value is checked.
18
+ * If it returned `true`, then it succeeds, otherwise we wait further.
19
+ * If there is a timeout or an error in the checking function, it fails.
20
+ *
21
+ * @param solver resolving function
22
+ * @param options Options
23
+ */
24
+ export declare function waitForResolve(solver: () => boolean | PromiseLike<boolean>, { interval, timeout, }?: WaitForResolveOptions): Promise<void>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForResolve = waitForResolve;
4
+ const globalSettings_1 = require("../data/globalSettings");
5
+ /**
6
+ * Waits for the check function to return `true`
7
+ *
8
+ * The checking function is launched at a given interval and its value is checked.
9
+ * If it returned `true`, then it succeeds, otherwise we wait further.
10
+ * If there is a timeout or an error in the checking function, it fails.
11
+ *
12
+ * @param solver resolving function
13
+ * @param options Options
14
+ */
15
+ function waitForResolve(solver, { interval = globalSettings_1.globalSettings.waitForResolve.interval, timeout = globalSettings_1.globalSettings.waitForResolve.timeout, } = {}) {
16
+ const until = timeout === 0 ? 0 : Date.now() + timeout;
17
+ let resolveResult;
18
+ let rejectResult;
19
+ const resultPromise = new Promise((resolve, reject) => {
20
+ resolveResult = resolve;
21
+ rejectResult = reject;
22
+ });
23
+ const timer = setInterval(async () => {
24
+ try {
25
+ if (await solver()) {
26
+ clearInterval(timer);
27
+ resolveResult();
28
+ return;
29
+ }
30
+ if (until && Date.now() > until) {
31
+ clearInterval(timer);
32
+ rejectResult(new Error('waitForResolve timeout'));
33
+ }
34
+ }
35
+ catch (error) {
36
+ rejectResult(error);
37
+ }
38
+ }, interval);
39
+ return resultPromise;
40
+ }
@@ -0,0 +1,28 @@
1
+ export type WaitHttpServiceOptions = {
2
+ /** URL to check */
3
+ url: string;
4
+ /**
5
+ * Request Method
6
+ * @default 'HEAD'
7
+ */
8
+ method?: string;
9
+ /**
10
+ * Expected response status
11
+ * @default 200
12
+ */
13
+ expectedStatus?: number;
14
+ /**
15
+ * Interval between requests
16
+ * @default 1000
17
+ */
18
+ interval?: number;
19
+ /**
20
+ * Waiting time
21
+ * @default Infinity
22
+ */
23
+ timeout?: number;
24
+ };
25
+ /**
26
+ * Waits for a response with the required status at the given URL
27
+ */
28
+ export declare function waitHttpService({ url, method, expectedStatus, interval, timeout, }: WaitHttpServiceOptions): Promise<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitHttpService = waitHttpService;
4
+ const promises_1 = require("node:timers/promises");
5
+ const fetchWithoutRejectUnauthorized_1 = require("./fetchWithoutRejectUnauthorized");
6
+ /**
7
+ * Waits for a response with the required status at the given URL
8
+ */
9
+ async function waitHttpService({ url, method = 'HEAD', expectedStatus = 200, interval = 1000, timeout = Infinity, }) {
10
+ const until = Date.now() + timeout;
11
+ let success = false;
12
+ do {
13
+ const response = await (0, fetchWithoutRejectUnauthorized_1.fetchWithoutRejectUnauthorized)(url, {
14
+ method,
15
+ }).catch(() => null);
16
+ if (response?.status === expectedStatus) {
17
+ success = true;
18
+ return;
19
+ }
20
+ await (0, promises_1.setTimeout)(interval);
21
+ if (Date.now() > until) {
22
+ throw new Error('Timed out waiting for ' + url);
23
+ }
24
+ } while (!success);
25
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Writes data to the cache file
3
+ *
4
+ * @param path Path to the directory with cache
5
+ * @param name Cache name (without extension)
6
+ * @param data Data to write to cache
7
+ */
8
+ export declare function writeCache(path: string, name: string, data: unknown): Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeCache = writeCache;
4
+ const promises_1 = require("fs/promises");
5
+ const path_1 = require("path");
6
+ /**
7
+ * Writes data to the cache file
8
+ *
9
+ * @param path Path to the directory with cache
10
+ * @param name Cache name (without extension)
11
+ * @param data Data to write to cache
12
+ */
13
+ async function writeCache(path, name, data) {
14
+ const fullPath = (0, path_1.resolve)(path, name + '.json');
15
+ const json = JSON.stringify(data);
16
+ await (0, promises_1.mkdir)(path, { recursive: true }).catch(() => { });
17
+ await (0, promises_1.writeFile)(fullPath, json, 'utf8');
18
+ }