@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
package/commons/logger.js DELETED
@@ -1,178 +0,0 @@
1
- 'use strict';
2
-
3
- const winston = require('winston');
4
- const os = require('os');
5
-
6
- const hostname = os.hostname();
7
- const runnerVersion = getRunnerVersion();
8
- const config = require('./config');
9
-
10
- const isLocal = 'false';
11
-
12
-
13
- const loggerConfig = {
14
- privateKey: 'd0eb01da-f966-1663-63c6-8871225d7c39',
15
- applicationName: 'testim',
16
- subsystemName: 'runner',
17
- };
18
-
19
- function getRunnerVersion() {
20
- try {
21
- const pack = require(`${__dirname}/../package.json`);
22
- return pack.version;
23
- } catch (err) {
24
- return '';
25
- }
26
- }
27
-
28
- function getStreamsAndWaitForFlushPromise() {
29
- const transports = [];
30
-
31
- let waitForFlush = () => Promise.resolve();
32
-
33
- if (!config.IS_ON_PREM) {
34
- const { CoralogixTransport } = require('../lib/coralogix-winston.transport');
35
-
36
- CoralogixTransport.configure(loggerConfig);
37
- const loggerInstance = new CoralogixTransport({
38
- category: 'ROOT',
39
- });
40
- transports.push(loggerInstance);
41
-
42
- waitForFlush = () => loggerInstance.waitForFlush();
43
- }
44
-
45
- if (config.LOGGER_CONSOLE) {
46
- transports.push(new winston.transports.Console({
47
- format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
48
- }));
49
- }
50
- return [transports, waitForFlush];
51
- }
52
-
53
- const [transports, waitForFlush] = getStreamsAndWaitForFlushPromise();
54
- const level = config.LOGGER_DEBUG ? 'debug' : 'info';
55
- const defaultMeta = {};
56
- if (!isLocal.includes('@echo')) {
57
- Object.assign(defaultMeta, devFlags());
58
-
59
- } else {
60
- Object.assign(defaultMeta, localFlags());
61
- }
62
-
63
- const winstonMainLogger = winston.createLogger({
64
- levels: winston.config.syslog.levels,
65
- level,
66
- transports,
67
- defaultMeta: { name: 'runner', hostname, nodeVersion: process.version, runnerVersion, ...defaultMeta },
68
- });
69
-
70
- let executionId = null;
71
- let projectId = null;
72
-
73
- function setExecutionId(execId) {
74
- executionId = execId;
75
- }
76
-
77
- function setProjectId(projId) {
78
- projectId = projId;
79
- }
80
-
81
- function setProxyUri(proxyUri) {
82
- if (config.IS_ON_PREM || !proxyUri) {
83
- return;
84
- }
85
- const { CoralogixTransport } = require('../lib/coralogix-winston.transport');
86
- CoralogixTransport.configure({ ...loggerConfig, proxyUri });
87
- }
88
-
89
- function releaseFlags() {
90
- return {
91
- release: true,
92
- branch: 'production',
93
- };
94
- }
95
-
96
- function devFlags() {
97
- return {
98
- release: false,
99
- branch: 'test',
100
- };
101
- }
102
-
103
- function localFlags() {
104
- return {
105
- release: false,
106
- branch: 'local',
107
- };
108
- }
109
-
110
- function addExecutionMetadata(dataExecutionId) {
111
- const logData = {};
112
- if (executionId && !dataExecutionId) {
113
- logData.executionId = executionId;
114
- }
115
-
116
- logData.projectId = projectId;
117
- logData.time = (new Date()).toISOString();
118
-
119
- return logData;
120
- }
121
-
122
- class Logger {
123
- constructor(logger) {
124
- this._logger = logger;
125
- this.debug = this.debug.bind(this);
126
- this.info = this.info.bind(this);
127
- this.warn = this.warn.bind(this);
128
- this.error = this.error.bind(this);
129
- this.fatal = this.fatal.bind(this);
130
- }
131
-
132
- debug(msg, data = {}) {
133
- this.innerLog('debug', msg, data);
134
- }
135
-
136
- info(msg, data = {}) {
137
- this.innerLog('info', msg, data);
138
- }
139
-
140
- warn(msg, data = {}) {
141
- this.innerLog('warning', msg, data);
142
- }
143
-
144
- error(msg, data = {}) {
145
- this.innerLog('error', msg, data);
146
- }
147
-
148
- fatal(msg, data = {}) {
149
- this.innerLog('crit', msg, data);
150
- }
151
-
152
- innerLog(logLevel, msg, data = {}) {
153
- try {
154
- this._logger.log(logLevel, Object.assign({ meta: data }, { message: msg }, addExecutionMetadata(data.executionId)));
155
- } catch (err) {
156
- try {
157
- this._logger.log('crit', Object.assign({ message: `failed to log message ${err.message}, ${err.stack}` }, addExecutionMetadata(data.executionId)));
158
- } catch (_err) {
159
- // well what can we do
160
- }
161
- }
162
- }
163
-
164
- waitForFlush() {
165
- return waitForFlush();
166
- }
167
- }
168
-
169
- function getLogger(loggerName) {
170
- return new Logger(winstonMainLogger.child({ category: loggerName }));
171
- }
172
-
173
- module.exports = {
174
- getLogger,
175
- setExecutionId,
176
- setProjectId,
177
- setProxyUri,
178
- };
@@ -1,140 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "definitions": {
4
- "request": {
5
- "type": "object",
6
- "required": ["url"],
7
- "additionalProperties": false,
8
- "properties": {
9
- "url": { "type": "string" },
10
- "method": {
11
- "type": "string",
12
- "pattern": "^GET$|^HEAD$|^POST$|^PUT$|^DELETE$|^CONNECT$|^OPTIONS$|^TRACE$|^PATCH$"
13
- }
14
- }
15
- },
16
- "header": {
17
- "type": "object",
18
- "required": [
19
- "name",
20
- "value"
21
- ],
22
- "additionalProperties": false,
23
- "properties": {
24
- "name": {
25
- "type": "string"
26
- },
27
- "value": {
28
- "type": "string"
29
- }
30
- }
31
- },
32
- "cookie": {
33
- "type": "object",
34
- "required": [
35
- "name",
36
- "value"
37
- ],
38
- "additionalProperties": false,
39
- "properties": {
40
- "name": {
41
- "type": "string"
42
- },
43
- "value": {
44
- "type": "string"
45
- },
46
- "path": {
47
- "type": "string"
48
- },
49
- "domain": {
50
- "type": "string"
51
- },
52
- "expires": {
53
- "type": "string",
54
- "format": "date-time"
55
- },
56
- "httpOnly": {
57
- "type": "boolean"
58
- },
59
- "secure": {
60
- "type": "boolean"
61
- }
62
- }
63
- },
64
- "response": {
65
- "type": "object",
66
- "required": ["status"],
67
- "additionalProperties": false,
68
- "properties": {
69
- "status": {
70
- "type": "integer",
71
- "minimum": 100,
72
- "exclusiveMaximum": 600
73
- },
74
- "headers": {
75
- "type": "array",
76
- "items": { "$ref": "#/definitions/header" }
77
- },
78
- "cookies": {
79
- "type": "array",
80
- "items": { "$ref": "#/definitions/cookie" }
81
- },
82
- "content": {
83
- "type": "object",
84
- "required": ["text"],
85
- "additionalProperties": false,
86
- "properties": {
87
- "text": {
88
- "type": "string"
89
- }
90
- }
91
- }
92
- }
93
- },
94
- "redirectResponse": {
95
- "type": "object",
96
- "required": ["redirectUrl"],
97
- "additionalProperties": false,
98
- "properties": {
99
- "redirectUrl": { "type": "string" }
100
- }
101
- },
102
- "passthroughResponse": {
103
- "type": "object",
104
- "required": ["passthrough"],
105
- "additionalProperties": false,
106
- "properties": {
107
- "passthrough": { "type": "boolean", "enum": [ true ] }
108
- }
109
- },
110
- "entry": {
111
- "type": "object",
112
- "required": ["request", "response"],
113
- "additionalProperties": false,
114
- "properties": {
115
- "request": { "$ref": "#/definitions/request" },
116
- "response": {
117
- "oneOf": [
118
- { "$ref": "#/definitions/response" },
119
- { "$ref": "#/definitions/redirectResponse" },
120
- { "$ref": "#/definitions/passthroughResponse" }
121
- ]
122
- },
123
- "maxHits": {
124
- "type": "integer",
125
- "minimum": 1
126
- }
127
- }
128
- }
129
- },
130
- "type": "object",
131
- "required": ["entries"],
132
- "properties": {
133
- "version": { "type": "string", "enum": ["1.2", "1.2.0"] },
134
- "creator": { "type": "string" },
135
- "entries": {
136
- "type": "array",
137
- "items": { "$ref": "#/definitions/entry" }
138
- }
139
- }
140
- }
@@ -1,174 +0,0 @@
1
-
2
- const util = require('util');
3
- const { additionalLogDetails } = require('./logUtils');
4
- const exec = util.promisify(require('child_process').exec);
5
- const spawn = require('child_process').spawn;
6
- const path = require('path');
7
- const { NpmPackageError, NpmPermissionsError } = require('../errors');
8
- const fse = require('fs-extra');
9
- const logger = require('./logger').getLogger('cli-service');
10
- const { requireWithFallback } = require('./requireWithFallback');
11
- const fs = require('fs');
12
- const utils = require('../utils');
13
-
14
- async function getLatestPackageVersion(packageName) {
15
- const result = await exec(`npm view ${packageName} version`);
16
- return result.stdout.trim();
17
- }
18
-
19
- function getPackageIfInstalledLocally(packageName) {
20
- try {
21
- // note: this code fails if require itself throws here
22
- // rather than an ENOENT - but since lazy dependencies are all controlled
23
- // by us that's probably fine.
24
- return requireWithFallback(packageName);
25
- } catch (err) {
26
- return false;
27
- }
28
- }
29
-
30
- async function isPackageInstalledInPath(rootPath, packageName) {
31
- try {
32
- return await fse.pathExists(path.join(rootPath, `./node_modules/${packageName}/package.json`));
33
- } catch (error) {
34
- return false;
35
- }
36
- }
37
-
38
- function getLocallyInstalledPackageVersion(rootPath, packageName) {
39
- // eslint-disable-next-line import/no-dynamic-require
40
- return require(path.join(rootPath, `./node_modules/${packageName}/package.json`)).version;
41
- }
42
-
43
- // this is not exactly correct, but it's good enough.
44
- async function fileExists(path) {
45
- try {
46
- await fs.promises.access(path);
47
- return true;
48
- } catch (err) {
49
- return false;
50
- }
51
- }
52
-
53
- async function installPackageLocally(rootPath, packageName, execOptions) {
54
- function getPathWithMissingPermissions(error) {
55
- const pathRegex = /EACCES[^']+'(.+)'/;
56
- const regexResult = pathRegex.exec(error.stderr);
57
- if (regexResult === null) {
58
- return false;
59
- }
60
- return regexResult[1];
61
- }
62
-
63
- // https://github.com/npm/arborist/pull/362
64
- function npmSevenAndEightMissingPermissions(error) {
65
- return /The "to" argument must be of type string./.exec(error.stderr);
66
- }
67
-
68
- // this is here because our shrinkwrap blocks our lazy deps for some reason
69
- const oldShrinkwrap = path.join(rootPath, 'npm-shrinkwrap.json');
70
- const newShrinkwrap = path.join(rootPath, 'npm-shrinkwrap-dummy.json');
71
- let renamed = false;
72
- try {
73
- try {
74
- if (await fileExists(oldShrinkwrap)) {
75
- await fs.promises.rename(oldShrinkwrap, newShrinkwrap);
76
- renamed = true;
77
- }
78
- } catch (err) {
79
- // ignore error
80
- }
81
- return await exec(`npm i ${packageName} --no-save --no-prune --prefer-offline --no-audit --progress=false`, { ...execOptions, cwd: rootPath }).catch(err => {
82
- const pathWithMissingPermissions = getPathWithMissingPermissions(err);
83
- const npmEightMissingPermissions = npmSevenAndEightMissingPermissions(err);
84
- if (pathWithMissingPermissions || npmEightMissingPermissions) {
85
- logger.info('Failed to install package due to insufficient write access', {
86
- ...additionalLogDetails(),
87
- package: packageName,
88
- path: pathWithMissingPermissions || rootPath,
89
- });
90
- // eslint-disable-next-line no-console
91
- console.error(`
92
-
93
- Testim failed installing the package ${packageName} due to insufficient permissions.
94
- This is probably due to an installation of @testim/testim-cli with sudo, and running it without sudo.
95
- Testim had missing write access to ${pathWithMissingPermissions || rootPath}
96
-
97
- `);
98
- throw new NpmPermissionsError(pathWithMissingPermissions || rootPath);
99
- }
100
- throw err;
101
- });
102
- } finally {
103
- if (renamed) {
104
- try {
105
- await fs.promises.rename(newShrinkwrap, oldShrinkwrap);
106
- } catch (err) {
107
- // ignore error
108
- }
109
- }
110
- }
111
- }
112
-
113
- const localNpmLocation = path.resolve(require.resolve('npm').replace('index.js', ''), 'bin', 'npm-cli.js');
114
-
115
- function installPackages(prefix, packageNames, proxyUri, timeoutMs) {
116
- return new Promise((resolve, reject) => {
117
- const proxyFlag = proxyUri ? ['--proxy', proxyUri] : [];
118
-
119
- const envVars = proxyUri ? { env: Object.assign(process.env, { HTTP_PROXY: proxyUri, HTTPS_PROXY: proxyUri }) } : {};
120
-
121
- let stdout = '';
122
- let stderr = '';
123
-
124
- const ops = '--no-save --no-package-lock --no-prune --prefer-offline --no-audit --progress=false'.split(' ');
125
- const npmInstall = spawn('node', [localNpmLocation, 'i', '--prefix', prefix, ...ops, ...packageNames, ...proxyFlag], envVars);
126
- npmInstall.stderr.pipe(process.stderr);
127
- npmInstall.stdout.pipe(process.stdout);
128
-
129
- npmInstall.stdout.on('data', (data) => {
130
- stdout += data;
131
- });
132
-
133
- npmInstall.stderr.on('data', (data) => {
134
- stderr += data;
135
- });
136
-
137
- npmInstall.on('close', (code) => {
138
- if (code) {
139
- let errorString;
140
- try {
141
- const packageVersion = /npm ERR! 404 {2}'(.+)' is not in the npm registry/gm.exec(stderr)[1];
142
- const packageName = packageVersion.split('@')[0];
143
- errorString = `404 Not Found - GET https://registry.npmjs.org/${packageName} - Not found`;
144
- } catch (err) {
145
- errorString = `Npm Install closed with exit code ${code}\n stdout: ${stdout} stderr: ${stderr}`;
146
- }
147
-
148
- logger.debug(`Npm Install closed with exit code ${code}`, { message: errorString });
149
-
150
- reject(new NpmPackageError(errorString));
151
- } else {
152
- resolve(stdout);
153
- }
154
- });
155
-
156
- setTimeout(() => {
157
- try {
158
- npmInstall.kill();
159
- } finally {
160
- reject(new utils.TimeoutError());
161
- }
162
- }, timeoutMs);
163
- });
164
- }
165
-
166
- module.exports = {
167
- isPackageInstalledInPath,
168
- getLatestPackageVersion,
169
- getPackageIfInstalledLocally,
170
- getLocallyInstalledPackageVersion,
171
- installPackageLocally,
172
- installPackages,
173
- NpmPermissionsError,
174
- };