@testim/testim-cli 3.288.0 → 3.290.0-beta

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 (217) hide show
  1. package/cli.js +22390 -122
  2. package/cli.js.map +1 -0
  3. package/npm-shrinkwrap.json +8 -29129
  4. package/package.json +16 -10
  5. package/OverrideTestDataBuilder.js +0 -117
  6. package/agent/routers/cliJsCode/index.js +0 -13
  7. package/agent/routers/cliJsCode/router.js +0 -63
  8. package/agent/routers/cliJsCode/service.js +0 -705
  9. package/agent/routers/codim/router.js +0 -69
  10. package/agent/routers/codim/router.test.js +0 -60
  11. package/agent/routers/codim/service.js +0 -193
  12. package/agent/routers/general/index.js +0 -36
  13. package/agent/routers/hybrid/registerRoutes.js +0 -81
  14. package/agent/routers/index.js +0 -56
  15. package/agent/routers/playground/router.js +0 -77
  16. package/agent/routers/playground/service.js +0 -96
  17. package/agent/routers/standalone-browser/registerRoutes.js +0 -47
  18. package/agent/server.js +0 -150
  19. package/cdpTestRunner.js +0 -86
  20. package/chromiumInstaller.js +0 -91
  21. package/cli/isCiRun.js +0 -10
  22. package/cli/onExit.js +0 -65
  23. package/cli/writeStackTrace.js +0 -27
  24. package/cliAgentMode.js +0 -384
  25. package/codim/codim-cli.js +0 -91
  26. package/codim/codim-npm-package/index.ts +0 -427
  27. package/codim/codim-npm-package/package-lock.json +0 -14
  28. package/codim/codim-npm-package/package.json +0 -14
  29. package/codim/hybrid-utils.js +0 -28
  30. package/codim/measure-perf.js +0 -41
  31. package/codim/template.js/.idea/workspace.xml +0 -57
  32. package/codim/template.js/.vscode/launch.json +0 -53
  33. package/codim/template.ts/.idea/workspace.xml +0 -57
  34. package/codim/template.ts/.vscode/launch.json +0 -55
  35. package/commons/AbortError.js +0 -12
  36. package/commons/SeleniumPerfStats.js +0 -58
  37. package/commons/chrome-launcher.js +0 -15
  38. package/commons/chromedriverWrapper.js +0 -70
  39. package/commons/config.js +0 -39
  40. package/commons/constants.js +0 -67
  41. package/commons/detectDebugger.js +0 -19
  42. package/commons/featureAvailabilityService.js +0 -26
  43. package/commons/featureFlags.js +0 -132
  44. package/commons/getSessionPlayerRequire.js +0 -28
  45. package/commons/httpRequest.js +0 -261
  46. package/commons/httpRequestCounters.js +0 -98
  47. package/commons/httpRequestCounters.test.js +0 -38
  48. package/commons/initializeUserWithAuth.js +0 -55
  49. package/commons/lazyRequire.js +0 -105
  50. package/commons/logUtils.js +0 -15
  51. package/commons/logUtils.test.js +0 -21
  52. package/commons/logger.js +0 -178
  53. package/commons/mockNetworkRuleFileSchema.json +0 -140
  54. package/commons/npmWrapper.js +0 -174
  55. package/commons/npmWrapper.test.js +0 -374
  56. package/commons/performance-logger.js +0 -71
  57. package/commons/preloadTests.js +0 -29
  58. package/commons/prepareRunner.js +0 -85
  59. package/commons/prepareRunner.test.js +0 -144
  60. package/commons/prepareRunnerAndTestimStartUtils.js +0 -198
  61. package/commons/prepareRunnerAndTestimStartUtils.test.js +0 -73
  62. package/commons/requireWithFallback.js +0 -25
  63. package/commons/runnerFileCache.js +0 -204
  64. package/commons/socket/baseSocketServiceSocketIO.js +0 -197
  65. package/commons/socket/realDataService.js +0 -59
  66. package/commons/socket/realDataServiceSocketIO.js +0 -33
  67. package/commons/socket/remoteStepService.js +0 -55
  68. package/commons/socket/remoteStepServiceSocketIO.js +0 -61
  69. package/commons/socket/socketService.js +0 -175
  70. package/commons/socket/testResultService.js +0 -62
  71. package/commons/socket/testResultServiceSocketIO.js +0 -64
  72. package/commons/testimAnalytics.js +0 -40
  73. package/commons/testimCloudflare.js +0 -83
  74. package/commons/testimCloudflare.test.js +0 -185
  75. package/commons/testimCustomToken.js +0 -124
  76. package/commons/testimDesiredCapabilitiesBuilder.js +0 -647
  77. package/commons/testimNgrok.js +0 -90
  78. package/commons/testimNgrok.test.js +0 -140
  79. package/commons/testimServicesApi.js +0 -631
  80. package/commons/testimTunnel.js +0 -73
  81. package/commons/testimTunnel.test.js +0 -172
  82. package/commons/xhr2.js +0 -897
  83. package/coverage/SummaryToObjectReport.js +0 -19
  84. package/coverage/jsCoverage.js +0 -252
  85. package/credentialsManager.js +0 -142
  86. package/errors.js +0 -161
  87. package/executionQueue.js +0 -37
  88. package/fixLocalBuild.js +0 -24
  89. package/inputFileUtils.js +0 -103
  90. package/lib/coralogix-winston.transport.js +0 -99
  91. package/player/SeleniumProtocolError.js +0 -100
  92. package/player/WebDriverHttpRequest.js +0 -177
  93. package/player/WebdriverioWebDriverApi.js +0 -671
  94. package/player/appiumTestPlayer.js +0 -90
  95. package/player/chromeLauncherTestPlayer.js +0 -67
  96. package/player/constants.js +0 -332
  97. package/player/extensionTestPlayer.js +0 -32
  98. package/player/findElementStrategy.js +0 -154
  99. package/player/scripts/isElementDisplayed.js +0 -252
  100. package/player/seleniumTestPlayer.js +0 -140
  101. package/player/services/frameLocator.js +0 -170
  102. package/player/services/mobileFrameLocatorMock.js +0 -32
  103. package/player/services/playbackTimeoutCalculator.js +0 -175
  104. package/player/services/portSelector.js +0 -19
  105. package/player/services/tabService.js +0 -551
  106. package/player/services/tabServiceMock.js +0 -167
  107. package/player/services/windowCreationListener.js +0 -8
  108. package/player/stepActions/RefreshStepAction.js +0 -16
  109. package/player/stepActions/apiStepAction.js +0 -89
  110. package/player/stepActions/baseCliJsStepAction.js +0 -51
  111. package/player/stepActions/baseJsStepAction.js +0 -277
  112. package/player/stepActions/cliConditionStepAction.js +0 -11
  113. package/player/stepActions/cliJsStepAction.js +0 -11
  114. package/player/stepActions/dropFileStepAction.js +0 -34
  115. package/player/stepActions/evaluateExpressionStepAction.js +0 -52
  116. package/player/stepActions/extensionOnlyStepAction.js +0 -12
  117. package/player/stepActions/extractTextStepAction.js +0 -19
  118. package/player/stepActions/hoverStepAction.js +0 -55
  119. package/player/stepActions/inputFileStepAction.js +0 -199
  120. package/player/stepActions/jsCodeStepAction.js +0 -11
  121. package/player/stepActions/jsConditionStepAction.js +0 -11
  122. package/player/stepActions/locateStepAction.js +0 -159
  123. package/player/stepActions/mouseStepAction.js +0 -370
  124. package/player/stepActions/navigationStepAction.js +0 -29
  125. package/player/stepActions/nodePackageStepAction.js +0 -47
  126. package/player/stepActions/pixelValidationStepAction.js +0 -39
  127. package/player/stepActions/scripts/dispatchEvents.js +0 -282
  128. package/player/stepActions/scripts/doClick.js +0 -221
  129. package/player/stepActions/scripts/doDragPath.js +0 -225
  130. package/player/stepActions/scripts/doubleClick.js +0 -119
  131. package/player/stepActions/scripts/dropEvent.js +0 -63
  132. package/player/stepActions/scripts/focusElement.js +0 -46
  133. package/player/stepActions/scripts/html5dragAction.js +0 -56
  134. package/player/stepActions/scripts/html5dragActionV2.js +0 -312
  135. package/player/stepActions/scripts/runCode.js +0 -147
  136. package/player/stepActions/scripts/scroll.js +0 -90
  137. package/player/stepActions/scripts/selectOption.js +0 -51
  138. package/player/stepActions/scripts/setText.js +0 -415
  139. package/player/stepActions/scripts/wheel.js +0 -61
  140. package/player/stepActions/scrollStepAction.js +0 -96
  141. package/player/stepActions/selectOptionStepAction.js +0 -49
  142. package/player/stepActions/sfdcRecordedStepAction.js +0 -24
  143. package/player/stepActions/sfdcStepAction.js +0 -28
  144. package/player/stepActions/sleepStepAction.js +0 -12
  145. package/player/stepActions/specialKeyStepAction.js +0 -52
  146. package/player/stepActions/stepAction.js +0 -73
  147. package/player/stepActions/stepActionRegistrar.js +0 -111
  148. package/player/stepActions/submitStepAction.js +0 -12
  149. package/player/stepActions/tdkHybridStepAction.js +0 -18
  150. package/player/stepActions/textStepAction.js +0 -110
  151. package/player/stepActions/textValidationStepAction.js +0 -64
  152. package/player/stepActions/wheelStepAction.js +0 -41
  153. package/player/utils/cookieUtils.js +0 -39
  154. package/player/utils/eyeSdkService.js +0 -250
  155. package/player/utils/imageCaptureUtils.js +0 -267
  156. package/player/utils/screenshotUtils.js +0 -68
  157. package/player/utils/stepActionUtils.js +0 -90
  158. package/player/utils/windowUtils.js +0 -195
  159. package/player/webDriverUtils.js +0 -40
  160. package/player/webDriverUtils.test.js +0 -116
  161. package/player/webdriver.js +0 -976
  162. package/polyfills/Array.prototype.at.js +0 -13
  163. package/polyfills/index.js +0 -9
  164. package/processHandler.js +0 -79
  165. package/processHandler.test.js +0 -55
  166. package/reports/chromeReporter.js +0 -17
  167. package/reports/consoleReporter.js +0 -190
  168. package/reports/debugReporter.js +0 -82
  169. package/reports/jsonReporter.js +0 -55
  170. package/reports/junitReporter.js +0 -183
  171. package/reports/reporter.js +0 -166
  172. package/reports/reporterUtils.js +0 -54
  173. package/reports/teamCityReporter.js +0 -73
  174. package/runOptions.d.ts +0 -305
  175. package/runOptions.js +0 -1288
  176. package/runOptionsAgentFlow.js +0 -87
  177. package/runOptionsUtils.js +0 -60
  178. package/runner.js +0 -355
  179. package/runners/ParallelWorkerManager.js +0 -284
  180. package/runners/TestPlanRunner.js +0 -419
  181. package/runners/buildCodeTests.js +0 -159
  182. package/runners/runnerUtils.js +0 -81
  183. package/services/analyticsService.js +0 -96
  184. package/services/branchService.js +0 -29
  185. package/services/gridService.js +0 -357
  186. package/services/gridService.test.js +0 -357
  187. package/services/labFeaturesService.js +0 -64
  188. package/services/lambdatestService.js +0 -227
  189. package/services/lambdatestService.test.js +0 -353
  190. package/services/localRCASaver.js +0 -124
  191. package/stepPlayers/cliJsStepPlayback.js +0 -40
  192. package/stepPlayers/hybridStepPlayback.js +0 -140
  193. package/stepPlayers/nodePackageStepPlayback.js +0 -28
  194. package/stepPlayers/playwrightHybridStepPlayback.js +0 -61
  195. package/stepPlayers/puppeteerHybridStepPlayback.js +0 -76
  196. package/stepPlayers/remoteStepPlayback.js +0 -80
  197. package/stepPlayers/seleniumHybridStepPlayback.js +0 -84
  198. package/stepPlayers/tdkHybridStepPlayback.js +0 -112
  199. package/testRunHandler.js +0 -603
  200. package/testRunStatus.js +0 -567
  201. package/testimNpmDriver.js +0 -52
  202. package/utils/argsUtils.js +0 -91
  203. package/utils/argsUtils.test.js +0 -32
  204. package/utils/fsUtils.js +0 -174
  205. package/utils/index.js +0 -197
  206. package/utils/promiseUtils.js +0 -85
  207. package/utils/stringUtils.js +0 -98
  208. package/utils/stringUtils.test.js +0 -22
  209. package/utils/timeUtils.js +0 -25
  210. package/utils/utils.test.js +0 -27
  211. package/workers/BaseWorker.js +0 -498
  212. package/workers/BaseWorker.test.js +0 -186
  213. package/workers/WorkerAppium.js +0 -180
  214. package/workers/WorkerExtension.js +0 -192
  215. package/workers/WorkerExtensionSingleBrowser.js +0 -77
  216. package/workers/WorkerSelenium.js +0 -253
  217. package/workers/workerUtils.js +0 -20
@@ -1,631 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
- const pako = require('pako');
5
- const pRetry = require('p-retry');
6
- const hash = require('object-hash');
7
- const utils = require('../utils');
8
- const config = require('./config');
9
- const constants = require('./constants');
10
- const httpRequest = require('./httpRequest');
11
- const testimCustomToken = require('./testimCustomToken');
12
- const { ArgError } = require('../errors');
13
- const { getLogger } = require('./logger');
14
-
15
- const runnerVersion = utils.getRunnerVersion();
16
- const logger = getLogger('testim service api');
17
-
18
- const DEFAULT_REQUEST_RETRY = 3;
19
- const GRID_PATH = '/grid';
20
-
21
- function getTokenHeader() {
22
- return testimCustomToken.getCustomTokenV3()
23
- .then(brearToken => {
24
- if (!brearToken) {
25
- throw new Error('Failed to get token from server');
26
- }
27
- return { Authorization: `Bearer ${brearToken}` };
28
- });
29
- }
30
-
31
- function postAuth({
32
- url, body, headers = {}, timeout, retry,
33
- }) {
34
- return getTokenHeader()
35
- .then(tokenHeaders => {
36
- const finalHeaders = Object.assign({}, headers, tokenHeaders);
37
- return httpRequest.post({
38
- url: `${config.SERVICES_HOST}${url || ''}`,
39
- body,
40
- headers: finalHeaders,
41
- timeout,
42
- retry,
43
- });
44
- });
45
- }
46
-
47
- // eslint-disable-next-line default-param-last
48
- function postAuthFormData(url, fields, files, headers = {}, timeout) {
49
- return getTokenHeader()
50
- .then(tokenHeaders => {
51
- const finalHeaders = Object.assign({}, headers, tokenHeaders);
52
- return httpRequest.postForm(`${config.SERVICES_HOST}${url || ''}`, fields, files, finalHeaders, timeout);
53
- });
54
- }
55
-
56
- function putAuth(url, body) {
57
- return getTokenHeader()
58
- .then(headers => httpRequest.put(`${config.SERVICES_HOST}${url || ''}`, body, headers));
59
- }
60
-
61
- function deleteAuth(url, body) {
62
- return getTokenHeader()
63
- .then(headers => httpRequest.delete(`${config.SERVICES_HOST}${url || ''}`, body, headers));
64
- }
65
-
66
- function getWithAuth(url, query, options, timeout) {
67
- return getTokenHeader()
68
- .then(headers => httpRequest.get(`${config.SERVICES_HOST}${url || ''}`, query, headers, timeout, options));
69
- }
70
-
71
- function getS3Artifact(url, timeout) {
72
- return pRetry(() => getWithAuth(`/storage${url}`, null, { isBinary: true }, timeout), { retries: DEFAULT_REQUEST_RETRY });
73
- }
74
-
75
- function getTestPlan(projectId, testPlanNames) {
76
- //TODO: need to be checked after 3 months to prevent users from using old version
77
- const parseProperty = (dataValue) => (dataValue == null ? [] : (typeof (dataValue) === 'string' && JSON.parse(dataValue)) || dataValue);
78
- return pRetry((() => getWithAuth('/testPlan', { projectId, name: testPlanNames.join(',') }), { retries: DEFAULT_REQUEST_RETRY }))
79
- .then(body => body.map(testPlan => {
80
- testPlan.testConfigIds = parseProperty(testPlan.testConfigIds);
81
- testPlan.beforeAllLabels = parseProperty(testPlan.beforeAllLabels);
82
- testPlan.testLabels = parseProperty(testPlan.testLabels);
83
- testPlan.afterAllLabels = parseProperty(testPlan.afterAllLabels);
84
- return testPlan;
85
- }));
86
- }
87
-
88
- async function loadSfdcCredential({ branch, projectId }) {
89
- const branchData = await pRetry(() => getWithAuth(`/branch/branchData/${branch}`, {
90
- projectId,
91
- }), { retries: DEFAULT_REQUEST_RETRY });
92
- return branchData?.sfdcCredential;
93
- }
94
-
95
- function loadTest({ testId, branch, projectId, skipSharedSteps = false, useBranchMap = true }) {
96
- return pRetry(() => getWithAuth(`/test/${testId}`, {
97
- projectId,
98
- branch,
99
- skipSharedSteps,
100
- useBranchMap,
101
- }), { retries: DEFAULT_REQUEST_RETRY });
102
- }
103
-
104
- function saveTestPlanResult(projectId, testPlanId, result) {
105
- return pRetry(() => postAuth({ url: '/testPlan/result', body: { projectId, testPlanId, result } }), { retries: DEFAULT_REQUEST_RETRY });
106
- }
107
-
108
- function updateTestStatus(projectId, executionId, testId, resultId, status, data, retries = DEFAULT_REQUEST_RETRY) {
109
- return pRetry(() => putAuth('/result/run/test', {
110
- runId: executionId,
111
- testId,
112
- resultId,
113
- status,
114
- projectId,
115
- runnerVersion,
116
- ...data,
117
- }), { retries });
118
- }
119
-
120
- function updateExecutionTests(executionId, runnerStatuses, status, reason, success, startTime, endTime, projectId) {
121
- return pRetry(() => putAuth('/result/run/tests', {
122
- runId: executionId,
123
- runnerStatuses,
124
- status,
125
- reason,
126
- success,
127
- startTime,
128
- endTime,
129
- projectId,
130
- }), { retries: DEFAULT_REQUEST_RETRY });
131
- }
132
-
133
- function reportExecutionStarted({
134
- executionId,
135
- projectId,
136
- labels,
137
- startTime,
138
- executions,
139
- config,
140
- resultLabels,
141
- remoteRunId,
142
- localRunUserId,
143
- isLocalRun,
144
- intersections,
145
- }) {
146
- const isCiRun = require('../cli/isCiRun').isCi;
147
- return postAuth({
148
- timeout: 90000,
149
- url: '/result/run',
150
- body: {
151
- runId: executionId,
152
- projectId,
153
- labels,
154
- startTime,
155
- execution: executions,
156
- status: 'RUNNING',
157
- config,
158
- resultLabels,
159
- remoteRunId,
160
- intersections,
161
- metadata: {
162
- isCiRun,
163
- localRunUserId,
164
- isLocalRun,
165
- },
166
- },
167
- retry: 3, // TODO: add a log in the callback
168
- });
169
- }
170
-
171
- // eslint-disable-next-line default-param-last
172
- function reportExecutionFinished(status, executionId, projectId, success, tmsOptions = {}, remoteRunId, resultExtraData) {
173
- const endTime = Date.now();
174
-
175
- return pRetry(() => putAuth('/result/run', {
176
- runId: executionId,
177
- projectId,
178
- endTime,
179
- status,
180
- success,
181
- tmsOptions,
182
- remoteRunId,
183
- resultExtraData,
184
- }), { retries: DEFAULT_REQUEST_RETRY });
185
- }
186
-
187
- /**
188
- * @param {string} projectId
189
- * @param {string[]} names
190
- * @param {string[]} planIds
191
- * @param {string} branch
192
- * @param {import('../runOptions').RunnerOptions['intersections']} intersections
193
- * @returns {ReturnType<import('services/src/test-plan/service')['testPlan']['getTestPlanTestList']>}
194
- */
195
- async function getTestPlanTestList(projectId, names, planIds, branch, intersections) {
196
- return pRetry(() => postAuth({
197
- url: '/testPlan/list',
198
- body: { projectId, names, planIds, branch, intersections },
199
- // people who send insane lists get a timeout :(
200
- timeout: 120000,
201
- }), { retries: DEFAULT_REQUEST_RETRY });
202
- }
203
-
204
- /**
205
- * @param {{
206
- * projectId: string;
207
- * labels: string[];
208
- * testIds: string[];
209
- * testNames: string[];
210
- * testConfigNames?: string[];
211
- * suiteNames: string[];
212
- * suiteIds: string[];
213
- * branch: string;
214
- * rerunFailedByRunId?: string;
215
- * testConfigIds?: string[];
216
- * intersections: import('../runOptions').RunnerOptions['intersections'];
217
- * }} param0
218
- * @returns {Promise<import('services/src/suite/service').RunListResult>}
219
- */
220
- function getSuiteTestList({
221
- projectId, labels, testIds, testNames, testConfigNames, suiteNames, suiteIds, branch, rerunFailedByRunId, testConfigIds, intersections,
222
- }) {
223
- return pRetry(() => postAuth({
224
- url: '/suite/v2/list',
225
- body: {
226
- projectId,
227
- labels,
228
- testIds,
229
- testNames,
230
- testConfigNames,
231
- suiteNames,
232
- suiteIds,
233
- branch,
234
- rerunFailedByRunId,
235
- testConfigIds,
236
- intersections,
237
- },
238
- }), { retries: DEFAULT_REQUEST_RETRY, factor: 1 });
239
- }
240
-
241
- async function getAppDetails({ appId, projectId }) {
242
- try {
243
- return await pRetry(() => getWithAuth(`/mobile-app/app/${appId}?projectId=${projectId}`), { retries: DEFAULT_REQUEST_RETRY, factor: 1 });
244
- } catch (error) {
245
- logger.error('failed getting application details', { appId, error });
246
- return undefined;
247
- }
248
- }
249
-
250
- function getUsageForCurrentBillingPeriod(projectId) {
251
- return pRetry(() => getWithAuth(`/plan/project/${projectId}/usage-current-billing-period`), { retries: DEFAULT_REQUEST_RETRY })
252
- .catch((error) => {
253
- logger.error('failed getting usage for current billing period', { projectId, error });
254
- return undefined;
255
- });
256
- }
257
-
258
- function isTestResultCompleted(resultId, projectId, testRetryKey) {
259
- return pRetry(() => getWithAuth(`/result/${resultId}/isComplete`, { projectId, testRetryKey }), { retries: DEFAULT_REQUEST_RETRY });
260
- }
261
-
262
- function getTestResults(testId, resultId, projectId, branch) {
263
- return pRetry(() => getWithAuth(`/test/v2/${testId}/result/${resultId}`, { projectId, branch }), { retries: DEFAULT_REQUEST_RETRY, factor: 1 });
264
- }
265
-
266
- function keepAliveGrid(projectId, slots) {
267
- return postAuth({
268
- url: `/grid/keep-alive?reqId=${utils.guid()}`,
269
- body: { projectId, slots },
270
- timeout: 10000,
271
- });
272
- }
273
-
274
- function releaseGridSlot(companyId, projectId, slotId, gridId, browser) {
275
- return postAuth({
276
- url: `/grid/release?reqId=${utils.guid()}`,
277
- body: {
278
- companyId, projectId, slotId, gridId, browser,
279
- },
280
- });
281
- }
282
-
283
- function getHybridGridProvider(body) {
284
- return postAuth({
285
- url: '/grid/hybrid/provider',
286
- body,
287
- });
288
- }
289
-
290
- function getGridByName(companyId, projectId, gridName, browser, executionId) {
291
- return pRetry(() => getWithAuth('/grid/name', {
292
- companyId, projectId, name: gridName, browser, executionId, reqId: utils.guid(),
293
- }), { retries: DEFAULT_REQUEST_RETRY });
294
- }
295
-
296
- function getGridById(companyId, projectId, gridId, browser, executionId) {
297
- return pRetry(() => getWithAuth(`/grid/${gridId}`, { companyId, projectId, browser, executionId, reqId: utils.guid() }), { retries: DEFAULT_REQUEST_RETRY });
298
- }
299
-
300
- /**
301
- * @param {{ projectId: string; token: string; branchName: string; lightweightMode?: import('../runOptions').LightweightSettings; localGrid: boolean; }} param0
302
- * @returns {Promise<{
303
- * authData: { token: string; refreshToken: string; uid: string; ngrokToken?: string; isNgrokWhitelisted?: boolean; };
304
- * editorConfig: { editorUrl: string };
305
- * companyByProjectId: Awaited<ReturnType<import('services/src/company/companyService')['getCompanyByProjectIdUsingCache']>>;
306
- * projectById: NonNullable<Awaited<ReturnType<import('services/src/commons/testimCache')['project']['getById']>>>;
307
- * allGrids: import('services/src/commons/mongo/models/grid').RawGrid[];
308
- * branchName: string | import('services/src/commons/mongo/models/branchesData').RawBranchesData | null;
309
- * }>}
310
- */
311
- async function initializeUserWithAuth({ projectId, token, branchName, lightweightMode, localGrid }) {
312
- try {
313
- return await pRetry(() => httpRequest.post({
314
- url: `${config.SERVICES_HOST}/executions/initialize`,
315
- body: {
316
- projectId,
317
- token,
318
- branchName: branchName || 'master',
319
- lightweightMode,
320
- localGrid,
321
- },
322
- }), { retries: DEFAULT_REQUEST_RETRY });
323
- } catch (e) {
324
- logger.error('error initializing info from server', e);
325
- if (e?.message?.includes('Bad Request')) {
326
- throw new ArgError(
327
- 'Error trying to retrieve CLI token. ' +
328
- 'Your CLI token and project might not match. ' +
329
- 'Please make sure to pass `--project` and `--token` that' +
330
- ' match to each other or make sure they match in your ~/.testim file.');
331
- }
332
- if (e?.code?.includes('ENOTFOUND')) {
333
- throw new ArgError('Due to network connectivity issues, Testim CLI has been unable to connect to the Testim backend.');
334
- }
335
- throw e;
336
- }
337
- }
338
-
339
- async function getEditorUrl() {
340
- if (config.EDITOR_URL) {
341
- return config.EDITOR_URL;
342
- }
343
- try {
344
- return await pRetry(() => getWithAuth('/system-info/editor-url'), {
345
- retries: DEFAULT_REQUEST_RETRY,
346
- onFailedAttempt: error => {
347
- if (error.attemptNumber >= DEFAULT_REQUEST_RETRY) {
348
- throw error;
349
- }
350
- },
351
- });
352
- } catch (err) {
353
- logger.error('cannot retrieve editor-url from server');
354
- return 'https://app.testim.io';
355
- }
356
- }
357
-
358
- function getAllGrids(companyId) {
359
- return pRetry(() => getWithAuth('/grid', { companyId }), { retries: DEFAULT_REQUEST_RETRY });
360
- }
361
-
362
- const fetchLambdatestConfig = async () => pRetry(() => getWithAuth('/grid/lt/config'), { retries: DEFAULT_REQUEST_RETRY });
363
-
364
- const getLabFeaturesByProjectId = async (projectId) => pRetry(() => getWithAuth(`/labFeature/v2/project/${projectId}`), { retries: DEFAULT_REQUEST_RETRY });
365
-
366
-
367
- function getRealData(projectId, channel, query) {
368
- return pRetry(() => getWithAuth(`/real-data/${channel}?${query}&projectId=${projectId}`), { retries: DEFAULT_REQUEST_RETRY });
369
- }
370
-
371
- function updateTestResult(projectId, resultId, testId, testResult, remoteRunId) {
372
- return pRetry(() => postAuth({
373
- url: '/result/test',
374
- body: {
375
- projectId,
376
- resultId,
377
- testId,
378
- testResult,
379
- remoteRunId,
380
- },
381
- }), { retries: DEFAULT_REQUEST_RETRY });
382
- }
383
-
384
- function clearTestResult(projectId, resultId, testId, testResult) {
385
- return pRetry(() => postAuth({
386
- url: '/result/test/clear',
387
- body: {
388
- projectId,
389
- resultId,
390
- testId,
391
- testResult,
392
- },
393
- }), { retries: DEFAULT_REQUEST_RETRY });
394
- }
395
-
396
- function saveRemoteStep(projectId, resultId, stepId, remoteStep) {
397
- return pRetry(() => postAuth({
398
- url: '/remoteStep',
399
- body: {
400
- projectId,
401
- resultId,
402
- stepId,
403
- remoteStep,
404
- },
405
- }), { retries: DEFAULT_REQUEST_RETRY });
406
- }
407
-
408
- /** @param {string} uri */
409
- function relativize(uri) {
410
- return uri.startsWith('/') ? uri : `/${uri}`;
411
- }
412
-
413
- /**
414
- * @param {string} filePath
415
- * @param {string} bucket
416
- * @param {string} projectId
417
- */
418
- function getStorageRelativePath(filePath, bucket, projectId) {
419
- let fullPath = relativize(filePath);
420
- if (projectId) {
421
- fullPath = `/${projectId}${fullPath}`;
422
- }
423
- if (bucket) {
424
- fullPath = `/${bucket}${fullPath}`;
425
- }
426
-
427
- return fullPath;
428
- }
429
-
430
- /**
431
- * @param {string} projectId
432
- * @param {string} testId
433
- * @param {string} testResultId
434
- * @param {*} content
435
- * @param {string} subType
436
- * @param {string} mimeType
437
- */
438
- async function uploadArtifact(projectId, testId, testResultId, content, subType, mimeType = 'application/octet-stream') {
439
- let fileSuffix = null;
440
- if (mimeType === 'application/json') {
441
- fileSuffix = '.json';
442
- }
443
- const fileName = `${subType}_${utils.guid()}${fileSuffix || ''}`;
444
- const path = `${testId}/${testResultId}/${fileName}`;
445
- const storagePath = getStorageRelativePath(path, 'test-result-artifacts', projectId);
446
-
447
- const buffer = Buffer.from(pako.gzip(content, {
448
- level: 3, // sufficient time/size ratio.
449
- }));
450
-
451
- const files = {
452
- file: {
453
- fileName,
454
- buffer,
455
- },
456
- };
457
-
458
- await pRetry(
459
- () => postAuthFormData(`/storage${storagePath}`, {}, files, { 'X-Asset-Encoding': 'gzip' }),
460
- { retries: DEFAULT_REQUEST_RETRY, factor: 1 },
461
- );
462
- return storagePath;
463
- }
464
-
465
- const uploadRunDataArtifact = _.memoize(async (projectId, testId, testResultId, runData) => {
466
- if (_.isEmpty(runData)) {
467
- return undefined;
468
- }
469
- return await uploadArtifact(projectId, testId, testResultId, JSON.stringify(runData), 'test-run-data', 'application/json');
470
- }, (projectId, testId, testResultId, runData) => `${hash(runData)}:${testId}:${testResultId}`);
471
-
472
- const updateTestDataArtifact = _.memoize(async (projectId, testId, testResultId, testData, projectDefaults) => {
473
- if (_.isEmpty(testData)) {
474
- return undefined;
475
- }
476
- const removeHiddenParamsInTestData = () => {
477
- const testDataValueClone = _.clone(testData);
478
- if (projectDefaults?.hiddenParams) {
479
- const { hiddenParams } = projectDefaults;
480
- (hiddenParams || []).forEach((param) => {
481
- if (testDataValueClone[param]) {
482
- testDataValueClone[param] = constants.test.HIDDEN_PARAM;
483
- }
484
- });
485
- }
486
- return testDataValueClone;
487
- };
488
-
489
- return await uploadArtifact(projectId, testId, testResultId, JSON.stringify(removeHiddenParamsInTestData(testData)), 'test-test-data', 'application/json');
490
- }, (projectId, testId, testResultId, testData) => `${hash(testData)}:${testId}:${testResultId}`);
491
-
492
- function addTestRetry({
493
- projectId,
494
- runId,
495
- testId,
496
- newResultId,
497
- originalTestResultId,
498
- previousTestResultId,
499
- testResult,
500
- }) {
501
- return pRetry(() => postAuth({
502
- url: '/result/test/retry',
503
- body: {
504
- projectId,
505
- newResultId,
506
- originalTestResultId,
507
- previousTestResultId,
508
- testId,
509
- runId,
510
- testResult,
511
- },
512
- }), { retries: DEFAULT_REQUEST_RETRY });
513
- }
514
-
515
- /**
516
- * @param {string} projectId
517
- * @returns {Promise<import('../../../clickim/src/common/api/testimApplitoolsApi').ApplitoolsIntegrationData>}
518
- */
519
- async function getApplitoolsIntegrationData(projectId) {
520
- try {
521
- return await getWithAuth(`/integration/applitools/v3/connected?projectId=${projectId}`);
522
- } catch (err) {
523
- logger.warn('could\'nt get applitools integration data.', { err });
524
- return {};
525
- }
526
- }
527
-
528
-
529
- /**
530
- * @param {string} companyId
531
- * @param {string[]} routes
532
- * @returns {Promise<{ _id?: string; token?: string; routesMapping?: { [k: string]: string; } }>}
533
- */
534
- async function getCloudflareTunnel(companyId, routes) {
535
- try {
536
- return await putAuth('/tunnel', { companyId, routes });
537
- } catch (err) {
538
- logger.warn('could\'nt get tunnel.', { err });
539
- return {};
540
- }
541
- }
542
- /**
543
- * @param {string} companyId
544
- * @param {string} tunnelId
545
- * @returns {Promise<void>}
546
- */
547
- async function forceUpdateCloudflareTunnelRoutes(companyId, tunnelId) {
548
- try {
549
- return await postAuth({ url: `/tunnel/${tunnelId}`, body: { companyId } });
550
- } catch (err) {
551
- logger.warn('could\'nt get tunnel.', { err });
552
- return undefined;
553
- }
554
- }
555
- /**
556
- * @param {string} companyId
557
- * @param {string} tunnelId
558
- * @returns {Promise<void>}
559
- */
560
- async function deleteCloudflareTunnel(companyId, tunnelId) {
561
- try {
562
- return await deleteAuth(`/tunnel/${tunnelId}`, { companyId });
563
- } catch (err) {
564
- logger.warn('could\'nt get tunnel.', { err });
565
- return {};
566
- }
567
- }
568
-
569
- function updateRemoteRunFailure(body) {
570
- return httpRequest.post({ url: `${config.SERVICES_HOST}/result/remoteRunFailure`, body });
571
- }
572
-
573
- /**
574
- * @param {string} projectType
575
- * @param {string} gridId
576
- * @param {string} companyId
577
- * @param {string} selectors
578
- * @return {Promise<Array[import('../../../services/src/grid/mobileGridService').MobileDevice] | null>}
579
- */
580
-
581
- async function getMobileDevicesFromGrid({ projectId, projectType, gridId, companyId, selectors }) {
582
- let url = `${GRID_PATH}/mobileDevices/${gridId}/${companyId}?projectType=${projectType}`;
583
- url = selectors ? `${url}&selectors=${encodeURIComponent(selectors)}` : url;
584
- try {
585
- return await pRetry(() => getWithAuth(url, { projectId }), { retries: DEFAULT_REQUEST_RETRY });
586
- } catch (err) {
587
- logger.warn('could\'nt get devices from headspin grid.', { err });
588
- return null;
589
- }
590
- }
591
-
592
- module.exports = {
593
- getAppDetails,
594
- getS3Artifact,
595
- getTestPlan,
596
- saveTestPlanResult,
597
- updateTestStatus,
598
- updateExecutionTests,
599
- reportExecutionStarted,
600
- reportExecutionFinished,
601
- getTestPlanTestList,
602
- getSuiteTestList,
603
- getUsageForCurrentBillingPeriod,
604
- getTestResults,
605
- getGridByName,
606
- releaseGridSlot,
607
- keepAliveGrid,
608
- getGridById,
609
- getAllGrids,
610
- fetchLambdatestConfig,
611
- getRealData,
612
- updateTestResult,
613
- clearTestResult,
614
- saveRemoteStep,
615
- getEditorUrl,
616
- getLabFeaturesByProjectId,
617
- uploadRunDataArtifact,
618
- updateTestDataArtifact,
619
- initializeUserWithAuth,
620
- addTestRetry,
621
- getHybridGridProvider,
622
- loadSfdcCredential,
623
- loadTest,
624
- isTestResultCompleted,
625
- getApplitoolsIntegrationData,
626
- getCloudflareTunnel,
627
- forceUpdateCloudflareTunnelRoutes,
628
- deleteCloudflareTunnel,
629
- updateRemoteRunFailure,
630
- getMobileDevicesFromGrid,
631
- };
@@ -1,73 +0,0 @@
1
- 'use strict';
2
-
3
- const ora = require('ora');
4
-
5
- const LambdatestService = require('../services/lambdatestService');
6
- const processHandler = require('../processHandler');
7
- const testimCustomToken = require('./testimCustomToken');
8
- const { gridTypes } = require('./constants');
9
- const testimNgrok = require('./testimNgrok');
10
- const testimCloudflare = require('./testimCloudflare');
11
- const logger = require('./logger').getLogger('tunnel');
12
-
13
- const shouldUseLambdatestTunnel = options => [gridTypes.LAMBDATEST, gridTypes.HYBRID].includes(options.gridData && options.gridData.type) && options.gridData.tunnel === 'lambdatest';
14
- const shouldUseCloudflareTunnel = options => options.tunnelRoutes || (options.gridData && options.gridData.type === gridTypes.HYBRID && options.gridData.tunnel === 'cloudflare');
15
-
16
- const connect = async (options) => {
17
- if (!options.tunnel) {
18
- return;
19
- }
20
-
21
- const authData = testimCustomToken.getTokenV3UserData();
22
- let spinner;
23
- try {
24
- if (shouldUseLambdatestTunnel(options)) {
25
- spinner = ora('Starting testim lambdatest tunnel...').start();
26
- await LambdatestService.connectTunnel(options);
27
- } else if (shouldUseCloudflareTunnel(options)) {
28
- spinner = ora('Starting testim cloudflare tunnel...').start();
29
- await testimCloudflare.connectTunnel(options);
30
- } else {
31
- spinner = ora('Starting testim ngrok tunnel...').start();
32
- await testimNgrok.connectTunnel(options, authData);
33
- }
34
- spinner.succeed();
35
- } catch (err) {
36
- const msg = 'Failed to start tunnel. Please contact support@testim.io';
37
- logger.error('Failed to open tunnel', { err });
38
- spinner.fail(msg);
39
- throw new Error(msg);
40
- }
41
- };
42
-
43
- const disconnect = async (options) => {
44
- if (!options.tunnel) {
45
- return;
46
- }
47
-
48
- try {
49
- if (shouldUseLambdatestTunnel(options)) {
50
- await LambdatestService.disconnectTunnel(options);
51
- } else if (options.tunnelRoutes) {
52
- await testimCloudflare.disconnectTunnel(options);
53
- } else {
54
- await testimNgrok.disconnectTunnel(options);
55
- }
56
- } catch (err) {
57
- const msg = 'catch error - failed to close tunnel';
58
- logger.error(msg, { err });
59
- throw new Error(msg);
60
- }
61
- };
62
-
63
- const serveTunneling = async (options, waitFor = new Promise(() => { /* avoid exiting process */ })) => {
64
- await module.exports.connect(options);
65
- processHandler.registerExitHook(() => module.exports.disconnect(options));
66
- return await waitFor;
67
- };
68
-
69
- module.exports = {
70
- connect,
71
- disconnect,
72
- serveTunneling,
73
- };