@wdio/appium-service 8.29.1 → 8.29.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAIlE,OAAO,KAAK,EAAyB,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAW5E,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,QAAQ,CAAC,eAAe;IAO/D,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,OAAO,CAAC;IARpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,CAA+C;gBAGpD,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,EAAE,YAAY,CAAC,kBAAkB,EAC9C,OAAO,CAAC,gCAAoB;YAS1B,WAAW;IAqBzB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAgDlB,SAAS;IAgCf,UAAU;IAOV,OAAO,CAAC,YAAY;YAiCN,kBAAkB;mBAeX,iBAAiB;CAezC"}
1
+ {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAIlE,OAAO,KAAK,EAAyB,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAY5E,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,QAAQ,CAAC,eAAe;IAO/D,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,OAAO,CAAC;IARpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,CAA+C;gBAGpD,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,EAAE,YAAY,CAAC,kBAAkB,EAC9C,OAAO,CAAC,gCAAoB;YAS1B,WAAW;IAqBzB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAgDlB,SAAS;IAgCf,UAAU;IAMV,OAAO,CAAC,YAAY;YAmEN,kBAAkB;mBAeX,iBAAiB;CAezC"}
package/build/launcher.js CHANGED
@@ -18,6 +18,7 @@ const DEFAULT_CONNECTION = {
18
18
  hostname: '127.0.0.1',
19
19
  path: '/'
20
20
  };
21
+ const APPIUM_START_TIMEOUT = 30 * 1000;
21
22
  export default class AppiumLauncher {
22
23
  _options;
23
24
  _capabilities;
@@ -122,33 +123,65 @@ export default class AppiumLauncher {
122
123
  this._process.kill();
123
124
  }
124
125
  }
125
- _startAppium(command, args) {
126
+ _startAppium(command, args, timeout = APPIUM_START_TIMEOUT) {
126
127
  log.info(`Will spawn Appium process: ${command} ${args.join(' ')}`);
127
128
  const process = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'] });
129
+ // just for validate the first error
130
+ let errorCaptured = false;
131
+ // to set a timeout for the promise
132
+ let timeoutId;
133
+ // to store the first error message
128
134
  let error;
129
135
  return new Promise((resolve, reject) => {
136
+ let outputBuffer = '';
137
+ /**
138
+ * set timeout for promise. If Appium does not start within given timeout,
139
+ * e.g. if the port is already in use, reject the promise.
140
+ */
141
+ timeoutId = setTimeout(() => {
142
+ rejectOnce(new Error('Timeout: Appium did not start within expected time'));
143
+ }, timeout);
144
+ /**
145
+ * reject promise if Appium does not start within given timeout,
146
+ * e.g. if the port is already in use
147
+ *
148
+ * @param err - error to reject with
149
+ */
150
+ const rejectOnce = (err) => {
151
+ if (!errorCaptured) {
152
+ errorCaptured = true;
153
+ clearTimeout(timeoutId);
154
+ reject(err);
155
+ }
156
+ };
130
157
  process.stdout.on('data', (data) => {
131
- if (data.includes('Appium REST http interface listener started')) {
158
+ outputBuffer += data.toString();
159
+ if (outputBuffer.includes('Appium REST http interface listener started')) {
132
160
  log.info(`Appium started with ID: ${process.pid}`);
161
+ clearTimeout(timeoutId);
133
162
  resolve(process);
134
163
  }
135
164
  });
136
165
  /**
137
166
  * only capture first error to print it in case Appium failed to start.
138
167
  */
139
- process.stderr.once('data', (err) => { error = err; });
140
- process.once('exit', exitCode => {
168
+ process.stderr.once('data', (data) => {
169
+ error = data.toString() || 'Appium exited without unknown error message';
170
+ log.error(error);
171
+ rejectOnce(new Error(error));
172
+ });
173
+ process.once('exit', (exitCode) => {
141
174
  let errorMessage = `Appium exited before timeout (exit code: ${exitCode})`;
142
175
  if (exitCode === 2) {
143
176
  errorMessage += '\n' + (error?.toString() || 'Check that you don\'t already have a running Appium service.');
144
177
  }
145
- else if (error) {
146
- errorMessage += `\n${error.toString()}`;
178
+ else if (errorCaptured) {
179
+ errorMessage += `\n${error?.toString()}`;
147
180
  }
148
181
  if (exitCode !== 0) {
149
182
  log.error(errorMessage);
150
183
  }
151
- reject(new Error(errorMessage));
184
+ rejectOnce(new Error(errorMessage));
152
185
  });
153
186
  });
154
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/appium-service",
3
- "version": "8.29.1",
3
+ "version": "8.29.3",
4
4
  "description": "A WebdriverIO service to start & stop Appium Server",
5
5
  "author": "Morten Bjerg Gregersen <morten@mogee.dk>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-appium-service",
@@ -33,17 +33,17 @@
33
33
  },
34
34
  "typeScriptVersion": "3.8.3",
35
35
  "dependencies": {
36
- "@wdio/config": "8.29.1",
36
+ "@wdio/config": "8.29.3",
37
37
  "@wdio/logger": "8.28.0",
38
38
  "@wdio/types": "8.29.1",
39
- "@wdio/utils": "8.29.1",
39
+ "@wdio/utils": "8.29.3",
40
40
  "get-port": "^7.0.0",
41
41
  "import-meta-resolve": "^4.0.0",
42
42
  "param-case": "^3.0.4",
43
- "webdriverio": "8.29.1"
43
+ "webdriverio": "8.29.3"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "d434fcf0aaaa9d835789c4c335d319f94a899687"
48
+ "gitHead": "4c6433be548950dc6ccf0efff77507dfa2f0b321"
49
49
  }