@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,374 +0,0 @@
1
- 'use strict';
2
-
3
- const proxyquire = require('proxyquire').noCallThru();
4
- const { sinon, expect } = require('../../test/utils/testUtils');
5
- const os = require('os');
6
- const { NpmPermissionsError } = require('../errors');
7
- const path = require('path');
8
-
9
- const fs = require('fs');
10
-
11
- describe('npmWrapper', () => {
12
- describe('installPackageLocally', () => {
13
- describe('unit', () => {
14
- class ExecError extends Error {
15
- constructor(stderr) {
16
- super();
17
- this.stderr = stderr;
18
- }
19
- }
20
-
21
- let npmWrapper;
22
-
23
- let fakeChildProcess;
24
- let fakeLogger;
25
- let fakeFS;
26
- let originalConsole;
27
- beforeEach(() => {
28
- fakeChildProcess = { exec: sinon.stub() };
29
- fakeLogger = { warn: sinon.stub(), info: sinon.stub() };
30
- fakeFS = {
31
- promises: {
32
- access: sinon.stub().rejects(new Error()),
33
- },
34
- };
35
- originalConsole = global.console;
36
- global.console = { log: sinon.stub(), error: sinon.stub() };
37
-
38
- npmWrapper = proxyquire('./npmWrapper', {
39
- child_process: fakeChildProcess,
40
- fs: fakeFS,
41
- './logger': { getLogger: () => fakeLogger },
42
- });
43
- });
44
-
45
- afterEach(() => {
46
- global.console = originalConsole;
47
- });
48
-
49
- function stubExecRejection(err) {
50
- fakeChildProcess.exec.yields(undefined, Promise.reject(err));
51
- }
52
-
53
- it('should call npm with expected arguments', async () => {
54
- fakeChildProcess.exec.yields(undefined, []); //resolve without errors
55
- const cwd = '/some/dir';
56
- const pkg = 'some-package';
57
- const expectedCmd = 'npm i some-package --no-save --no-prune --prefer-offline --no-audit --progress=false';
58
- const expectedExecParams = { cwd };
59
-
60
- await npmWrapper.installPackageLocally(cwd, pkg);
61
-
62
- expect(fakeChildProcess.exec).to.have.been.calledOnce;
63
- const [cmd, execParams] = fakeChildProcess.exec.firstCall.args;
64
- expect(cmd).to.eql(expectedCmd);
65
- expect(execParams).to.eql(expectedExecParams);
66
- });
67
-
68
- it('should throw an error if nothing was printed to stderr', async () => {
69
- const execErr = new ExecError(undefined);
70
-
71
- stubExecRejection(execErr);
72
-
73
- await expect(npmWrapper.installPackageLocally('/some/dir', 'some-package')).to.be.rejectedWith(execErr);
74
- });
75
-
76
- it('should throw an error if an error which isnt related to permissions occurred', async () => {
77
- const execErr = new ExecError('not related, really');
78
-
79
- stubExecRejection(execErr);
80
-
81
- await expect(npmWrapper.installPackageLocally('/some/dir', 'some-package')).to.be.rejectedWith(execErr);
82
- });
83
-
84
- it('should throw an error if stderr includes "EACCES", but the path was not specified', async () => {
85
- const execErr = new ExecError('EACCES permission denied, oh no');
86
-
87
- stubExecRejection(execErr);
88
-
89
- await expect(npmWrapper.installPackageLocally('/some/dir', 'some-package')).to.be.rejectedWith(execErr);
90
- });
91
-
92
- [
93
- {
94
- stderr: 'EACCES\n\tpermission denied, access \'/some/path\'\n\t',
95
- expectedPath: '/some/path',
96
- },
97
- {
98
- stderr: `npm WARN @testim/testim-cli@3.108.0 No repository field.
99
- npm WARN @testim/testim-cli@3.108.0 license should be a valid SPDX license expression
100
-
101
- npm ERR! code EACCES
102
- npm ERR! syscall access
103
- npm ERR! path /usr/local/lib/node_modules/@testim/testim-cli/node_modules
104
- npm ERR! errno -13
105
- npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@testim/testim-cli/node_modules'
106
- npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@testim/testim-cli/node_modules'] {
107
- npm ERR! errno: -13,
108
- npm ERR! code: 'EACCES',
109
- npm ERR! syscall: 'access',
110
- npm ERR! path: '/usr/local/lib/node_modules/@testim/testim-cli/node_modules'
111
- npm ERR! }`,
112
- expectedPath: '/usr/local/lib/node_modules/@testim/testim-cli/node_modules',
113
- },
114
- ].forEach(({ stderr, expectedPath }) => {
115
- it(`should throw an NpmPermissionsError if stderr is ${stderr}`, async () => {
116
- const execErr = new ExecError(stderr);
117
-
118
- stubExecRejection(execErr);
119
-
120
- expect(npmWrapper.installPackageLocally('/some/dir', 'some-package')).to.be
121
- .rejectedWith(NpmPermissionsError, `Testim had missing write access to ${expectedPath}`);
122
- });
123
-
124
- it(`should print the path to console error if stderr is ${stderr}`, async () => {
125
- const execErr = new ExecError(stderr);
126
- const packageName = 'some-package';
127
- const expectedMessage = `
128
-
129
- Testim failed installing the package ${packageName} due to insufficient permissions.
130
- This is probably due to an installation of @testim/testim-cli with sudo, and running it without sudo.
131
- Testim had missing write access to ${expectedPath}
132
-
133
- `;
134
-
135
- stubExecRejection(execErr);
136
-
137
- try {
138
- await npmWrapper.installPackageLocally('/some/dir', packageName);
139
- } catch {
140
- //it doesn't really matter if an error was thrown or not
141
- } finally {
142
- // eslint-disable-next-line no-console
143
- expect(console.error).to.have.been.calledOnceWith(expectedMessage);
144
- }
145
- });
146
-
147
- it(`should log the error if stderr is ${stderr}`, async () => {
148
- const execErr = new ExecError(stderr);
149
- const packageName = 'some-package';
150
- const expectedInLog = {
151
- package: packageName,
152
- path: expectedPath,
153
- };
154
-
155
- stubExecRejection(execErr);
156
-
157
- try {
158
- await npmWrapper.installPackageLocally('/some/dir', packageName);
159
- } catch {
160
- //it doesn't really matter if an error was thrown or not
161
- } finally {
162
- // eslint-disable-next-line no-console
163
- expect(fakeLogger.info).to.have.been.calledOnce;
164
- const [message, body] = fakeLogger.info.firstCall.args;
165
- expect(message).to.eql('Failed to install package due to insufficient write access');
166
- expect(body).to.include(expectedInLog);
167
- }
168
- });
169
- });
170
- });
171
-
172
- describe('integration', () => {
173
- const npmWrapper = require('./npmWrapper');
174
-
175
- it('should install a package on the designated folder', async () => {
176
- const dirToInstall = path.resolve(os.tmpdir(), `runnerTest_npmWrapper_${Date.now()}`);
177
- const pkg = 'map-obj';
178
- fs.mkdirSync(dirToInstall);
179
- const expectedFile = path.resolve(dirToInstall, 'node_modules', pkg, 'package.json');
180
-
181
- await npmWrapper.installPackageLocally(dirToInstall, pkg);
182
-
183
- expect(fs.existsSync(expectedFile), 'expected package.json file to be generated').to.be.true;
184
- // eslint-disable-next-line import/no-dynamic-require
185
- expect(require(expectedFile).name, 'unexpected package was installed').to.be.eql(pkg);
186
- }).timeout(20000);
187
-
188
- it('should throw an NpmPermissionsError if npm had permission issues', async () => {
189
- const dirToInstall = path.resolve(os.tmpdir(), `runnerTest_npmWrapper_${Date.now()}`);
190
- fs.mkdirSync(dirToInstall);
191
- const nodeModulesDir = path.resolve(dirToInstall, 'node_modules');
192
- fs.mkdirSync(nodeModulesDir);
193
- fs.chmodSync(nodeModulesDir, '000'); //no permissions at all
194
- const pkg = 'map-obj';
195
- const unexpectedDir = path.resolve(nodeModulesDir, pkg);
196
-
197
- await expect(npmWrapper.installPackageLocally(dirToInstall, pkg)).to.be.rejectedWith(NpmPermissionsError);
198
-
199
- expect(fs.existsSync(unexpectedDir), 'expected the package not to be installed - this could be a problem with the test itself, and not the tested class').to.be.false;
200
- }).timeout(20000);
201
- });
202
-
203
- describe('shirnkwrap handling', () => {
204
- let fakeChildProcess;
205
- let fakeLogger;
206
- let originalConsole;
207
- const shrinkwrapPath = '/some/dir/npm-shrinkwrap.json';
208
- const shrinkwrapDummyPath = '/some/dir/npm-shrinkwrap-dummy.json';
209
- beforeEach(() => {
210
- fakeChildProcess = { exec: sinon.stub() };
211
- fakeLogger = { warn: sinon.stub(), info: sinon.stub() };
212
- originalConsole = global.console;
213
- global.console = { log: sinon.stub(), error: sinon.stub() };
214
- });
215
-
216
- afterEach(() => {
217
- global.console = originalConsole;
218
- });
219
-
220
- it('does not call rename if access fails', async () => {
221
- const fakeFS = {
222
- promises: {
223
- access: sinon.stub(),
224
- rename: sinon.stub(),
225
- },
226
- };
227
- fakeFS.promises.access.rejects();
228
- const npmWrapper = proxyquire('./npmWrapper', {
229
- child_process: fakeChildProcess,
230
- fs: fakeFS,
231
- './logger': { getLogger: () => fakeLogger },
232
- });
233
-
234
- fakeChildProcess.exec.yields(undefined, []); //resolve without errors
235
- const cwd = '/some/dir';
236
- const pkg = 'some-package';
237
- await npmWrapper.installPackageLocally(cwd, pkg);
238
- sinon.assert.calledOnce(fakeFS.promises.access);
239
- sinon.assert.notCalled(fakeFS.promises.rename);
240
- expect(fakeFS.promises.access.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
241
- });
242
-
243
- it('calls rename once if rename fails on the first time', async () => {
244
- const fakeFS = {
245
- promises: {
246
- access: sinon.stub().resolves(),
247
- rename: sinon.stub().rejects(),
248
- },
249
- };
250
-
251
- const npmWrapper = proxyquire('./npmWrapper', {
252
- child_process: fakeChildProcess,
253
- fs: fakeFS,
254
- './logger': { getLogger: () => fakeLogger },
255
- });
256
-
257
- fakeChildProcess.exec.yields(undefined, []); //resolve without errors
258
- const cwd = '/some/dir';
259
- const pkg = 'some-package';
260
- await npmWrapper.installPackageLocally(cwd, pkg);
261
- sinon.assert.calledOnce(fakeFS.promises.access);
262
- sinon.assert.calledOnce(fakeFS.promises.rename);
263
- });
264
-
265
- it('calls rename twice if first is success', async () => {
266
- const fakeFS = {
267
- promises: {
268
- access: sinon.stub().resolves(),
269
- rename: sinon.stub().resolves(),
270
- },
271
- };
272
- const npmWrapper = proxyquire('./npmWrapper', {
273
- child_process: fakeChildProcess,
274
- fs: fakeFS,
275
- './logger': { getLogger: () => fakeLogger },
276
- });
277
-
278
- fakeChildProcess.exec.yields(undefined, []); //resolve without errors
279
- const cwd = '/some/dir';
280
- const pkg = 'some-package';
281
-
282
- await npmWrapper.installPackageLocally(cwd, pkg);
283
- sinon.assert.calledOnce(fakeFS.promises.access);
284
- sinon.assert.calledTwice(fakeFS.promises.rename);
285
- expect(fakeFS.promises.access.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
286
- expect(fakeFS.promises.rename.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
287
- expect(fakeFS.promises.rename.getCall(0).args[1]).to.be.equal(shrinkwrapDummyPath);
288
- expect(fakeFS.promises.rename.getCall(1).args[0]).to.be.equal(shrinkwrapDummyPath);
289
- expect(fakeFS.promises.rename.getCall(1).args[1]).to.be.equal(shrinkwrapPath);
290
- });
291
-
292
- it('doesn\'t throw if first rename fails', async () => {
293
- const fakeFS = {
294
- promises: {
295
- access: sinon.stub().resolves(true),
296
- rename: sinon.stub().rejects(),
297
- },
298
- };
299
- const npmWrapper = proxyquire('./npmWrapper', {
300
- child_process: fakeChildProcess,
301
- fs: fakeFS,
302
- './logger': { getLogger: () => fakeLogger },
303
- });
304
-
305
- fakeChildProcess.exec.yields(undefined, []); //resolve without errors
306
- const cwd = '/some/dir';
307
- const pkg = 'some-package';
308
- await npmWrapper.installPackageLocally(cwd, pkg);
309
- sinon.assert.calledOnce(fakeFS.promises.access);
310
- sinon.assert.calledOnce(fakeFS.promises.rename);
311
- expect(fakeFS.promises.access.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
312
- expect(fakeFS.promises.rename.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
313
- expect(fakeFS.promises.rename.getCall(0).args[1]).to.be.equal(shrinkwrapDummyPath);
314
- });
315
-
316
- it('doesn\'t throw is second rename fails', async () => {
317
- const fakeFS = {
318
- promises: {
319
- access: sinon.stub().resolves(),
320
- rename: sinon.stub().onFirstCall().resolves().onSecondCall()
321
- .rejects(),
322
- },
323
- };
324
-
325
- const npmWrapper = proxyquire('./npmWrapper', {
326
- child_process: fakeChildProcess,
327
- fs: fakeFS,
328
- './logger': { getLogger: () => fakeLogger },
329
- });
330
-
331
- fakeChildProcess.exec.yields(undefined, []); //resolve without errors
332
- const cwd = '/some/dir';
333
- const pkg = 'some-package';
334
- await npmWrapper.installPackageLocally(cwd, pkg);
335
- sinon.assert.calledOnce(fakeFS.promises.access);
336
- sinon.assert.calledTwice(fakeFS.promises.rename);
337
- expect(fakeFS.promises.access.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
338
- expect(fakeFS.promises.rename.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
339
- expect(fakeFS.promises.rename.getCall(0).args[1]).to.be.equal(shrinkwrapDummyPath);
340
- expect(fakeFS.promises.rename.getCall(1).args[0]).to.be.equal(shrinkwrapDummyPath);
341
- expect(fakeFS.promises.rename.getCall(1).args[1]).to.be.equal(shrinkwrapPath);
342
- });
343
-
344
- it('calls rename even if exec fails', async () => {
345
- const fakeFS = {
346
- promises: {
347
- access: sinon.stub().resolves(),
348
- rename: sinon.stub().onFirstCall().resolves().onSecondCall()
349
- .rejects(),
350
- },
351
- };
352
-
353
- fakeChildProcess.exec.throws();
354
-
355
- const npmWrapper = proxyquire('./npmWrapper', {
356
- child_process: fakeChildProcess,
357
- fs: fakeFS,
358
- './logger': { getLogger: () => fakeLogger },
359
- });
360
-
361
- const cwd = '/some/dir';
362
- const pkg = 'some-package';
363
- await expect(npmWrapper.installPackageLocally(cwd, pkg)).to.be.rejected;
364
- sinon.assert.calledOnce(fakeFS.promises.access);
365
- sinon.assert.calledTwice(fakeFS.promises.rename);
366
- expect(fakeFS.promises.access.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
367
- expect(fakeFS.promises.rename.getCall(0).args[0]).to.be.equal(shrinkwrapPath);
368
- expect(fakeFS.promises.rename.getCall(0).args[1]).to.be.equal(shrinkwrapDummyPath);
369
- expect(fakeFS.promises.rename.getCall(1).args[0]).to.be.equal(shrinkwrapDummyPath);
370
- expect(fakeFS.promises.rename.getCall(1).args[1]).to.be.equal(shrinkwrapPath);
371
- });
372
- });
373
- });
374
- });
@@ -1,71 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- 'use strict';
4
-
5
- const MEASURE_TESTIM_CLI_PERFORMANCE = process.env.MEASURE_TESTIM_CLI_PERFORMANCE;
6
- const epoch = Date.now();
7
- let last = Date.now();
8
-
9
- module.exports = {
10
- log(...args) {
11
- if (!MEASURE_TESTIM_CLI_PERFORMANCE) {
12
- return;
13
- }
14
- const time = Date.now();
15
- console.log(`${time - epoch}\t\t\t${time - last}\t\t\t`, ...args);
16
- last = time;
17
- },
18
- measure(fn) {
19
- if (!MEASURE_TESTIM_CLI_PERFORMANCE) {
20
- return;
21
- }
22
- const start = Date.now();
23
- try {
24
- fn();
25
- } finally {
26
- console.log(fn.name, 'took', Date.now() - start);
27
- }
28
- },
29
- patchPromisePrototype() {
30
- // TODO: Stop monkey patching shit
31
- // eslint-disable-next-line no-extend-native
32
- Promise.prototype.log = function log(message) {
33
- if (!MEASURE_TESTIM_CLI_PERFORMANCE) {
34
- return this;
35
- }
36
- return this.then((v) => {
37
- module.exports.log(message);
38
- return v;
39
- });
40
- };
41
- },
42
- measureRequireTimes() {
43
- if (!MEASURE_TESTIM_CLI_PERFORMANCE) {
44
- return;
45
- }
46
- const {
47
- performance,
48
- PerformanceObserver,
49
- } = require('perf_hooks');
50
- const mod = require('module');
51
-
52
- // Monkey patch the require function
53
- mod.Module.prototype.require = performance.timerify(mod.Module.prototype.require);
54
- // TODO: Stop monkey patching shit
55
- // eslint-disable-next-line no-global-assign
56
- require = performance.timerify(require);
57
-
58
- // Activate the observer
59
- const obs = new PerformanceObserver((list) => {
60
- const entries = list.getEntries();
61
- entries.sort((a, b) => b.duration - a.duration).filter(x => x.duration > 1).forEach((entry) => {
62
- console.log(`require('${entry[0]}')`, entry.duration);
63
- });
64
- obs.disconnect();
65
- });
66
- obs.observe({ entryTypes: ['function'], buffered: true });
67
- },
68
- };
69
-
70
- // ew ~ Benji
71
- module.exports.patchPromisePrototype();
@@ -1,29 +0,0 @@
1
- const _ = require('lodash');
2
- const localRunnerCache = require('./runnerFileCache');
3
- const servicesApi = require('./testimServicesApi');
4
- const { promiseMap } = require('../utils');
5
-
6
-
7
- const TEN_HOURS = 1000 * 60 * 60 * 10;
8
-
9
- /**
10
- * @param {import('../runOptions').RunnerOptions} options
11
- */
12
- async function preloadTests(options) {
13
- if (!Array.isArray(options.testId) || !options.testId.length) {
14
- return {};
15
- }
16
- const opts = {
17
- branch: options.branch,
18
- projectId: options.project,
19
- };
20
- return await localRunnerCache.memoize(async () => {
21
- const results = await promiseMap(options.testId, testId => servicesApi.loadTest({ ...opts, testId }), { concurrency: 2 });
22
- return _.keyBy(results, 'testData.id');
23
- }, 'loadTests', TEN_HOURS, [opts, options.testId])();
24
- }
25
-
26
-
27
- module.exports = {
28
- preloadTests,
29
- };
@@ -1,85 +0,0 @@
1
- // @ts-check
2
-
3
- const { CLI_MODE } = require('./constants');
4
-
5
- const os = require('os');
6
- const utils = require('../utils');
7
- const Ajv = require('ajv');
8
- const prepareRunnerAndTestimStartUtils = require('./prepareRunnerAndTestimStartUtils');
9
- const mockNetworkRuleFileSchema = require('./mockNetworkRuleFileSchema.json');
10
- const { initializeUserWithAuth } = require('./initializeUserWithAuth');
11
- const { downloadAndInstallChromium } = require('../chromiumInstaller');
12
-
13
- const MAX_RULE_FILE_SIZE_IN_MB = 1;
14
- const PREPARE_MOCK_NETWORK_ERROR_PREFIX = 'JSON file supplied to --mock-network-pattern';
15
-
16
- const logger = require('./logger').getLogger('prepare runner');
17
-
18
- /** @param {import('../runOptions').RunnerOptions} options */
19
- async function prepare(options) {
20
- /**
21
- * @type {Promise<void>}
22
- */
23
- let chromedriverPromise = Promise.resolve();
24
-
25
- const hasNoGrid = !options.host && !options.gridId && !options.grid && (!options.testPlan || options.testPlan.length === 0);
26
- const isTdkRun = options.files.length !== 0;
27
- if ((hasNoGrid && isTdkRun) || options.useLocalChromeDriver) {
28
- options.chromeBinaryLocation = options.downloadBrowser ? await downloadAndInstallChromium() : options.chromeBinaryLocation;
29
- chromedriverPromise = prepareRunnerAndTestimStartUtils.prepareChromeDriver(
30
- { projectId: options.project, userId: options.user },
31
- { chromeBinaryLocation: options.chromeBinaryLocation },
32
- Boolean(options.lightweightMode?.general)
33
- );
34
- options.useLocalChromeDriver = true;
35
- }
36
-
37
- if (!options.playerRequirePath && options.mode !== CLI_MODE.EXTENSION) {
38
- await prepareRunnerAndTestimStartUtils.preparePlayer(options.playerLocation, options.canary);
39
- }
40
- if (options.mode === CLI_MODE.EXTENSION && !options.ext) {
41
- await prepareRunnerAndTestimStartUtils.prepareExtension(options.extensionLocation);
42
- }
43
-
44
- let customExtensionLocation;
45
-
46
- if (options.installCustomExtension) {
47
- const unlimitedSize = Boolean(options.useLocalChromeDriver || options.useChromeLauncher);
48
- customExtensionLocation = await prepareRunnerAndTestimStartUtils.prepareCustomExtension(options.installCustomExtension, unlimitedSize);
49
- }
50
-
51
- await chromedriverPromise;
52
-
53
- return customExtensionLocation;
54
- }
55
-
56
- async function prepareMockNetwork(location) {
57
- logger.info('prepare MockNetwork', { location });
58
- const _rulesJson = await utils.getSourceAsBuffer(location);
59
- const rulesJsonBuf = Buffer.isBuffer(_rulesJson) ? _rulesJson : _rulesJson.body;
60
- if (rulesJsonBuf.byteLength > MAX_RULE_FILE_SIZE_IN_MB * 1000000) {
61
- throw new Error(`${PREPARE_MOCK_NETWORK_ERROR_PREFIX} exceeded ${MAX_RULE_FILE_SIZE_IN_MB}MB`);
62
- }
63
-
64
- let rulesJson;
65
- try {
66
- rulesJson = JSON.parse(rulesJsonBuf.toString('utf-8'));
67
- } catch (error) {
68
- throw new Error(`${PREPARE_MOCK_NETWORK_ERROR_PREFIX} cannot be parsed.${os.EOL}${error}`);
69
- }
70
-
71
- const ajv = new Ajv();
72
- const valid = ajv.validate(mockNetworkRuleFileSchema, rulesJson);
73
- if (!valid) {
74
- const errors = ajv.errors?.map((e, i) => `${++i}) ${e.dataPath} ${e.message}`).join(os.EOL);
75
- throw new Error(`${PREPARE_MOCK_NETWORK_ERROR_PREFIX} is malformed.${os.EOL}${errors}`);
76
- }
77
-
78
- return rulesJson.entries;
79
- }
80
-
81
- module.exports = {
82
- prepare,
83
- prepareMockNetwork,
84
- initializeUserWithAuth,
85
- };