@testim/testim-cli 3.289.0 → 3.290.0

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 +1951 -203
  4. package/package.json +9 -5
  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 -13
  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,144 +0,0 @@
1
- const { sinon, expect } = require('../../test/utils/testUtils');
2
- const utils = require('../utils');
3
- const { prepareMockNetwork } = require('./prepareRunner');
4
-
5
- describe('prepareRunner', () => {
6
- describe('prepareMockNetwork', () => {
7
- const localFileUrl = './rules.json';
8
- const remoteFileUrl = 'https://s3/testim/files/rules.json';
9
- let getSourceAsBufferStub;
10
-
11
- beforeEach(() => {
12
- getSourceAsBufferStub = sinon.stub(utils, 'getSourceAsBuffer');
13
- });
14
-
15
- afterEach(() => {
16
- sinon.restore();
17
- });
18
-
19
- it('prepareMockNetwork rejected with - exceeded 1MB', () => {
20
- // Arrange:
21
- const buf = Buffer.alloc(1000001);
22
- getSourceAsBufferStub.withArgs(localFileUrl).returns(Promise.resolve(buf));
23
-
24
- // Act:
25
- const mockNetworkRules = prepareMockNetwork(localFileUrl);
26
-
27
- // Assert:
28
- sinon.assert.calledOnce(getSourceAsBufferStub);
29
- return expect(mockNetworkRules).to.be.rejectedWith('exceeded 1MB');
30
- });
31
-
32
- it('prepareMockNetwork rejected with - cannot be parsed', () => {
33
- // Arrange:
34
- const buf = Buffer.from('{a: 1}');
35
- getSourceAsBufferStub.withArgs(localFileUrl).returns(Promise.resolve(buf));
36
-
37
- // Act:
38
- const mockNetworkRules = prepareMockNetwork(localFileUrl);
39
-
40
- // Assert:
41
- sinon.assert.calledOnce(getSourceAsBufferStub);
42
- return expect(mockNetworkRules).to.be.rejectedWith('cannot be parsed');
43
- });
44
-
45
- it('prepareMockNetwork rejected with - is malformed', () => {
46
- // Arrange:
47
- const buf1 = Buffer.from('{"a": 1}');
48
- const buf2 = Buffer.from(JSON.stringify({
49
- version: '2.0.0',
50
- entries: [],
51
- }));
52
- const buf3 = Buffer.from(Buffer.from(JSON.stringify({
53
- version: '1.0.0',
54
- entries: [{
55
- request: {
56
- url: '/test/*',
57
- },
58
- }],
59
- })));
60
- const buf4 = Buffer.from(Buffer.from(JSON.stringify({
61
- version: '1.0.0',
62
- entries: [{
63
- request: {
64
- url: '/test/*',
65
- method: 'POSTTTTT',
66
- },
67
- response: {
68
- status: 200,
69
- },
70
- }],
71
- })));
72
- const buf5 = Buffer.from(Buffer.from(JSON.stringify({
73
- version: '1.0.0',
74
- entries: [{
75
- request: {
76
- url: '/test/*',
77
- },
78
- response: {
79
- status: 600,
80
- },
81
- }],
82
- })));
83
- const buf6 = Buffer.from(Buffer.from(JSON.stringify({
84
- version: '1.0.0',
85
- entries: [{
86
- request: {
87
- url: '/test/*',
88
- },
89
- response: {
90
- status: 400.1,
91
- },
92
- }],
93
- })));
94
- getSourceAsBufferStub.withArgs(`${remoteFileUrl}.1`).returns(Promise.resolve(buf1));
95
- getSourceAsBufferStub.withArgs(`${remoteFileUrl}.2`).returns(Promise.resolve(buf2));
96
- getSourceAsBufferStub.withArgs(`${remoteFileUrl}.3`).returns(Promise.resolve(buf3));
97
- getSourceAsBufferStub.withArgs(`${remoteFileUrl}.4`).returns(Promise.resolve(buf4));
98
- getSourceAsBufferStub.withArgs(`${remoteFileUrl}.5`).returns(Promise.resolve(buf5));
99
- getSourceAsBufferStub.withArgs(`${remoteFileUrl}.6`).returns(Promise.resolve(buf6));
100
-
101
- // Act:
102
- const mockNetworkRules1 = prepareMockNetwork(`${remoteFileUrl}.1`);
103
- const mockNetworkRules2 = prepareMockNetwork(`${remoteFileUrl}.2`);
104
- const mockNetworkRules3 = prepareMockNetwork(`${remoteFileUrl}.3`);
105
- const mockNetworkRules4 = prepareMockNetwork(`${remoteFileUrl}.4`);
106
- const mockNetworkRules5 = prepareMockNetwork(`${remoteFileUrl}.5`);
107
- const mockNetworkRules6 = prepareMockNetwork(`${remoteFileUrl}.6`);
108
-
109
- // Assert:
110
- return Promise.all([
111
- expect(mockNetworkRules1).to.be.rejectedWith('is malformed'),
112
- expect(mockNetworkRules2).to.be.rejectedWith('is malformed'),
113
- expect(mockNetworkRules3).to.be.rejectedWith('is malformed'),
114
- expect(mockNetworkRules4).to.be.rejectedWith('is malformed'),
115
- expect(mockNetworkRules5).to.be.rejectedWith('is malformed'),
116
- expect(mockNetworkRules6).to.be.rejectedWith('is malformed'),
117
- ]);
118
- });
119
-
120
- it('prepareMockNetwork is fine', () => {
121
- // Arrange:
122
- const buf = Buffer.from(JSON.stringify({
123
- version: '1.2',
124
- entries: [{
125
- request: {
126
- url: '/test/*',
127
- method: 'POST',
128
- },
129
- response: {
130
- status: 400,
131
- },
132
- }],
133
- }));
134
- getSourceAsBufferStub.withArgs(localFileUrl).returns(Promise.resolve(buf));
135
-
136
- // Act:
137
- const mockNetworkRules = prepareMockNetwork(localFileUrl);
138
-
139
- // Assert:
140
- sinon.assert.calledOnce(getSourceAsBufferStub);
141
- return expect(mockNetworkRules).to.be.fulfilled;
142
- });
143
- });
144
- });
@@ -1,198 +0,0 @@
1
- // @ts-check
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const ms = require('ms');
6
- const { serializeError } = require('serialize-error');
7
- const { additionalLogDetails } = require('./logUtils');
8
-
9
- const config = require('./config');
10
- const { ArgError, NpmPermissionsError } = require('../errors');
11
- const {
12
- getCliLocation,
13
- isURL,
14
- downloadAndSave,
15
- getSource,
16
- getLocalFileSizeInMB,
17
- download,
18
- unzipFile,
19
- getSourcePath,
20
- promiseMap,
21
- } = require('../utils');
22
- const localRunnerCache = require('./runnerFileCache');
23
- const logger = require('./logger').getLogger('prepare runner and testim start');
24
-
25
- const MSEC_IN_HALF_DAY = ms('0.5 day');
26
- const MAX_CUSTOM_EXT_SIZE_MB = 16;
27
- const MAX_CUSTOM_SIZE_ERROR_MSG = `The size of the custom extension is more than ${MAX_CUSTOM_EXT_SIZE_MB}MB`;
28
-
29
- module.exports = {
30
- prepareChromeDriver,
31
- prepareCustomExtension,
32
- prepareExtension,
33
- getSessionPlayerFolder,
34
- preparePlayer,
35
- };
36
-
37
- /**
38
- * @param {string} location
39
- */
40
- async function prepareCustomExtension(location, unlimitedSize = false) {
41
- if (!location) {
42
- return undefined;
43
- }
44
-
45
- if (isURL(location)) {
46
- const destFile = path.join(process.cwd(), location.replace(/^.*[\\\/]/, ''));
47
- const contentLength = await getRemoteFileSizeInMB(location);
48
- if (contentLength > MAX_CUSTOM_EXT_SIZE_MB && !unlimitedSize) {
49
- throw new ArgError(MAX_CUSTOM_SIZE_ERROR_MSG);
50
- }
51
- await downloadAndSave(location, destFile);
52
- return destFile;
53
- }
54
-
55
- const destFile = path.resolve(location);
56
- if (!fs.existsSync(destFile)) {
57
- throw new ArgError(`Failed to find custom extension in location: ${destFile}`);
58
- }
59
- const fileSize = getLocalFileSizeInMB(destFile);
60
- if (fileSize > MAX_CUSTOM_EXT_SIZE_MB && !unlimitedSize) {
61
- throw new ArgError(MAX_CUSTOM_SIZE_ERROR_MSG);
62
- }
63
- return destFile;
64
- }
65
-
66
-
67
- /**
68
- * @param {string} url
69
- */
70
- async function getRemoteFileSizeInMB(url) {
71
- const httpRequest = require('./httpRequest');
72
- try {
73
- const res = await httpRequest.head(url);
74
- const contentLengthHeader = res.headers['content-length'];
75
- const contentLengthBytes = contentLengthHeader ? parseInt(contentLengthHeader, 10) : 0;
76
- return contentLengthBytes / 1000000;
77
- } catch (err) {
78
- logger.warn('failed to download custom extension', { err });
79
- throw new ArgError(`Failed to download custom extension from location: ${url}`);
80
- }
81
- }
82
-
83
- /**
84
- * @param {string[]} locations
85
- */
86
- function prepareExtension(locations) {
87
- logger.info('prepare extension', { locations });
88
-
89
- const fullLocations = locations.map(location => ({ location, path: getSourcePath(location) }));
90
- return localRunnerCache.memoize(
91
- () => promiseMap(fullLocations, ({ location, path }) => getSource(location, path)),
92
- 'prepareExtension',
93
- MSEC_IN_HALF_DAY,
94
- fullLocations
95
- )();
96
- }
97
-
98
- async function prepareChromeDriver(userDetails = {}, driverOptions = {}, skipIsReadyCheck = false) {
99
- const ora = require('ora');
100
- const spinner = ora('Starting Driver').start();
101
- const chromedriverWrapper = require('./chromedriverWrapper');
102
-
103
- try {
104
- await chromedriverWrapper.install();
105
- await chromedriverWrapper.start();
106
- if (!skipIsReadyCheck) {
107
- // @ts-ignore
108
- await chromedriverWrapper.isReady(driverOptions);
109
- }
110
- spinner.succeed('Chrome Driver initiated successfully');
111
- } catch (error) {
112
- const errorMsg = 'Failed to initiate Chrome Driver';
113
-
114
- if (!(error instanceof NpmPermissionsError)) { //NpmPermissionsError was printed and logged already
115
- logger.error(errorMsg, {
116
- ...userDetails,
117
- ...additionalLogDetails(),
118
- error: serializeError(error),
119
- });
120
- // eslint-disable-next-line no-console
121
- console.log(`
122
- 1. If you don't have Chrome, please install it from https://www.google.com/chrome.
123
- 2. If Chrome is installed, please verify it's binary directory:
124
- - installed where chromedriver expects it (see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver#requirements).
125
- - exists in your PATH environment variables.
126
- 3. Try adding --chrome-binary-location flag to Testim CLI specifying the exact location of chrome binary in your computer (e.g on Windows "C:/Program Files/Google/Chrome/Application/chrome.exe").
127
- 4. You can always use a standalone Selenium grid and providing it's details with the --host and --port flags (see https://www.npmjs.com/package/selenium-standalone)`);
128
- }
129
-
130
- spinner.fail(errorMsg);
131
- throw error;
132
- }
133
- }
134
-
135
- async function getPlayerVersion() {
136
- const url = `${config.BLOB_URL}/extension/sessionPlayer_LATEST_RELEASE`;
137
- const res = await download(url);
138
- return res.body.toString('utf8');
139
- }
140
-
141
- /**
142
- * @param {string} location
143
- * @param {boolean=} canary
144
- */
145
- async function getPlayerLocation(location, canary) {
146
- if (!isURL(location) || (isURL(location) && canary) || config.IS_ON_PREM) {
147
- return location;
148
- }
149
-
150
- const ver = await getPlayerVersion();
151
- return `${location}-${ver}`;
152
- }
153
-
154
- function getSessionPlayerFolder() {
155
- const cliLocation = getCliLocation();
156
-
157
- return path.resolve(cliLocation, 'testim-bin');
158
- }
159
-
160
- function getPlayerDestination() {
161
- const testimAppData = getSessionPlayerFolder();
162
-
163
- const playerDestination = path.resolve(testimAppData, 'sessionPlayer.zip');
164
-
165
- return playerDestination;
166
- }
167
-
168
- async function downloadAndUnzip(loc, playerFileName, isRetry = false) {
169
- try {
170
- await getSource(loc, playerFileName);
171
- return await unzipFile(playerFileName, getSessionPlayerFolder());
172
- } catch (err) {
173
- if (isRetry) {
174
- throw err;
175
- }
176
- return await downloadAndUnzip(loc, playerFileName, true);
177
- }
178
- }
179
-
180
- /**
181
- * @param {string} location
182
- * @param {boolean=} canary
183
- */
184
- async function preparePlayer(location, canary) {
185
- logger.info('prepare player', { location, canary });
186
- const playerFileName = getPlayerDestination();
187
- return localRunnerCache.memoize(
188
- async () => {
189
- const loc = await getPlayerLocation(location, canary);
190
- await downloadAndUnzip(loc, playerFileName);
191
- // return a truthy value, so the caching has a value, and doesn't ignore
192
- return {};
193
- },
194
- 'preparePlayer',
195
- MSEC_IN_HALF_DAY,
196
- [location, canary, playerFileName]
197
- )();
198
- }
@@ -1,73 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- 'use strict';
4
-
5
- const { sinon, expect } = require('../../test/utils/testUtils');
6
- const proxyquire = require('proxyquire').noCallThru();
7
- const { NpmPermissionsError } = require('../errors');
8
-
9
- describe('prepareRunnerAndTestimStartUtils', () => {
10
- describe('prepareChromeDriver', () => {
11
- let prepareChromeDriver;
12
- let chromeDriverWrapper;
13
-
14
- beforeEach(() => {
15
- chromeDriverWrapper = {
16
- install: sinon.stub(),
17
- start: sinon.stub(),
18
- isReady: sinon.stub(),
19
- };
20
- prepareChromeDriver = proxyquire('./prepareRunnerAndTestimStartUtils', {
21
- './chromedriverWrapper': chromeDriverWrapper,
22
- }).prepareChromeDriver;
23
- });
24
-
25
- afterEach(() => {
26
- sinon.restore();
27
- });
28
-
29
- it('should call install and start chromedriver', async () => {
30
- chromeDriverWrapper.install.resolves();
31
- chromeDriverWrapper.start.resolves();
32
- chromeDriverWrapper.isReady.resolves();
33
- const driverOptions = { someOption: 'option' };
34
-
35
- await prepareChromeDriver({ name: 'some username' }, driverOptions);
36
-
37
- expect(chromeDriverWrapper.install).to.have.been.calledOnce;
38
- expect(chromeDriverWrapper.start).to.have.been.calledOnce;
39
- expect(chromeDriverWrapper.isReady).to.have.been.calledOnceWithExactly(driverOptions);
40
- });
41
-
42
- it('should throw if an NpmPermissionsError was thrown while installing', async () => {
43
- const error = new NpmPermissionsError('/path/with/no/access');
44
- chromeDriverWrapper.install.rejects(error);
45
-
46
- expect(prepareChromeDriver()).to.be.rejectedWith(error);
47
- });
48
-
49
- it('should throw if an Error was thrown while starting', async () => {
50
- const error = new Error('oh noes');
51
- chromeDriverWrapper.install.resolves();
52
- chromeDriverWrapper.start.rejects(error);
53
-
54
- expect(prepareChromeDriver()).to.be.rejectedWith(error);
55
- });
56
-
57
- it('should print instructions if Error was thrown while starting', async () => {
58
- sinon.stub(console, 'log');
59
- const error = new Error('oh noes');
60
- chromeDriverWrapper.install.resolves();
61
- chromeDriverWrapper.start.rejects(error);
62
-
63
- await expect(prepareChromeDriver()).to.be.rejected;
64
- expect(console.log).to.have.been.calledOnceWith(`
65
- 1. If you don't have Chrome, please install it from https://www.google.com/chrome.
66
- 2. If Chrome is installed, please verify it's binary directory:
67
- - installed where chromedriver expects it (see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver#requirements).
68
- - exists in your PATH environment variables.
69
- 3. Try adding --chrome-binary-location flag to Testim CLI specifying the exact location of chrome binary in your computer (e.g on Windows "C:/Program Files/Google/Chrome/Application/chrome.exe").
70
- 4. You can always use a standalone Selenium grid and providing it's details with the --host and --port flags (see https://www.npmjs.com/package/selenium-standalone)`);
71
- });
72
- });
73
- });
@@ -1,25 +0,0 @@
1
- /* eslint-disable import/no-dynamic-require */
2
-
3
- 'use strict';
4
-
5
- const path = require('path');
6
-
7
- module.exports = {
8
- requireWithFallback,
9
- };
10
-
11
- /**
12
- * Require with statCache issue workaround
13
- * @param {string} packageNama
14
- */
15
- function requireWithFallback(packageNama) {
16
- // Workaround for
17
- // https://github.com/nodejs/node/issues/31803 statCache
18
- const mainPath = path.resolve(
19
- path.dirname(require.resolve(`${packageNama}/package.json`)),
20
- // @ts-ignore
21
- require(`${packageNama}/package.json`).main || ''
22
- );
23
-
24
- return require(mainPath);
25
- }
@@ -1,204 +0,0 @@
1
- // @ts-check
2
-
3
- 'use strict';
4
-
5
- const path = require('path');
6
- const debounce = require('lodash/debounce');
7
- const fs = require('fs');
8
- const { getCliLocation } = require('../utils');
9
-
10
- const logger = require('./logger').getLogger('local cache');
11
- const crypto = require('crypto');
12
- const utils = require('../utils');
13
-
14
- let cacheLocation = path.resolve(getCliLocation(), 'testim-cache');
15
-
16
- let encryptKeyResolve;
17
- let encryptAndSaveResolve;
18
- let cacheEnabled = true;
19
- let cacheMissAllowed = true;
20
- let waitingForSave = false;
21
-
22
- let _encryptAndSavePromise = new Promise(resolve => { encryptAndSaveResolve = resolve; });
23
- const _encryptKeyPromise = new Promise(resolve => { encryptKeyResolve = resolve; });
24
-
25
-
26
- const THREE_HOURS = 1000 * 60 * 60 * 3;
27
-
28
- const getCacheFileLocation = () => path.resolve(path.resolve(cacheLocation, 'testim.cache'));
29
-
30
- async function getLocalRunnerCache() {
31
- try {
32
- return await utils.promiseTimeout(
33
- fs.promises.readFile(getCacheFileLocation()).then(async buffer => {
34
- const key = await _encryptKeyPromise;
35
- return decrypt(key, buffer);
36
- }),
37
- 30_000,
38
- );
39
- } catch {
40
- return {};
41
- }
42
- }
43
-
44
- let localRunnerCache = getLocalRunnerCache();
45
-
46
- async function doesPathExist(dirPath) {
47
- try {
48
- await fs.promises.access(dirPath, fs.constants.F_OK);
49
- return true;
50
- } catch (err) {
51
- if (err.code === 'ENOENT') {
52
- return false;
53
- }
54
-
55
- // no permissions to check
56
- throw err;
57
- }
58
- }
59
-
60
- const encryptAndSave = debounce(async (object) => {
61
- let error;
62
- try {
63
- const key = await _encryptKeyPromise;
64
- const iv = crypto.randomBytes(16);
65
- const objStr = JSON.stringify(object);
66
- const keyBuffer = Buffer.from(key);
67
- const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.concat([keyBuffer, Buffer.alloc(32)], 32), iv);
68
- const result = Buffer.concat([iv, cipher.update(objStr), cipher.final()]);
69
- const pathExists = await doesPathExist(cacheLocation);
70
- if (!pathExists) {
71
- await fs.promises.mkdir(cacheLocation, { recursive: true });
72
- }
73
- await fs.promises.writeFile(getCacheFileLocation(), result);
74
- } catch (err) {
75
- logger.error('failed saving cache', { err });
76
- error = err;
77
- }
78
- if (error) {
79
- encryptAndSaveResolve({ success: false, error });
80
- } else {
81
- encryptAndSaveResolve({ success: true });
82
- }
83
- }, 200);
84
-
85
- function decrypt(key, buffer) {
86
- const iv = buffer.slice(0, 16);
87
- const encryptedText = buffer.slice(16);
88
- const keyBuffer = Buffer.from(key);
89
- const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.concat([keyBuffer, Buffer.alloc(32)], 32), iv);
90
- const decrypted = decipher.update(encryptedText);
91
- // @ts-ignore
92
- return JSON.parse(Buffer.concat([decrypted, decipher.final()]));
93
- }
94
- /**
95
- * argument-less memoize for functions with a global cache name
96
- * @template T
97
- * @param {() => PromiseLike<T>} fn
98
- * @param {string} fnName
99
- * @param {number=} duration
100
- * @param {*} parameters
101
- * @returns {() => Promise<Awaited<T>>}
102
- */
103
- function memoize(fn, fnName, duration = THREE_HOURS, parameters = undefined) {
104
- return async () => {
105
- if (!cacheEnabled) {
106
- return await fn();
107
- }
108
- const originalFnName = fnName;
109
- if (parameters) {
110
- fnName += JSON.stringify(parameters);
111
- }
112
- const cached = await get(fnName);
113
- if (cached) {
114
- logger.debug('cache hit:', { fnName });
115
- return cached;
116
- }
117
- logger.debug('cache miss:', { fnName });
118
- if (!cacheMissAllowed) {
119
- throw new Error(`Attempted to rebuild cache for ${originalFnName}. cache miss is not allowed with current run configuration`);
120
- }
121
- const value = await fn();
122
- if (value) {
123
- await set(fnName, value, duration);
124
- }
125
- return value;
126
- };
127
- }
128
-
129
- async function get(key) {
130
- const obj = await localRunnerCache;
131
- const valueExpiry = obj[key];
132
- if (!valueExpiry) {
133
- return undefined; // not in cache
134
- }
135
- const { value, expiry } = valueExpiry;
136
- if (expiry < Date.now()) {
137
- return undefined;
138
- }
139
- if (!value) {
140
- return undefined;
141
- }
142
- return value;
143
- }
144
-
145
- async function set(key, value, ttl) {
146
- if (waitingForSave) {
147
- logger.error('calling set after waitForSave is not allowed', { key, ttl });
148
- throw new Error('calling set after waitForSave is not allowed');
149
- }
150
- try {
151
- const obj = await localRunnerCache;
152
- obj[key] = { value, expiry: Date.now() + ttl };
153
- _encryptAndSavePromise = new Promise(resolve => { encryptAndSaveResolve = resolve; });
154
- encryptAndSave(obj);
155
- } catch (e) {
156
- logger.error('failed updating cache');
157
- }
158
- }
159
-
160
- async function clear() {
161
- const obj = await localRunnerCache;
162
- Object.keys(obj).forEach(key => {
163
- delete obj[key];
164
- });
165
- }
166
-
167
- function setEnabled(enabled) {
168
- cacheEnabled = enabled;
169
- }
170
-
171
-
172
- function enableCacheMiss(enabled) {
173
- cacheMissAllowed = enabled;
174
- }
175
-
176
- async function waitForSave() {
177
- try {
178
- waitingForSave = true;
179
- return await _encryptAndSavePromise;
180
- } finally {
181
- waitingForSave = false;
182
- }
183
- }
184
-
185
- function setCacheLocation(location) {
186
- cacheLocation = location;
187
- localRunnerCache = getLocalRunnerCache();
188
- }
189
-
190
- module.exports.setEncryptKey = encryptKeyResolve;
191
- module.exports.memoize = memoize;
192
- module.exports.get = get;
193
-
194
- module.exports.set = set;
195
- module.exports.clear = clear;
196
- module.exports.disable = setEnabled.bind(this, false);
197
- module.exports.enable = setEnabled.bind(this, true);
198
- module.exports.isEnabled = function () { return cacheEnabled; };
199
- module.exports.disableCacheMiss = enableCacheMiss.bind(this, false);
200
- module.exports.enableCacheMiss = enableCacheMiss.bind(this, true);
201
- module.exports.isEnabled = function () { return cacheEnabled; };
202
- module.exports.setCacheLocation = setCacheLocation;
203
- module.exports.waitForSave = waitForSave;
204
- module.exports.getCacheFileLocation = getCacheFileLocation;