@wdio/native-core 1.3.0 → 2.0.0-next.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 (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 +1 -0
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +239 -31
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/instances.d.ts +46 -0
  14. package/dist/cjs/instances.d.ts.map +1 -0
  15. package/dist/cjs/logWriter.d.ts.map +1 -1
  16. package/dist/cjs/package.json +1 -1
  17. package/dist/cjs/portManager.d.ts.map +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 +1 -0
  29. package/dist/esm/index.d.ts.map +1 -1
  30. package/dist/esm/index.js +236 -33
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/instances.d.ts +46 -0
  33. package/dist/esm/instances.d.ts.map +1 -0
  34. package/dist/esm/logWriter.d.ts.map +1 -1
  35. package/dist/esm/package.json +1 -1
  36. package/dist/esm/portManager.d.ts.map +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 -10
@@ -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,KAAK,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K,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"],"names":[],"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AAE,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,KAAK,I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ED,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,7 @@ 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 './instances.js';
7
8
  export * from './logCapture.js';
8
9
  export * from './logLevel.js';
9
10
  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,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) {
@@ -474,11 +526,9 @@ class DriverPool {
474
526
 
475
527
  // Port allocation for driver subprocesses.
476
528
  //
477
- // Extracted unchanged from packages/tauri-service/src/portManager.ts (the
478
- // only modification is the `createLogger` argument). The "port pair"
479
- // abstraction (main driver port + native driver port) maps directly onto
480
- // both Tauri's (tauri-driver + msedgedriver/WebKitWebDriver) and Dioxus's
481
- // (wdio-dioxus-driver + msedgedriver) external-provider layout.
529
+ // The "port pair" abstraction (main driver port + native driver port) maps
530
+ // directly onto both Tauri's (tauri-driver + msedgedriver/WebKitWebDriver) and
531
+ // Dioxus's (wdio-dioxus-driver + msedgedriver) external-provider layout.
482
532
  //
483
533
  // Services that use a single port (e.g., the embedded provider) call
484
534
  // `allocatePort` instead of `allocatePortPair`.
@@ -624,7 +674,7 @@ const defaultKill = (proc, signal) => {
624
674
  return;
625
675
  }
626
676
  if (isWindows) {
627
- node_child_process.spawn('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore' }).on('error', () => { });
677
+ killWindowsProcessTree(proc);
628
678
  return;
629
679
  }
630
680
  try {
@@ -801,6 +851,21 @@ function nonChromeBrowserNameError(browserName, allowed = [BROWSER_MODE_SUPPORTE
801
851
  return (`Browser mode only supports browserName: '${BROWSER_MODE_SUPPORTED_BROWSER}', but got '${browserName}'. ` +
802
852
  `Remove the browserName from your capability (it is set automatically) or set it to '${BROWSER_MODE_SUPPORTED_BROWSER}'.`);
803
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
+ }
804
869
  /**
805
870
  * Preflight the dev server before the worker navigates to it.
806
871
  *
@@ -819,8 +884,56 @@ async function probeDevServerReachable(url, timeoutMs = DEV_SERVER_PROBE_TIMEOUT
819
884
  return nativeUtils.Err(new Error(`Dev server not reachable at ${url} — is it running? (${detail})`));
820
885
  }
821
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
+ }
822
920
  const DEV_SERVER_READY_TIMEOUT_MS = 60_000;
823
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
+ }
824
937
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
825
938
  /**
826
939
  * Poll {@link probeDevServerReachable} until the server answers or the budget elapses.
@@ -845,6 +958,7 @@ async function waitForDevServerReachable(url, { timeoutMs = DEV_SERVER_READY_TIM
845
958
  * (no subprocess spawn/kill involved). The returned `url` supplies/overrides `devServerUrl`.
846
959
  * - **string / object** — if `reuseExistingServer` (default `!CI`) and `devServerUrl` is already
847
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.
848
962
  *
849
963
  * The caller stores the returned `stop` and must call it in `onComplete` *and* on an `onPrepare`
850
964
  * failure (WDIO does not call `onComplete` after `onPrepare` throws). `stop` is idempotent.
@@ -865,11 +979,17 @@ async function startManagedDevServer(devServer, devServerUrl, deps = {}) {
865
979
  const config = typeof devServer === 'string' ? { command: devServer } : devServer;
866
980
  const isCI = deps.isCI ?? Boolean(process.env.CI);
867
981
  const reuseExisting = config.reuseExistingServer ?? !isCI;
868
- 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) {
869
988
  log$2.info(`Reusing dev server already reachable at ${devServerUrl}`);
870
989
  return { url: devServerUrl, stop: async () => { } };
871
990
  }
872
991
  const proc = new DevServerProcess({ spawn: deps.spawn, probe: deps.probe });
992
+ activeManagedServers.add(origin);
873
993
  try {
874
994
  await proc.start({
875
995
  command: config.command,
@@ -882,10 +1002,25 @@ async function startManagedDevServer(devServer, devServerUrl, deps = {}) {
882
1002
  catch (error) {
883
1003
  // start() can throw *after* the process spawned (readiness timeout) — stop the live-but-unready
884
1004
  // process before propagating, or it orphans (holding the port). Mirrors the function form's close().
885
- await proc.stop();
1005
+ try {
1006
+ await proc.stop();
1007
+ }
1008
+ finally {
1009
+ activeManagedServers.delete(origin);
1010
+ }
886
1011
  throw error;
887
1012
  }
888
- 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
+ };
889
1024
  }
890
1025
 
891
1026
  // Platform-specific deeplink (URL protocol-handler) helpers.
@@ -1002,6 +1137,73 @@ async function executeDeeplinkCommand(command, args, env) {
1002
1137
  });
1003
1138
  }
1004
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
+
1005
1207
  // Log-level priority comparison utility.
1006
1208
  //
1007
1209
  // Extracted from packages/tauri-service/src/logForwarder.ts and
@@ -1085,6 +1287,7 @@ class LogWriter {
1085
1287
  */
1086
1288
  write(message, prefixedMessage) {
1087
1289
  if (!this.logStream) {
1290
+ // biome-ignore lint/suspicious/noConsole: stdout fallback before the log file is open
1088
1291
  console.log(message);
1089
1292
  return;
1090
1293
  }
@@ -1159,11 +1362,16 @@ exports.PortManager = PortManager;
1159
1362
  exports.closeLogWriter = closeLogWriter;
1160
1363
  exports.createLogCapture = createLogCapture;
1161
1364
  exports.executeDeeplinkCommand = executeDeeplinkCommand;
1365
+ exports.forEachInstance = forEachInstance;
1162
1366
  exports.getLogWriter = getLogWriter;
1163
1367
  exports.getPlatformCommand = getPlatformCommand;
1164
1368
  exports.isLogWriterInitialized = isLogWriterInitialized;
1369
+ exports.mixedModesError = mixedModesError;
1165
1370
  exports.nonChromeBrowserNameError = nonChromeBrowserNameError;
1371
+ exports.normaliseInstanceCaps = normaliseInstanceCaps;
1166
1372
  exports.probeDevServerReachable = probeDevServerReachable;
1373
+ exports.requireInstance = requireInstance;
1374
+ exports.resolveDevServerUrls = resolveDevServerUrls;
1167
1375
  exports.shouldLog = shouldLog;
1168
1376
  exports.startManagedDevServer = startManagedDevServer;
1169
1377
  exports.validateDeeplinkUrl = validateDeeplinkUrl;