@testim/testim-cli 3.289.0 → 3.290.1-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.
- package/cli.js +22390 -122
- package/cli.js.map +1 -0
- package/npm-shrinkwrap.json +1169 -12846
- package/package.json +16 -10
- package/OverrideTestDataBuilder.js +0 -117
- package/agent/routers/cliJsCode/index.js +0 -13
- package/agent/routers/cliJsCode/router.js +0 -63
- package/agent/routers/cliJsCode/service.js +0 -705
- package/agent/routers/codim/router.js +0 -69
- package/agent/routers/codim/router.test.js +0 -60
- package/agent/routers/codim/service.js +0 -193
- package/agent/routers/general/index.js +0 -36
- package/agent/routers/hybrid/registerRoutes.js +0 -81
- package/agent/routers/index.js +0 -56
- package/agent/routers/playground/router.js +0 -77
- package/agent/routers/playground/service.js +0 -96
- package/agent/routers/standalone-browser/registerRoutes.js +0 -47
- package/agent/server.js +0 -150
- package/cdpTestRunner.js +0 -86
- package/chromiumInstaller.js +0 -91
- package/cli/isCiRun.js +0 -10
- package/cli/onExit.js +0 -65
- package/cli/writeStackTrace.js +0 -27
- package/cliAgentMode.js +0 -384
- package/codim/codim-cli.js +0 -91
- package/codim/codim-npm-package/index.ts +0 -427
- package/codim/codim-npm-package/package-lock.json +0 -14
- package/codim/codim-npm-package/package.json +0 -14
- package/codim/hybrid-utils.js +0 -28
- package/codim/measure-perf.js +0 -41
- package/codim/template.js/.idea/workspace.xml +0 -57
- package/codim/template.js/.vscode/launch.json +0 -53
- package/codim/template.ts/.idea/workspace.xml +0 -57
- package/codim/template.ts/.vscode/launch.json +0 -55
- package/commons/AbortError.js +0 -12
- package/commons/SeleniumPerfStats.js +0 -58
- package/commons/chrome-launcher.js +0 -15
- package/commons/chromedriverWrapper.js +0 -70
- package/commons/config.js +0 -39
- package/commons/constants.js +0 -67
- package/commons/detectDebugger.js +0 -19
- package/commons/featureAvailabilityService.js +0 -26
- package/commons/featureFlags.js +0 -132
- package/commons/getSessionPlayerRequire.js +0 -28
- package/commons/httpRequest.js +0 -261
- package/commons/httpRequestCounters.js +0 -98
- package/commons/httpRequestCounters.test.js +0 -38
- package/commons/initializeUserWithAuth.js +0 -55
- package/commons/lazyRequire.js +0 -105
- package/commons/logUtils.js +0 -15
- package/commons/logUtils.test.js +0 -21
- package/commons/logger.js +0 -178
- package/commons/mockNetworkRuleFileSchema.json +0 -140
- package/commons/npmWrapper.js +0 -174
- package/commons/npmWrapper.test.js +0 -374
- package/commons/performance-logger.js +0 -71
- package/commons/preloadTests.js +0 -29
- package/commons/prepareRunner.js +0 -85
- package/commons/prepareRunner.test.js +0 -144
- package/commons/prepareRunnerAndTestimStartUtils.js +0 -198
- package/commons/prepareRunnerAndTestimStartUtils.test.js +0 -73
- package/commons/requireWithFallback.js +0 -25
- package/commons/runnerFileCache.js +0 -204
- package/commons/socket/baseSocketServiceSocketIO.js +0 -197
- package/commons/socket/realDataService.js +0 -59
- package/commons/socket/realDataServiceSocketIO.js +0 -33
- package/commons/socket/remoteStepService.js +0 -55
- package/commons/socket/remoteStepServiceSocketIO.js +0 -61
- package/commons/socket/socketService.js +0 -175
- package/commons/socket/testResultService.js +0 -62
- package/commons/socket/testResultServiceSocketIO.js +0 -64
- package/commons/testimAnalytics.js +0 -40
- package/commons/testimCloudflare.js +0 -83
- package/commons/testimCloudflare.test.js +0 -185
- package/commons/testimCustomToken.js +0 -124
- package/commons/testimDesiredCapabilitiesBuilder.js +0 -647
- package/commons/testimNgrok.js +0 -90
- package/commons/testimNgrok.test.js +0 -140
- package/commons/testimServicesApi.js +0 -631
- package/commons/testimTunnel.js +0 -73
- package/commons/testimTunnel.test.js +0 -172
- package/commons/xhr2.js +0 -897
- package/coverage/SummaryToObjectReport.js +0 -19
- package/coverage/jsCoverage.js +0 -252
- package/credentialsManager.js +0 -142
- package/errors.js +0 -161
- package/executionQueue.js +0 -37
- package/fixLocalBuild.js +0 -24
- package/inputFileUtils.js +0 -103
- package/lib/coralogix-winston.transport.js +0 -99
- package/player/SeleniumProtocolError.js +0 -100
- package/player/WebDriverHttpRequest.js +0 -177
- package/player/WebdriverioWebDriverApi.js +0 -671
- package/player/appiumTestPlayer.js +0 -90
- package/player/chromeLauncherTestPlayer.js +0 -67
- package/player/constants.js +0 -332
- package/player/extensionTestPlayer.js +0 -32
- package/player/findElementStrategy.js +0 -154
- package/player/scripts/isElementDisplayed.js +0 -252
- package/player/seleniumTestPlayer.js +0 -140
- package/player/services/frameLocator.js +0 -170
- package/player/services/mobileFrameLocatorMock.js +0 -32
- package/player/services/playbackTimeoutCalculator.js +0 -175
- package/player/services/portSelector.js +0 -19
- package/player/services/tabService.js +0 -551
- package/player/services/tabServiceMock.js +0 -167
- package/player/services/windowCreationListener.js +0 -8
- package/player/stepActions/RefreshStepAction.js +0 -16
- package/player/stepActions/apiStepAction.js +0 -89
- package/player/stepActions/baseCliJsStepAction.js +0 -51
- package/player/stepActions/baseJsStepAction.js +0 -277
- package/player/stepActions/cliConditionStepAction.js +0 -11
- package/player/stepActions/cliJsStepAction.js +0 -11
- package/player/stepActions/dropFileStepAction.js +0 -34
- package/player/stepActions/evaluateExpressionStepAction.js +0 -52
- package/player/stepActions/extensionOnlyStepAction.js +0 -12
- package/player/stepActions/extractTextStepAction.js +0 -19
- package/player/stepActions/hoverStepAction.js +0 -55
- package/player/stepActions/inputFileStepAction.js +0 -199
- package/player/stepActions/jsCodeStepAction.js +0 -11
- package/player/stepActions/jsConditionStepAction.js +0 -11
- package/player/stepActions/locateStepAction.js +0 -159
- package/player/stepActions/mouseStepAction.js +0 -370
- package/player/stepActions/navigationStepAction.js +0 -29
- package/player/stepActions/nodePackageStepAction.js +0 -47
- package/player/stepActions/pixelValidationStepAction.js +0 -39
- package/player/stepActions/scripts/dispatchEvents.js +0 -282
- package/player/stepActions/scripts/doClick.js +0 -221
- package/player/stepActions/scripts/doDragPath.js +0 -225
- package/player/stepActions/scripts/doubleClick.js +0 -119
- package/player/stepActions/scripts/dropEvent.js +0 -63
- package/player/stepActions/scripts/focusElement.js +0 -46
- package/player/stepActions/scripts/html5dragAction.js +0 -56
- package/player/stepActions/scripts/html5dragActionV2.js +0 -312
- package/player/stepActions/scripts/runCode.js +0 -147
- package/player/stepActions/scripts/scroll.js +0 -90
- package/player/stepActions/scripts/selectOption.js +0 -51
- package/player/stepActions/scripts/setText.js +0 -415
- package/player/stepActions/scripts/wheel.js +0 -61
- package/player/stepActions/scrollStepAction.js +0 -96
- package/player/stepActions/selectOptionStepAction.js +0 -49
- package/player/stepActions/sfdcRecordedStepAction.js +0 -24
- package/player/stepActions/sfdcStepAction.js +0 -28
- package/player/stepActions/sleepStepAction.js +0 -12
- package/player/stepActions/specialKeyStepAction.js +0 -52
- package/player/stepActions/stepAction.js +0 -73
- package/player/stepActions/stepActionRegistrar.js +0 -111
- package/player/stepActions/submitStepAction.js +0 -12
- package/player/stepActions/tdkHybridStepAction.js +0 -18
- package/player/stepActions/textStepAction.js +0 -110
- package/player/stepActions/textValidationStepAction.js +0 -64
- package/player/stepActions/wheelStepAction.js +0 -41
- package/player/utils/cookieUtils.js +0 -39
- package/player/utils/eyeSdkService.js +0 -250
- package/player/utils/imageCaptureUtils.js +0 -267
- package/player/utils/screenshotUtils.js +0 -68
- package/player/utils/stepActionUtils.js +0 -90
- package/player/utils/windowUtils.js +0 -195
- package/player/webDriverUtils.js +0 -40
- package/player/webDriverUtils.test.js +0 -116
- package/player/webdriver.js +0 -976
- package/polyfills/Array.prototype.at.js +0 -13
- package/polyfills/index.js +0 -13
- package/processHandler.js +0 -79
- package/processHandler.test.js +0 -55
- package/reports/chromeReporter.js +0 -17
- package/reports/consoleReporter.js +0 -190
- package/reports/debugReporter.js +0 -82
- package/reports/jsonReporter.js +0 -55
- package/reports/junitReporter.js +0 -183
- package/reports/reporter.js +0 -166
- package/reports/reporterUtils.js +0 -54
- package/reports/teamCityReporter.js +0 -73
- package/runOptions.d.ts +0 -305
- package/runOptions.js +0 -1288
- package/runOptionsAgentFlow.js +0 -87
- package/runOptionsUtils.js +0 -60
- package/runner.js +0 -355
- package/runners/ParallelWorkerManager.js +0 -284
- package/runners/TestPlanRunner.js +0 -419
- package/runners/buildCodeTests.js +0 -159
- package/runners/runnerUtils.js +0 -81
- package/services/analyticsService.js +0 -96
- package/services/branchService.js +0 -29
- package/services/gridService.js +0 -357
- package/services/gridService.test.js +0 -357
- package/services/labFeaturesService.js +0 -64
- package/services/lambdatestService.js +0 -227
- package/services/lambdatestService.test.js +0 -353
- package/services/localRCASaver.js +0 -124
- package/stepPlayers/cliJsStepPlayback.js +0 -40
- package/stepPlayers/hybridStepPlayback.js +0 -140
- package/stepPlayers/nodePackageStepPlayback.js +0 -28
- package/stepPlayers/playwrightHybridStepPlayback.js +0 -61
- package/stepPlayers/puppeteerHybridStepPlayback.js +0 -76
- package/stepPlayers/remoteStepPlayback.js +0 -80
- package/stepPlayers/seleniumHybridStepPlayback.js +0 -84
- package/stepPlayers/tdkHybridStepPlayback.js +0 -112
- package/testRunHandler.js +0 -603
- package/testRunStatus.js +0 -567
- package/testimNpmDriver.js +0 -52
- package/utils/argsUtils.js +0 -91
- package/utils/argsUtils.test.js +0 -32
- package/utils/fsUtils.js +0 -174
- package/utils/index.js +0 -197
- package/utils/promiseUtils.js +0 -85
- package/utils/stringUtils.js +0 -98
- package/utils/stringUtils.test.js +0 -22
- package/utils/timeUtils.js +0 -25
- package/utils/utils.test.js +0 -27
- package/workers/BaseWorker.js +0 -498
- package/workers/BaseWorker.test.js +0 -186
- package/workers/WorkerAppium.js +0 -180
- package/workers/WorkerExtension.js +0 -192
- package/workers/WorkerExtensionSingleBrowser.js +0 -77
- package/workers/WorkerSelenium.js +0 -253
- package/workers/workerUtils.js +0 -20
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const analytics = require('../commons/testimAnalytics');
|
|
4
|
-
const { isCi } = require('../cli/isCiRun');
|
|
5
|
-
|
|
6
|
-
const calcSource = (source, user) => {
|
|
7
|
-
if (source !== 'cli' && source !== 'cli-local') {
|
|
8
|
-
return source;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (isCi && user) {
|
|
12
|
-
return 'ci-with-user';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (isCi) {
|
|
16
|
-
return 'ci';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (user) {
|
|
20
|
-
return 'cli-with-user';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return source;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function setLightweightAnalytics(properties, lightweightMode) {
|
|
27
|
-
if (lightweightMode && lightweightMode.type) {
|
|
28
|
-
properties[`${lightweightMode.type}Mode`] = true;
|
|
29
|
-
}
|
|
30
|
-
return properties;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function analyticsTestStart({
|
|
34
|
-
executionId, projectId, testId, resultId, companyId, companyName, projectName, companyPlan, sessionType, source, user, lightweightMode, isStartUp, projectType,
|
|
35
|
-
}) {
|
|
36
|
-
const properties = setLightweightAnalytics({
|
|
37
|
-
executionId,
|
|
38
|
-
projectId,
|
|
39
|
-
testId,
|
|
40
|
-
resultId,
|
|
41
|
-
companyId,
|
|
42
|
-
companyName,
|
|
43
|
-
projectName,
|
|
44
|
-
companyPlan,
|
|
45
|
-
sessionType,
|
|
46
|
-
source: calcSource(source, user),
|
|
47
|
-
isStartUp,
|
|
48
|
-
projectType,
|
|
49
|
-
}, lightweightMode);
|
|
50
|
-
analytics.trackWithCIUser('test-run-ci', properties);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function analyticsTestEnd({
|
|
54
|
-
executionId, projectId, testId, resultId, result, companyId, companyName, projectName, companyPlan, sessionType, source, user, lightweightMode,
|
|
55
|
-
logger, isStartUp, projectType,
|
|
56
|
-
}) {
|
|
57
|
-
try {
|
|
58
|
-
const properties = setLightweightAnalytics({
|
|
59
|
-
executionId,
|
|
60
|
-
projectId,
|
|
61
|
-
testId,
|
|
62
|
-
resultId,
|
|
63
|
-
companyId,
|
|
64
|
-
companyName,
|
|
65
|
-
projectName,
|
|
66
|
-
companyPlan,
|
|
67
|
-
sessionType,
|
|
68
|
-
mockNetworkEnabled: result.wasMockNetworkActivated,
|
|
69
|
-
source: calcSource(source, user),
|
|
70
|
-
isStartUp,
|
|
71
|
-
projectType,
|
|
72
|
-
}, lightweightMode);
|
|
73
|
-
|
|
74
|
-
if (result.success) {
|
|
75
|
-
analytics.trackWithCIUser('test-run-ci-success', properties);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
analytics.trackWithCIUser('test-run-ci-fail', Object.assign({}, properties, { failureReason: result.failureReason }));
|
|
79
|
-
} catch (err) {
|
|
80
|
-
logger.error('failed to update test end analytics', { err });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function analyticsExecsStart({ executionId, projectId, sessionType }) {
|
|
85
|
-
analytics.trackWithCIUser('batch-run-ci', {
|
|
86
|
-
executionId,
|
|
87
|
-
projectId,
|
|
88
|
-
sessionType,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
module.exports = {
|
|
93
|
-
analyticsTestStart,
|
|
94
|
-
analyticsTestEnd,
|
|
95
|
-
analyticsExecsStart,
|
|
96
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/** @type {string | undefined} */
|
|
4
|
-
let currentBranch;
|
|
5
|
-
|
|
6
|
-
function getCurrentBranch() {
|
|
7
|
-
return currentBranch || 'master';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {Awaited<ReturnType<import('../commons/initializeUserWithAuth')['initializeUserWithAuth']>>['branchName']} branchData
|
|
12
|
-
* @param {boolean | string} acknowledgeAutoDetect
|
|
13
|
-
*/
|
|
14
|
-
function setCurrentBranch(branchData = 'master', acknowledgeAutoDetect = 'false') {
|
|
15
|
-
if (branchData?.branch && branchData.branch === 'master') {
|
|
16
|
-
currentBranch = 'master';
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (branchData && !branchData.isArchived) {
|
|
20
|
-
currentBranch = branchData.branch || branchData;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
currentBranch = acknowledgeAutoDetect ? 'master' : null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
getCurrentBranch,
|
|
28
|
-
setCurrentBranch,
|
|
29
|
-
};
|
package/services/gridService.js
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const _ = require('lodash');
|
|
6
|
-
|
|
7
|
-
const { GridError, ArgError, GridConcurrencyError } = require('../errors');
|
|
8
|
-
const { hasTestPlanFlag, promiseMap } = require('../utils');
|
|
9
|
-
const { gridMessages, gridTypes } = require('../commons/constants');
|
|
10
|
-
const logger = require('../commons/logger').getLogger('grid-service');
|
|
11
|
-
const servicesApi = require('../commons/testimServicesApi');
|
|
12
|
-
|
|
13
|
-
/** @type {Record<string, { gridId: string; companyId: string; slotId: string; browser: string }>} */
|
|
14
|
-
const gridCache = {};
|
|
15
|
-
const urlExtractRegex = /(^(https?):\/{2})?(.*)/;
|
|
16
|
-
let keepAliveTimer = null;
|
|
17
|
-
|
|
18
|
-
function extractProtocol(grid) {
|
|
19
|
-
if (grid.protocol) {
|
|
20
|
-
return grid.protocol;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if ([gridTypes.TESTIM, gridTypes.BROWSERSTACK, gridTypes.SAUCELABS].includes(grid.type) && grid.port === 443) {
|
|
24
|
-
return 'https';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if ([gridTypes.TESTIM_ENTERPRISE, gridTypes.LAMBDATEST, gridTypes.DEVICE_FARM].includes(grid.type)) {
|
|
28
|
-
const urlExtract = urlExtractRegex.exec(grid.host);
|
|
29
|
-
return urlExtract[2] || 'https';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return '';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function extractHost(hostUrl) {
|
|
36
|
-
const urlExtract = urlExtractRegex.exec(hostUrl);
|
|
37
|
-
return urlExtract[3];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getSerializableObject(grid) {
|
|
41
|
-
const host = grid && extractHost(grid.host);
|
|
42
|
-
const port = grid?.port;
|
|
43
|
-
const path = grid?.path;
|
|
44
|
-
const protocol = grid && extractProtocol(grid);
|
|
45
|
-
const accessToken = grid?.token;
|
|
46
|
-
const slotId = grid?.slotId;
|
|
47
|
-
const tunnel = grid?.hybrid?.tunnel;
|
|
48
|
-
const user = grid?.external?.user;
|
|
49
|
-
const key = grid?.external?.key;
|
|
50
|
-
const type = grid?.type;
|
|
51
|
-
const tunnelUser = type === gridTypes.HYBRID ?
|
|
52
|
-
(tunnel && grid.hybrid.external && grid.hybrid.external[grid.hybrid.tunnel] && grid.hybrid.external[grid.hybrid.tunnel].user) : user;
|
|
53
|
-
const tunnelKey = type === gridTypes.HYBRID ?
|
|
54
|
-
(tunnel && grid.hybrid.external && grid.hybrid.external[grid.hybrid.tunnel] && grid.hybrid.external[grid.hybrid.tunnel].key) : key;
|
|
55
|
-
const name = grid?.name;
|
|
56
|
-
const gridId = grid && (grid._id || grid.gridId);
|
|
57
|
-
const provider = grid?.provider;
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
host, port, path, protocol, accessToken, slotId, gridId, tunnel, user, key, type, name, provider, tunnelUser, tunnelKey,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @template {{ status: string; code?: string; grid: * }} T
|
|
66
|
-
* @param {string} projectId
|
|
67
|
-
* @param {string} companyId
|
|
68
|
-
* @param {number} workerId
|
|
69
|
-
* @param {string} browser
|
|
70
|
-
* @param {() => Promise<T>} getFun
|
|
71
|
-
*/
|
|
72
|
-
async function handleGetGridResponse(projectId, companyId, workerId, browser, getFun) {
|
|
73
|
-
/** @type {T} */
|
|
74
|
-
let res;
|
|
75
|
-
try {
|
|
76
|
-
res = await getFun();
|
|
77
|
-
} catch (err) {
|
|
78
|
-
logger.error('failed to get grid', { projectId, companyId, err });
|
|
79
|
-
throw new Error(gridMessages.UNKNOWN);
|
|
80
|
-
}
|
|
81
|
-
logger.info('get grid info', Object.assign({}, res, { projectId, companyId }));
|
|
82
|
-
const isSuccess = () => res.status === 'success';
|
|
83
|
-
const isError = () => res.status === 'error' && res.code;
|
|
84
|
-
if (!res || (!isError() && !isSuccess())) {
|
|
85
|
-
logger.error('invalid response - get grid', { res });
|
|
86
|
-
throw new Error(gridMessages.UNKNOWN);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (isSuccess()) {
|
|
90
|
-
const serGrid = getSerializableObject(res.grid);
|
|
91
|
-
module.exports.addItemToGridCache(workerId, companyId, serGrid.gridId, serGrid.slotId, browser);
|
|
92
|
-
return serGrid;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (isError() && res.code === 'not-found') {
|
|
96
|
-
throw new GridError(gridMessages.NOT_FOUND);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (isError() && res.code === 'no-available-slot') {
|
|
100
|
-
throw new GridConcurrencyError(`Failed to run test on ${browser} - concurrency limit reached`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
logger.error('invalid code error response - get grid', { res });
|
|
104
|
-
throw new GridError(gridMessages.UNKNOWN);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function addItemToGridCache(workerId, companyId, gridId, slotId, browser) {
|
|
108
|
-
gridCache[workerId] = { gridId, companyId, slotId, browser };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function getHostAndPortById(workerId, companyId, projectId, gridId, browser, executionId) {
|
|
112
|
-
return handleGetGridResponse(projectId, companyId, workerId, browser, () =>
|
|
113
|
-
servicesApi.getGridById(companyId, projectId, gridId, browser, executionId),
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function getHostAndPortByName(workerId, companyId, projectId, gridName, browser, executionId, options) {
|
|
118
|
-
const get = () => {
|
|
119
|
-
const grid = options.allGrids?.find(g => (g.name || '').toLowerCase() === gridName.toLowerCase());
|
|
120
|
-
if (grid?._id) {
|
|
121
|
-
return servicesApi.getGridById(companyId, projectId, grid._id, browser, executionId);
|
|
122
|
-
}
|
|
123
|
-
return servicesApi.getGridByName(companyId, projectId, gridName, browser, executionId);
|
|
124
|
-
};
|
|
125
|
-
return handleGetGridResponse(projectId, companyId, workerId, browser, get);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function getAllGrids(companyId) {
|
|
129
|
-
return servicesApi.getAllGrids(companyId);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function getGridDataByGridId(companyId, gridId, allGrids) {
|
|
133
|
-
const grids = await Promise.resolve(allGrids || getAllGrids(companyId));
|
|
134
|
-
const grid = grids.find(g => g._id === gridId);
|
|
135
|
-
if (!grid) {
|
|
136
|
-
throw new ArgError(`Failed to find grid id: ${gridId}`);
|
|
137
|
-
}
|
|
138
|
-
return getSerializableObject(grid);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function getGridDataByGridName(companyId, gridName, allGrids) {
|
|
142
|
-
const grids = await Promise.resolve(allGrids || getAllGrids(companyId));
|
|
143
|
-
const grid = grids.find(g => (g.name || '').toLowerCase() === gridName.toLowerCase());
|
|
144
|
-
if (!grid) {
|
|
145
|
-
throw new ArgError(`Failed to find grid name: ${gridName}`);
|
|
146
|
-
}
|
|
147
|
-
return getSerializableObject(grid);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async function releaseGridSlot(workerId, projectId) {
|
|
151
|
-
const gridData = gridCache[workerId];
|
|
152
|
-
if (!gridData) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const { slotId, gridId, browser, companyId } = gridData;
|
|
157
|
-
delete gridCache[workerId];
|
|
158
|
-
if (!slotId) {
|
|
159
|
-
logger.warn('failed to find grid slot id', { projectId });
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
logger.info('release slot id', { projectId, companyId, slotId, gridId, browser });
|
|
164
|
-
try {
|
|
165
|
-
await servicesApi.releaseGridSlot(companyId, projectId, slotId, gridId, browser);
|
|
166
|
-
} catch (err) {
|
|
167
|
-
logger.error('failed to release slot', { projectId, err });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async function keepAlive(projectId) {
|
|
172
|
-
const slots = Object.values(gridCache).filter(Boolean);
|
|
173
|
-
|
|
174
|
-
if (slots.length === 0) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
logger.info('keep alive worker slots', { projectId, slots });
|
|
179
|
-
try {
|
|
180
|
-
await servicesApi.keepAliveGrid(projectId, slots);
|
|
181
|
-
} catch (err) {
|
|
182
|
-
logger.error('failed to update grid keep alive', { err, slots, projectId });
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function startKeepAlive(projectId) {
|
|
187
|
-
const KEEP_ALIVE_INTERVAL = 10 * 1000;
|
|
188
|
-
keepAliveTimer = setInterval(keepAlive, KEEP_ALIVE_INTERVAL, projectId);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async function releaseAllSlots(projectId) {
|
|
192
|
-
const workerIds = Object.keys(gridCache);
|
|
193
|
-
|
|
194
|
-
if (_.isEmpty(workerIds)) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
logger.warn('not all slots released before end runner flow', { projectId });
|
|
199
|
-
try {
|
|
200
|
-
await promiseMap(workerIds, workerId => releaseGridSlot(workerId, projectId));
|
|
201
|
-
} catch (err) {
|
|
202
|
-
logger.error('failed to release all slots', { err, projectId });
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async function endKeepAlive(projectId) {
|
|
207
|
-
await releaseAllSlots(projectId);
|
|
208
|
-
clearInterval(keepAliveTimer);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function getVendorKeyFromOptions(type, options) {
|
|
212
|
-
const { testobjectSauce, saucelabs } = options;
|
|
213
|
-
if (type === 'testobject') {
|
|
214
|
-
return testobjectSauce.testobjectApiKey;
|
|
215
|
-
}
|
|
216
|
-
if (type === 'saucelabs') {
|
|
217
|
-
return saucelabs.accessKey;
|
|
218
|
-
}
|
|
219
|
-
return undefined;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function getVendorUserFromOptions(type, options) {
|
|
223
|
-
const { saucelabs } = options;
|
|
224
|
-
if (type === 'saucelabs') {
|
|
225
|
-
return saucelabs.username;
|
|
226
|
-
}
|
|
227
|
-
return undefined;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function getOptionGrid(options) {
|
|
231
|
-
const getGridType = () => {
|
|
232
|
-
if (!_.isEmpty(options.testobjectSauce)) {
|
|
233
|
-
return 'testobject';
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (!_.isEmpty(options.saucelabs)) {
|
|
237
|
-
return 'saucelabs';
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (!_.isEmpty(options.perfecto)) {
|
|
241
|
-
return 'perfecto';
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return 'hostAndPort';
|
|
245
|
-
};
|
|
246
|
-
const type = getGridType();
|
|
247
|
-
const { host, port, path, protocol } = options;
|
|
248
|
-
const key = getVendorKeyFromOptions(type, options);
|
|
249
|
-
const user = getVendorUserFromOptions(type, options);
|
|
250
|
-
return Promise.resolve({ host, port, path, protocol, type, user, key });
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
async function getTestPlanGridData(options, testPlanData) {
|
|
254
|
-
const companyId = options.company.companyId;
|
|
255
|
-
return await getGridDataByGridId(companyId, testPlanData.gridId, options.allGrids);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
async function getGridData(options) {
|
|
259
|
-
const {
|
|
260
|
-
allGrids = undefined, company,
|
|
261
|
-
host, useLocalChromeDriver, useChromeLauncher, gridId, grid,
|
|
262
|
-
} = options;
|
|
263
|
-
if (useLocalChromeDriver || useChromeLauncher) {
|
|
264
|
-
return { mode: 'local' };
|
|
265
|
-
}
|
|
266
|
-
if (host) {
|
|
267
|
-
return getOptionGrid(options);
|
|
268
|
-
}
|
|
269
|
-
const companyId = company.companyId;
|
|
270
|
-
if (gridId) {
|
|
271
|
-
return getGridDataByGridId(companyId, gridId, allGrids);
|
|
272
|
-
}
|
|
273
|
-
if (grid) {
|
|
274
|
-
return getGridDataByGridName(companyId, grid, allGrids);
|
|
275
|
-
}
|
|
276
|
-
if (hasTestPlanFlag(options) || options.tunnelOnlyMode) {
|
|
277
|
-
logger.info('skipping getting grid, as it is set on test plan', { companyId });
|
|
278
|
-
return undefined;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
throw new GridError('Missing host or grid configuration');
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* @param {string} browser
|
|
286
|
-
* @param {string} executionId
|
|
287
|
-
* @param {import('../runOptions').RunnerOptions} options
|
|
288
|
-
* @param {number} workerId
|
|
289
|
-
*/
|
|
290
|
-
async function getGridSlot(browser, executionId, options, workerId) {
|
|
291
|
-
const getGridDataFromServer = async () => {
|
|
292
|
-
const { host, project, grid, gridId, useLocalChromeDriver, useChromeLauncher, company } = options;
|
|
293
|
-
const companyId = company?.companyId;
|
|
294
|
-
if (useLocalChromeDriver || useChromeLauncher) {
|
|
295
|
-
return { mode: 'local' };
|
|
296
|
-
}
|
|
297
|
-
if (host) {
|
|
298
|
-
return getOptionGrid(options);
|
|
299
|
-
}
|
|
300
|
-
if (gridId) {
|
|
301
|
-
return getHostAndPortById(workerId, companyId, project, gridId, browser, executionId);
|
|
302
|
-
}
|
|
303
|
-
if (grid) {
|
|
304
|
-
return getHostAndPortByName(workerId, companyId, project, grid, browser, executionId, options);
|
|
305
|
-
}
|
|
306
|
-
throw new GridError('Missing host or grid configuration');
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
const gridInfo = await getGridDataFromServer();
|
|
310
|
-
return gridInfo;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const handleHybridOrVendorIfNeeded = async (runnerOptions = { }, gridInfo = {}, testRunConfig = {}, lambdatestService = {}, retryConfig = {}) => {
|
|
314
|
-
const { company = {} } = runnerOptions;
|
|
315
|
-
const companyId = company.companyId;
|
|
316
|
-
const { gridId, type } = gridInfo;
|
|
317
|
-
const browser = runnerOptions.browser || testRunConfig.browserValue;
|
|
318
|
-
const usingTunnel = Boolean(runnerOptions.tunnel);
|
|
319
|
-
const { maxRetries, currentRetry } = retryConfig;
|
|
320
|
-
|
|
321
|
-
if (!gridId || !type) {
|
|
322
|
-
return gridInfo;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (type === gridTypes.LAMBDATEST) {
|
|
326
|
-
await lambdatestService.enableIfNeeded(gridInfo);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (type !== gridTypes.HYBRID || !companyId || !browser || !maxRetries || !currentRetry) {
|
|
330
|
-
return gridInfo;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const response = await servicesApi.getHybridGridProvider({ companyId, gridId, maxRetries, currentRetry, browser, usingTunnel });
|
|
334
|
-
logger.info('handling hybrid grid', { response, companyId });
|
|
335
|
-
const gridData = getSerializableObject({ ...gridInfo, ...response.connectionDetails, provider: response.provider });
|
|
336
|
-
if (response.provider !== 'lambdatest') {
|
|
337
|
-
lambdatestService.disable();
|
|
338
|
-
}
|
|
339
|
-
if (response.provider === 'lambdatest') {
|
|
340
|
-
await lambdatestService.enableIfNeeded(gridData);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return gridData;
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
module.exports = {
|
|
347
|
-
getGridSlot,
|
|
348
|
-
releaseGridSlot,
|
|
349
|
-
getGridData,
|
|
350
|
-
getTestPlanGridData,
|
|
351
|
-
addItemToGridCache,
|
|
352
|
-
keepAlive: {
|
|
353
|
-
start: startKeepAlive,
|
|
354
|
-
end: endKeepAlive,
|
|
355
|
-
},
|
|
356
|
-
handleHybridOrVendorIfNeeded,
|
|
357
|
-
};
|