@wdio/native-core 1.3.1 → 2.0.0-next.1

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 (39) hide show
  1. package/dist/cjs/browserMode.d.ts +18 -0
  2. package/dist/cjs/browserMode.d.ts.map +1 -1
  3. package/dist/cjs/cmdLine.d.ts +4 -0
  4. package/dist/cjs/cmdLine.d.ts.map +1 -0
  5. package/dist/cjs/devServerProcess.d.ts.map +1 -1
  6. package/dist/cjs/driverPool.d.ts.map +1 -1
  7. package/dist/cjs/driverProcess.d.ts +2 -0
  8. package/dist/cjs/driverProcess.d.ts.map +1 -1
  9. package/dist/cjs/index.d.ts +2 -0
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +294 -27
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/instanceFailures.d.ts +15 -0
  14. package/dist/cjs/instanceFailures.d.ts.map +1 -0
  15. package/dist/cjs/instances.d.ts +57 -0
  16. package/dist/cjs/instances.d.ts.map +1 -0
  17. package/dist/cjs/package.json +1 -1
  18. package/dist/cjs/processTree.d.ts +3 -0
  19. package/dist/cjs/processTree.d.ts.map +1 -0
  20. package/dist/esm/browserMode.d.ts +18 -0
  21. package/dist/esm/browserMode.d.ts.map +1 -1
  22. package/dist/esm/cmdLine.d.ts +4 -0
  23. package/dist/esm/cmdLine.d.ts.map +1 -0
  24. package/dist/esm/devServerProcess.d.ts.map +1 -1
  25. package/dist/esm/driverPool.d.ts.map +1 -1
  26. package/dist/esm/driverProcess.d.ts +2 -0
  27. package/dist/esm/driverProcess.d.ts.map +1 -1
  28. package/dist/esm/index.d.ts +2 -0
  29. package/dist/esm/index.d.ts.map +1 -1
  30. package/dist/esm/index.js +287 -29
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/instanceFailures.d.ts +15 -0
  33. package/dist/esm/instanceFailures.d.ts.map +1 -0
  34. package/dist/esm/instances.d.ts +57 -0
  35. package/dist/esm/instances.d.ts.map +1 -0
  36. package/dist/esm/package.json +1 -1
  37. package/dist/esm/processTree.d.ts +3 -0
  38. package/dist/esm/processTree.d.ts.map +1 -0
  39. package/package.json +9 -9
@@ -16,6 +16,14 @@ export declare const BROWSER_MODE_SUPPORTED_BROWSER = "chrome";
16
16
  * legitimate `browserName: 'electron'` to chrome for the browser-mode session.
17
17
  */
18
18
  export declare function nonChromeBrowserNameError(browserName: unknown, allowed?: readonly string[]): string | undefined;
19
+ /**
20
+ * Check that every capability resolves to the same run mode.
21
+ *
22
+ * Returns an error message naming the modes found when they differ, and `undefined` when they
23
+ * match. A capability with no mode counts as `'native'`. Each launcher throws its own
24
+ * `SevereServiceError` with the message, as with {@link nonChromeBrowserNameError}.
25
+ */
26
+ export declare function mixedModesError(modes: readonly (string | undefined)[], service: string, optionsKey: string): string | undefined;
19
27
  /**
20
28
  * Preflight the dev server before the worker navigates to it.
21
29
  *
@@ -25,6 +33,15 @@ export declare function nonChromeBrowserNameError(browserName: unknown, allowed?
25
33
  * main process where outbound network is available.
26
34
  */
27
35
  export declare function probeDevServerReachable(url: string, timeoutMs?: number): Promise<Result<void, Error>>;
36
+ /**
37
+ * Resolve the dev server URL each browser-mode capability opens, in the order given.
38
+ *
39
+ * `managedUrl`, from the dev server the launcher started, applies to every capability. Without it,
40
+ * each capability opens its own URL (the caller merges a capability's `devServerUrl` over the
41
+ * service-level one), and each distinct URL is preflighted once with {@link probeDevServerReachable}.
42
+ * Fails when a capability has no URL or an invalid one, or when a dev server is unreachable.
43
+ */
44
+ export declare function resolveDevServerUrls(capabilityUrls: readonly (string | undefined)[], managedUrl?: string): Promise<Result<string[], Error>>;
28
45
  /**
29
46
  * Poll {@link probeDevServerReachable} until the server answers or the budget elapses.
30
47
  *
@@ -43,6 +60,7 @@ export declare function waitForDevServerReachable(url: string, { timeoutMs, poll
43
60
  * (no subprocess spawn/kill involved). The returned `url` supplies/overrides `devServerUrl`.
44
61
  * - **string / object** — if `reuseExistingServer` (default `!CI`) and `devServerUrl` is already
45
62
  * reachable, skip the spawn; otherwise spawn a {@link DevServerProcess} and poll `devServerUrl`.
63
+ * Throws if a server this process started this way at the same origin is still running.
46
64
  *
47
65
  * The caller stores the returned `stop` and must call it in `onComplete` *and* on an `onPrepare`
48
66
  * failure (WDIO does not call `onComplete` after `onPrepare` throws). `stop` is idempotent.
@@ -1 +1 @@
1
- {"version":3,"file":"browserMode.d.ts","sourceRoot":"","sources":["../../src/browserMode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAsC,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAOnF,eAAO,MAAM,8BAA8B,WAAW,CAAC;AAIvD;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,OAAO,EACpB,OAAO,GAAE,SAAS,MAAM,EAAqC,GAC5D,MAAM,GAAG,SAAS,CAWpB;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,MAAM,EACX,SAAS,GAAE,MAAoC,GAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAQ9B;AAOD;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,MAAM,EACX,EACE,SAAuC,EACvC,MAAiC,GAClC,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAQ9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,GAAE;IACJ,KAAK,CAAC,EAAE,cAAc,oBAAoB,EAAE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AE,KAAK,CAAC,CAAC,CA2BlC;AA0BD;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,MAAM,EACX,EACE,SAAuC,EACvC,MAAiC,GAClC,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAQ9B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,GAAE;IACJ,KAAK,CAAC,EAAE,cAAc,oBAAoB,EAAE,KAAK,CAAC;IAClD,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;CACrB,GACL,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAyDrD"}
@@ -0,0 +1,4 @@
1
+ export declare function unquote(arg: string): string;
2
+ export declare function quoteForCmd(arg: string): string;
3
+ export declare function needsShell(driverPath: string): boolean;
4
+ //# sourceMappingURL=cmdLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmdLine.d.ts","sourceRoot":"","sources":["../../src/cmdLine.ts"],"names":[],"mappings":"AACA,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM/C;AAGD,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEtD"}
@@ -1 +1 @@
1
- {"version":3,"file":"devServerProcess.d.ts","sourceRoot":"","sources":["../../src/devServerProcess.ts"],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UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIrD,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI/D,SAAS,IAAI;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE;IAWvE,cAAc,IAAI,MAAM,EAAE;CAS3B"}
@@ -45,6 +45,7 @@ export interface DriverProcessInfo {
45
45
  */
46
46
  export declare class DriverProcess {
47
47
  private _proc?;
48
+ private viaShell;
48
49
  private streamHandlers;
49
50
  private startupTimeout?;
50
51
  private pollTimer?;
@@ -62,6 +63,7 @@ export declare class DriverProcess {
62
63
  private waitForHttpReady;
63
64
  stop(driverName?: string): Promise<void>;
64
65
  isRunning(): boolean;
66
+ private kill;
65
67
  private waitForExit;
66
68
  private cleanup;
67
69
  private cleanupTimeout;
@@ -1 +1 @@
1
- {"version":3,"file":"driverProcess.d.ts","sourceRoot":"","sources":["../../src/driverProcess.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,KAAK,YAAY,EAAS,MAAM,oBAAoB,CAAC;AAW9D,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,aAAa,CAAC;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,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EnC;IAED,IAAI,IAAI,IAAI,MAAM,GAAG,SAAS,CAE7B;IAED,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAEnC;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAEhC;IAEK,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;YA+ItD,gBAAgB;YAwDhB,UAAU;YA6BV,gBAAgB;IAoBxB,IAAI,CAAC,UAAU,SAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BhD,SAAS,IAAI,OAAO;IAcpB,OAAO,CAAC,IAAI;YAYE,WAAW;IAqCzB,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,cAAc;CAUvB"}
@@ -4,6 +4,8 @@ export * from './deeplink.js';
4
4
  export * from './devServerProcess.js';
5
5
  export * from './driverPool.js';
6
6
  export * from './driverProcess.js';
7
+ export * from './instanceFailures.js';
8
+ export * from './instances.js';
7
9
  export * from './logCapture.js';
8
10
  export * from './logLevel.js';
9
11
  export * from './logWriter.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -9,6 +9,22 @@ var getPort = require('get-port');
9
9
  var node_fs = require('node:fs');
10
10
  var node_path = require('node:path');
11
11
 
12
+ // Without cmd.exe to strip them, quotes a caller put around a path would reach the driver as part of it
13
+ function unquote(arg) {
14
+ return arg.length > 1 && arg.startsWith('"') && arg.endsWith('"') ? arg.slice(1, -1) : arg;
15
+ }
16
+ function quoteForCmd(arg) {
17
+ const bare = unquote(arg);
18
+ if (!/[\s&()<>^|]/.test(bare)) {
19
+ return bare;
20
+ }
21
+ return `"${bare}"`;
22
+ }
23
+ // On Windows only a .exe or .com starts without cmd.exe; a .cmd shim, or a bare name cmd.exe resolves, needs it
24
+ function needsShell(driverPath) {
25
+ return process.platform === 'win32' && !/\.(exe|com)$/i.test(unquote(driverPath));
26
+ }
27
+
12
28
  // Stream-based log capture skeleton.
13
29
  //
14
30
  // Extracted from packages/tauri-service/src/logCapture.ts. Provides the
@@ -59,6 +75,13 @@ function createLogCapture(opts) {
59
75
  return rl;
60
76
  }
61
77
 
78
+ // Windows has no process groups, so killing a parent such as cmd.exe leaves the processes it started running;
79
+ // taskkill /T walks the tree instead. If taskkill can't run, the parent is killed directly. A failed taskkill
80
+ // leaves the parent running, so a caller's force-kill step can still walk its tree.
81
+ function killWindowsProcessTree(proc) {
82
+ node_child_process.spawn('taskkill', ['/pid', String(proc.pid), '/T', '/F'], { stdio: 'ignore' }).on('error', () => proc.kill());
83
+ }
84
+
62
85
  // Generic driver subprocess lifecycle.
63
86
  //
64
87
  // Extracted from packages/tauri-service/src/driverProcess.ts. Generalised so
@@ -76,9 +99,8 @@ function createLogCapture(opts) {
76
99
  // into the caller's `DriverStartOptions` so each service supplies its
77
100
  // own (we used to hardcode Tauri's strings).
78
101
  //
79
- // The poll-for-readiness behaviour (TCP open + HTTP /status reachable),
80
- // SIGTERM-then-SIGKILL shutdown sequence, and CI-aware timeouts all
81
- // transfer unchanged — they're generic.
102
+ // The poll-for-readiness behaviour (TCP open + HTTP /status reachable) and
103
+ // CI-aware timeouts transfer unchanged — they're generic.
82
104
  const log$6 = nativeUtils.createLogger('native-core', 'launcher');
83
105
  /**
84
106
  * Manages a single driver subprocess lifecycle (Tauri's tauri-driver,
@@ -86,6 +108,7 @@ const log$6 = nativeUtils.createLogger('native-core', 'launcher');
86
108
  */
87
109
  class DriverProcess {
88
110
  _proc;
111
+ viaShell = false;
89
112
  streamHandlers = [];
90
113
  startupTimeout;
91
114
  pollTimer;
@@ -135,13 +158,20 @@ class DriverProcess {
135
158
  }
136
159
  };
137
160
  try {
138
- const spawnEnv = env ? { ...process.env, ...env } : process.env;
139
- this._proc = node_child_process.spawn(driverPath, args, {
161
+ const spawnOptions = {
140
162
  stdio: ['ignore', 'pipe', 'pipe'],
141
163
  detached: false,
142
- env: spawnEnv,
143
- shell: process.platform === 'win32',
144
- });
164
+ env: env ? nativeUtils.mergeEnv(process.env, env) : process.env,
165
+ };
166
+ this.viaShell = needsShell(driverPath);
167
+ if (this.viaShell) {
168
+ // One quoted command line for cmd.exe: spawn's shell mode joins the arguments unquoted
169
+ this._proc = node_child_process.spawn([driverPath, ...args].map(quoteForCmd).join(' '), { ...spawnOptions, shell: true });
170
+ }
171
+ else {
172
+ const plain = process.platform === 'win32' ? unquote : (arg) => arg;
173
+ this._proc = node_child_process.spawn(plain(driverPath), args.map(plain), spawnOptions);
174
+ }
145
175
  log$6.info(`[${identifier}] Spawned process with PID: ${this._proc.pid ?? 'unknown'}`);
146
176
  this.startupTimeout = setTimeout(() => {
147
177
  if (!settled) {
@@ -188,10 +218,12 @@ class DriverProcess {
188
218
  onErrorDetected: (message) => safeReject(new Error(message)),
189
219
  onLine: onLogLine ?? noop,
190
220
  });
191
- if (stdoutHandler)
221
+ if (stdoutHandler) {
192
222
  this.streamHandlers.push(stdoutHandler);
193
- if (stderrHandler)
223
+ }
224
+ if (stderrHandler) {
194
225
  this.streamHandlers.push(stderrHandler);
226
+ }
195
227
  this._proc.once('exit', (code, signal) => {
196
228
  if (!settled) {
197
229
  safeReject(new Error(`${driverName} [${identifier}] exited unexpectedly during startup (code: ${code}, signal: ${signal})`));
@@ -306,7 +338,7 @@ class DriverProcess {
306
338
  return;
307
339
  }
308
340
  log$6.debug(`Stopping ${driverName}...`);
309
- this._proc.kill('SIGTERM');
341
+ this.kill('SIGTERM');
310
342
  await this.waitForExit(driverName);
311
343
  this.cleanup();
312
344
  // Additional delay to ensure the port is fully released.
@@ -325,16 +357,30 @@ class DriverProcess {
325
357
  }
326
358
  return !this._proc.killed;
327
359
  }
360
+ kill(signal) {
361
+ if (!this._proc) {
362
+ return;
363
+ }
364
+ if (this.viaShell) {
365
+ // Killing cmd.exe alone would leave the driver it started running and holding its port
366
+ killWindowsProcessTree(this._proc);
367
+ }
368
+ else {
369
+ this._proc.kill(signal);
370
+ }
371
+ }
328
372
  async waitForExit(driverName) {
329
373
  const stopTimeout = process.env.CI ? 10000 : 5000;
330
374
  return new Promise((resolve) => {
331
375
  let shutdownTimeout = null;
332
376
  let killTimeout = null;
333
377
  const cleanup = () => {
334
- if (shutdownTimeout)
378
+ if (shutdownTimeout) {
335
379
  clearTimeout(shutdownTimeout);
336
- if (killTimeout)
380
+ }
381
+ if (killTimeout) {
337
382
  clearTimeout(killTimeout);
383
+ }
338
384
  };
339
385
  const onExit = () => {
340
386
  cleanup();
@@ -344,7 +390,7 @@ class DriverProcess {
344
390
  this._proc?.once('exit', onExit);
345
391
  shutdownTimeout = setTimeout(() => {
346
392
  log$6.warn(`${driverName} did not stop gracefully after ${stopTimeout}ms, forcing kill`);
347
- this._proc?.kill('SIGKILL');
393
+ this.kill('SIGKILL');
348
394
  killTimeout = setTimeout(() => {
349
395
  log$6.warn(`${driverName} force kill timeout, giving up`);
350
396
  cleanup();
@@ -432,18 +478,24 @@ class DriverPool {
432
478
  log$5.debug(`Driver [${identifier}] stopped and cleaned up`);
433
479
  }
434
480
  async stopAll() {
435
- const count = this.drivers.size;
436
- if (count === 0) {
481
+ const entries = Array.from(this.drivers.entries());
482
+ if (entries.length === 0) {
437
483
  return;
438
484
  }
439
- log$5.info(`Stopping ${count} driver(s)...`);
440
- const stopPromises = [];
441
- for (const [identifier, info] of this.drivers.entries()) {
485
+ log$5.info(`Stopping ${entries.length} driver(s)...`);
486
+ const results = await Promise.allSettled(entries.map(([identifier, info]) => {
442
487
  log$5.debug(`Stopping driver [${identifier}]...`);
443
- stopPromises.push(info.process.stop(info.driverName));
444
- }
445
- await Promise.all(stopPromises);
488
+ return info.process.stop(info.driverName);
489
+ }));
446
490
  this.drivers.clear();
491
+ const failures = entries.flatMap(([identifier], i) => {
492
+ const result = results[i];
493
+ return result.status === 'rejected' ? [{ identifier, reason: result.reason }] : [];
494
+ });
495
+ if (failures.length > 0) {
496
+ const details = failures.map(({ identifier, reason }) => `${identifier}: ${nativeUtils.errorMessage(reason)}`).join('; ');
497
+ throw new AggregateError(failures.map(({ reason }) => reason), `Failed to stop driver(s): ${details}`);
498
+ }
447
499
  log$5.debug('All drivers stopped');
448
500
  }
449
501
  getDriver(identifier) {
@@ -622,7 +674,7 @@ const defaultKill = (proc, signal) => {
622
674
  return;
623
675
  }
624
676
  if (isWindows) {
625
- node_child_process.spawn('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore' }).on('error', () => { });
677
+ killWindowsProcessTree(proc);
626
678
  return;
627
679
  }
628
680
  try {
@@ -675,7 +727,7 @@ class DevServerProcess {
675
727
  // Own process group so teardown can kill the tree (see defaultKill).
676
728
  detached: !isWindows,
677
729
  stdio: ['ignore', 'pipe', 'pipe'],
678
- env: { ...process.env, ...options.env },
730
+ env: nativeUtils.mergeEnv(process.env, options.env),
679
731
  });
680
732
  this.#proc = proc;
681
733
  proc.stdout?.on('data', (d) => log$3.debug(`[dev-server] ${d.toString().trim()}`));
@@ -799,6 +851,21 @@ function nonChromeBrowserNameError(browserName, allowed = [BROWSER_MODE_SUPPORTE
799
851
  return (`Browser mode only supports browserName: '${BROWSER_MODE_SUPPORTED_BROWSER}', but got '${browserName}'. ` +
800
852
  `Remove the browserName from your capability (it is set automatically) or set it to '${BROWSER_MODE_SUPPORTED_BROWSER}'.`);
801
853
  }
854
+ /**
855
+ * Check that every capability resolves to the same run mode.
856
+ *
857
+ * Returns an error message naming the modes found when they differ, and `undefined` when they
858
+ * match. A capability with no mode counts as `'native'`. Each launcher throws its own
859
+ * `SevereServiceError` with the message, as with {@link nonChromeBrowserNameError}.
860
+ */
861
+ function mixedModesError(modes, service, optionsKey) {
862
+ const uniqueModes = [...new Set(modes.map((mode) => mode ?? 'native'))];
863
+ if (uniqueModes.length <= 1) {
864
+ return undefined;
865
+ }
866
+ return (`All ${service} capabilities must use the same mode, but found mixed modes: ${uniqueModes.join(', ')}. ` +
867
+ `Set mode consistently across all '${optionsKey}' entries.`);
868
+ }
802
869
  /**
803
870
  * Preflight the dev server before the worker navigates to it.
804
871
  *
@@ -817,8 +884,56 @@ async function probeDevServerReachable(url, timeoutMs = DEV_SERVER_PROBE_TIMEOUT
817
884
  return nativeUtils.Err(new Error(`Dev server not reachable at ${url} — is it running? (${detail})`));
818
885
  }
819
886
  }
887
+ /**
888
+ * Resolve the dev server URL each browser-mode capability opens, in the order given.
889
+ *
890
+ * `managedUrl`, from the dev server the launcher started, applies to every capability. Without it,
891
+ * each capability opens its own URL (the caller merges a capability's `devServerUrl` over the
892
+ * service-level one), and each distinct URL is preflighted once with {@link probeDevServerReachable}.
893
+ * Fails when a capability has no URL or an invalid one, or when a dev server is unreachable.
894
+ */
895
+ async function resolveDevServerUrls(capabilityUrls, managedUrl) {
896
+ const probedUrls = new Set();
897
+ const urls = [];
898
+ for (const capabilityUrl of capabilityUrls) {
899
+ const url = managedUrl ?? capabilityUrl;
900
+ if (!url) {
901
+ return nativeUtils.Err(new Error('devServerUrl is required when mode is "browser" (set it, or return a url from a devServer function)'));
902
+ }
903
+ try {
904
+ new URL(url);
905
+ }
906
+ catch {
907
+ return nativeUtils.Err(new Error(`devServerUrl is not a valid URL: ${url}`));
908
+ }
909
+ if (managedUrl === undefined && !probedUrls.has(url)) {
910
+ const reachable = await probeDevServerReachable(url);
911
+ if (nativeUtils.isErr(reachable)) {
912
+ return reachable;
913
+ }
914
+ probedUrls.add(url);
915
+ }
916
+ urls.push(url);
917
+ }
918
+ return nativeUtils.Ok(urls);
919
+ }
820
920
  const DEV_SERVER_READY_TIMEOUT_MS = 60_000;
821
921
  const DEV_SERVER_READY_POLL_MS = 500;
922
+ const activeManagedServers = new Set();
923
+ function originOf(url) {
924
+ try {
925
+ return new URL(url).origin;
926
+ }
927
+ catch {
928
+ return url;
929
+ }
930
+ }
931
+ function assertNotInUse(origin, url) {
932
+ if (activeManagedServers.has(origin)) {
933
+ throw new Error(`A dev server this process started at ${url} is still in use by another session. ` +
934
+ 'To share one dev server, start it yourself and pass devServerUrl without devServer, or run the sessions in separate processes.');
935
+ }
936
+ }
822
937
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
823
938
  /**
824
939
  * Poll {@link probeDevServerReachable} until the server answers or the budget elapses.
@@ -843,6 +958,7 @@ async function waitForDevServerReachable(url, { timeoutMs = DEV_SERVER_READY_TIM
843
958
  * (no subprocess spawn/kill involved). The returned `url` supplies/overrides `devServerUrl`.
844
959
  * - **string / object** — if `reuseExistingServer` (default `!CI`) and `devServerUrl` is already
845
960
  * reachable, skip the spawn; otherwise spawn a {@link DevServerProcess} and poll `devServerUrl`.
961
+ * Throws if a server this process started this way at the same origin is still running.
846
962
  *
847
963
  * The caller stores the returned `stop` and must call it in `onComplete` *and* on an `onPrepare`
848
964
  * failure (WDIO does not call `onComplete` after `onPrepare` throws). `stop` is idempotent.
@@ -863,11 +979,17 @@ async function startManagedDevServer(devServer, devServerUrl, deps = {}) {
863
979
  const config = typeof devServer === 'string' ? { command: devServer } : devServer;
864
980
  const isCI = deps.isCI ?? Boolean(process.env.CI);
865
981
  const reuseExisting = config.reuseExistingServer ?? !isCI;
866
- if (reuseExisting && nativeUtils.isOk(await probeDevServerReachable(devServerUrl))) {
982
+ const origin = originOf(devServerUrl);
983
+ assertNotInUse(origin, devServerUrl);
984
+ const reachable = reuseExisting && nativeUtils.isOk(await probeDevServerReachable(devServerUrl));
985
+ // Check again: another session may have claimed this origin during the probe.
986
+ assertNotInUse(origin, devServerUrl);
987
+ if (reachable) {
867
988
  log$2.info(`Reusing dev server already reachable at ${devServerUrl}`);
868
989
  return { url: devServerUrl, stop: async () => { } };
869
990
  }
870
991
  const proc = new DevServerProcess({ spawn: deps.spawn, probe: deps.probe });
992
+ activeManagedServers.add(origin);
871
993
  try {
872
994
  await proc.start({
873
995
  command: config.command,
@@ -880,10 +1002,25 @@ async function startManagedDevServer(devServer, devServerUrl, deps = {}) {
880
1002
  catch (error) {
881
1003
  // start() can throw *after* the process spawned (readiness timeout) — stop the live-but-unready
882
1004
  // process before propagating, or it orphans (holding the port). Mirrors the function form's close().
883
- await proc.stop();
1005
+ try {
1006
+ await proc.stop();
1007
+ }
1008
+ finally {
1009
+ activeManagedServers.delete(origin);
1010
+ }
884
1011
  throw error;
885
1012
  }
886
- return { url: devServerUrl, stop: () => proc.stop() };
1013
+ return {
1014
+ url: devServerUrl,
1015
+ stop: async () => {
1016
+ try {
1017
+ await proc.stop();
1018
+ }
1019
+ finally {
1020
+ activeManagedServers.delete(origin);
1021
+ }
1022
+ },
1023
+ };
887
1024
  }
888
1025
 
889
1026
  // Platform-specific deeplink (URL protocol-handler) helpers.
@@ -1000,6 +1137,127 @@ async function executeDeeplinkCommand(command, args, env) {
1000
1137
  });
1001
1138
  }
1002
1139
 
1140
+ /**
1141
+ * Flatten the capabilities a launcher hook receives (an array, one capabilities object, or a
1142
+ * multiremote record) into one entry per instance, holding the caller's objects by reference.
1143
+ *
1144
+ * A single session's `connectionTarget` is its caps object, which WebdriverIO hoists `hostname` and
1145
+ * `port` out of. A multiremote instance's is its outer `{ capabilities }` entry, because WebdriverIO
1146
+ * reads multiremote connection params only from there and ignores them inside the caps.
1147
+ */
1148
+ function normaliseInstanceCaps(capabilities) {
1149
+ if (Array.isArray(capabilities)) {
1150
+ return capabilities.map((caps) => ({ caps, connectionTarget: caps }));
1151
+ }
1152
+ const entries = Object.entries(capabilities);
1153
+ if (entries.length > 0 && entries.every(([, entry]) => isCapabilitiesEntry(entry))) {
1154
+ return entries.map(([name, entry]) => ({
1155
+ name,
1156
+ caps: entry.capabilities,
1157
+ connectionTarget: entry,
1158
+ }));
1159
+ }
1160
+ const caps = capabilities;
1161
+ return [{ caps, connectionTarget: caps }];
1162
+ }
1163
+ function isCapabilitiesEntry(value) {
1164
+ return value !== null && typeof value === 'object' && 'capabilities' in value;
1165
+ }
1166
+ /**
1167
+ * Run `callback` on each session in turn: every instance of a multiremote browser, or the browser
1168
+ * itself.
1169
+ *
1170
+ * Pass the worker `before` hook's `capabilities` for the callback to get each instance's caps. A
1171
+ * single session gets `capabilities` as is. A multiremote instance gets the caps its session was
1172
+ * requested with, with a W3C `alwaysMatch` unwrapped, or else its entry in `capabilities`.
1173
+ */
1174
+ async function forEachInstance(browser, callback, capabilities) {
1175
+ if (!nativeUtils.isMultiremote(browser)) {
1176
+ await callback(browser, { caps: capabilities });
1177
+ return;
1178
+ }
1179
+ for (const name of browser.instances) {
1180
+ const instance = requireInstance(browser, name);
1181
+ await callback(instance, { name, caps: requestedCapabilities(instance) ?? capabilitiesEntry(capabilities, name) });
1182
+ }
1183
+ }
1184
+ /** Get the multiremote instance named `name`, throwing if the browser has none by that name. */
1185
+ function requireInstance(browser, name) {
1186
+ const instance = browser.getInstance(name);
1187
+ if (!instance) {
1188
+ throw new Error(`Multiremote browser has no instance named "${name}"`);
1189
+ }
1190
+ return instance;
1191
+ }
1192
+ function requestedCapabilities(instance) {
1193
+ const requested = instance.requestedCapabilities;
1194
+ if (requested === null || typeof requested !== 'object') {
1195
+ return undefined;
1196
+ }
1197
+ if ('alwaysMatch' in requested) {
1198
+ return requested.alwaysMatch;
1199
+ }
1200
+ return requested;
1201
+ }
1202
+ function capabilitiesEntry(capabilities, name) {
1203
+ const entry = capabilities?.[name];
1204
+ return isCapabilitiesEntry(entry) ? entry.capabilities : undefined;
1205
+ }
1206
+ /**
1207
+ * An error message if two instances in one multiremote group share the object a launcher writes
1208
+ * to, or undefined if none do. Launchers write each instance's debugging port to that object, so
1209
+ * instances sharing it all get the last port and drive one app.
1210
+ *
1211
+ * `target` returns the object the launcher writes to, or undefined for an instance it leaves alone.
1212
+ * It defaults to the instance's capabilities.
1213
+ */
1214
+ function sharedInstanceCapsError(capabilities, target = (caps) => caps) {
1215
+ // Each parallel multiremote group runs in its own worker, so instances only clash within a group.
1216
+ const groups = (Array.isArray(capabilities) ? capabilities : [capabilities]);
1217
+ for (const group of groups) {
1218
+ const names = new Map();
1219
+ for (const { name, caps } of normaliseInstanceCaps(group)) {
1220
+ if (name === undefined) {
1221
+ continue;
1222
+ }
1223
+ const written = target(caps);
1224
+ if (written === undefined) {
1225
+ continue;
1226
+ }
1227
+ const sharedWith = names.get(written);
1228
+ if (sharedWith !== undefined) {
1229
+ return (`Multiremote instances "${sharedWith}" and "${name}" share one capabilities object, so they'd get the same debugging port. ` +
1230
+ 'Give each instance its own, for example `capabilities: { ...appCaps }`.');
1231
+ }
1232
+ names.set(written, name);
1233
+ }
1234
+ }
1235
+ return undefined;
1236
+ }
1237
+
1238
+ /** Runs `run` on every target at once and waits for all of them, collecting the failures with each target's name. */
1239
+ async function settleOnEach(targets, run) {
1240
+ const results = await Promise.allSettled(targets.map(async (target) => run(target)));
1241
+ const values = results.flatMap((result) => (result.status === 'fulfilled' ? [result.value] : []));
1242
+ const failures = results.flatMap((result, i) => result.status === 'rejected' ? [{ name: targets[i].name, error: result.reason }] : []);
1243
+ return { values, failures };
1244
+ }
1245
+ // Reporters print only the message, not `cause` or `errors`, so the message names each failure
1246
+ function instanceFailuresError(commandName, failures) {
1247
+ const message = `${commandName} failed on ${failures.map(({ name, error }) => `${name}: ${nativeUtils.errorMessage(error)}`).join('; ')}`;
1248
+ return failures.length === 1
1249
+ ? new Error(message, { cause: failures[0].error })
1250
+ : new AggregateError(failures.map(({ error }) => error), message);
1251
+ }
1252
+ /** Runs `run` in every instance of the multiremote root, and if any fail, throws an error naming each one. */
1253
+ async function runOnEachInstance(root, commandName, run) {
1254
+ const { values, failures } = await settleOnEach(root.instances.map((name) => ({ name })), ({ name }) => run(requireInstance(root, name)));
1255
+ if (failures.length > 0) {
1256
+ throw instanceFailuresError(commandName, failures);
1257
+ }
1258
+ return values;
1259
+ }
1260
+
1003
1261
  // Log-level priority comparison utility.
1004
1262
  //
1005
1263
  // Extracted from packages/tauri-service/src/logForwarder.ts and
@@ -1158,11 +1416,20 @@ exports.PortManager = PortManager;
1158
1416
  exports.closeLogWriter = closeLogWriter;
1159
1417
  exports.createLogCapture = createLogCapture;
1160
1418
  exports.executeDeeplinkCommand = executeDeeplinkCommand;
1419
+ exports.forEachInstance = forEachInstance;
1161
1420
  exports.getLogWriter = getLogWriter;
1162
1421
  exports.getPlatformCommand = getPlatformCommand;
1422
+ exports.instanceFailuresError = instanceFailuresError;
1163
1423
  exports.isLogWriterInitialized = isLogWriterInitialized;
1424
+ exports.mixedModesError = mixedModesError;
1164
1425
  exports.nonChromeBrowserNameError = nonChromeBrowserNameError;
1426
+ exports.normaliseInstanceCaps = normaliseInstanceCaps;
1165
1427
  exports.probeDevServerReachable = probeDevServerReachable;
1428
+ exports.requireInstance = requireInstance;
1429
+ exports.resolveDevServerUrls = resolveDevServerUrls;
1430
+ exports.runOnEachInstance = runOnEachInstance;
1431
+ exports.settleOnEach = settleOnEach;
1432
+ exports.sharedInstanceCapsError = sharedInstanceCapsError;
1166
1433
  exports.shouldLog = shouldLog;
1167
1434
  exports.startManagedDevServer = startManagedDevServer;
1168
1435
  exports.validateDeeplinkUrl = validateDeeplinkUrl;