spana-test 0.3.0 → 0.4.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 (50) hide show
  1. package/dist/agent/index.d.ts +1 -1
  2. package/dist/agent/index.js +7 -7
  3. package/dist/{android-PAPJJWVN.js → android-GFW6OXPQ.js} +16 -2
  4. package/dist/{chunk-GZK22EIE.js → chunk-EWIR2GVV.js} +54 -1
  5. package/dist/chunk-EWIR2GVV.js.map +1 -0
  6. package/dist/{chunk-7IA2XG3G.js → chunk-KYPLYRKW.js} +9 -9
  7. package/dist/{chunk-YXQEPVEW.js → chunk-LC3QJIHY.js} +71 -3
  8. package/dist/chunk-LC3QJIHY.js.map +1 -0
  9. package/dist/{chunk-KAKHFSVA.js → chunk-MCT4DYDK.js} +145 -54
  10. package/dist/chunk-MCT4DYDK.js.map +1 -0
  11. package/dist/{chunk-DSTUWLSW.js → chunk-PZYZ4O6D.js} +3 -3
  12. package/dist/{chunk-4OHBO7LD.js → chunk-S5JNNDXS.js} +44 -1
  13. package/dist/{chunk-4OHBO7LD.js.map → chunk-S5JNNDXS.js.map} +1 -1
  14. package/dist/{chunk-24KSKK2I.js → chunk-YAV6KBSW.js} +31 -2
  15. package/dist/chunk-YAV6KBSW.js.map +1 -0
  16. package/dist/{chunk-QPIE3IMG.js → chunk-YGHDMA6D.js} +2 -2
  17. package/dist/cli.js +5 -5
  18. package/dist/{discover-NPNF6SWQ.js → discover-CAQY6EG6.js} +4 -4
  19. package/dist/{doctor-command-C3SEQGRQ.js → doctor-command-YGQPO7GH.js} +3 -3
  20. package/dist/{flow-CW0_j7tw.d.ts → flow-thjUxXXx.d.ts} +24 -2
  21. package/dist/gherkin/steps.d.ts +2 -2
  22. package/dist/index.d.ts +3 -3
  23. package/dist/index.js +2 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/{installer-W5DITECS.js → installer-PVBSX7UC.js} +2 -2
  26. package/dist/{ios-3GRECXAP.js → ios-JPK43TFZ.js} +10 -2
  27. package/dist/{server-MZERO364.js → server-PZBRGU7P.js} +8 -8
  28. package/dist/session-2MZVGYAC.js +17 -0
  29. package/dist/{storybook-BK2JE4ld.d.ts → storybook-pBOPe_1D.d.ts} +6 -2
  30. package/dist/{studio-command-5BUER2RH.js → studio-command-YDWQOMRX.js} +2 -2
  31. package/dist/{test-command-2PXTHASW.js → test-command-B2VLWGDK.js} +86 -15
  32. package/dist/test-command-B2VLWGDK.js.map +1 -0
  33. package/package.json +1 -1
  34. package/dist/chunk-24KSKK2I.js.map +0 -1
  35. package/dist/chunk-GZK22EIE.js.map +0 -1
  36. package/dist/chunk-KAKHFSVA.js.map +0 -1
  37. package/dist/chunk-YXQEPVEW.js.map +0 -1
  38. package/dist/session-3UZ5WAAD.js +0 -17
  39. package/dist/test-command-2PXTHASW.js.map +0 -1
  40. /package/dist/{android-PAPJJWVN.js.map → android-GFW6OXPQ.js.map} +0 -0
  41. /package/dist/{chunk-7IA2XG3G.js.map → chunk-KYPLYRKW.js.map} +0 -0
  42. /package/dist/{chunk-DSTUWLSW.js.map → chunk-PZYZ4O6D.js.map} +0 -0
  43. /package/dist/{chunk-QPIE3IMG.js.map → chunk-YGHDMA6D.js.map} +0 -0
  44. /package/dist/{discover-NPNF6SWQ.js.map → discover-CAQY6EG6.js.map} +0 -0
  45. /package/dist/{doctor-command-C3SEQGRQ.js.map → doctor-command-YGQPO7GH.js.map} +0 -0
  46. /package/dist/{installer-W5DITECS.js.map → installer-PVBSX7UC.js.map} +0 -0
  47. /package/dist/{ios-3GRECXAP.js.map → ios-JPK43TFZ.js.map} +0 -0
  48. /package/dist/{server-MZERO364.js.map → server-PZBRGU7P.js.map} +0 -0
  49. /package/dist/{session-3UZ5WAAD.js.map → session-2MZVGYAC.js.map} +0 -0
  50. /package/dist/{studio-command-5BUER2RH.js.map → studio-command-YDWQOMRX.js.map} +0 -0
@@ -5,16 +5,25 @@ import {
5
5
  adbInstall,
6
6
  adbLaunchApp,
7
7
  adbOpenLink,
8
+ adbResetNetwork,
9
+ adbSetAirplaneMode,
10
+ adbSetCustomNetwork,
11
+ adbSetData,
12
+ adbSetNetworkProfile,
13
+ adbSetWifi,
8
14
  adbShell,
9
15
  findADB
10
- } from "./chunk-GZK22EIE.js";
16
+ } from "./chunk-EWIR2GVV.js";
11
17
  import {
12
18
  installedUrlSchemesOnSimulator,
13
19
  launchOnSimulator,
14
20
  launchWithUrlOnSimulator,
21
+ pfctlResetNetwork,
22
+ pfctlSetOffline,
23
+ pfctlSetThrottle,
15
24
  resetSimulatorKeychain,
16
25
  terminateOnSimulator
17
- } from "./chunk-4OHBO7LD.js";
26
+ } from "./chunk-S5JNNDXS.js";
18
27
  import {
19
28
  allocatePort,
20
29
  releasePort
@@ -23,7 +32,7 @@ import {
23
32
  DriverError,
24
33
  hasLaunchDeviceState,
25
34
  splitGraphemes
26
- } from "./chunk-24KSKK2I.js";
35
+ } from "./chunk-YAV6KBSW.js";
27
36
 
28
37
  // src/drivers/playwright.ts
29
38
  import { readFile, writeFile } from "fs/promises";
@@ -33,6 +42,29 @@ import {
33
42
  firefox,
34
43
  webkit
35
44
  } from "playwright-core";
45
+
46
+ // src/drivers/network-profiles.ts
47
+ var PROFILES = {
48
+ wifi: { offline: false, latencyMs: 2, downloadThroughputKbps: 3e4, uploadThroughputKbps: 15e3 },
49
+ "4g": { offline: false, latencyMs: 20, downloadThroughputKbps: 2e4, uploadThroughputKbps: 1e4 },
50
+ "3g": { offline: false, latencyMs: 100, downloadThroughputKbps: 1500, uploadThroughputKbps: 750 },
51
+ "2g": { offline: false, latencyMs: 300, downloadThroughputKbps: 280, uploadThroughputKbps: 256 },
52
+ edge: { offline: false, latencyMs: 400, downloadThroughputKbps: 240, uploadThroughputKbps: 200 },
53
+ offline: { offline: true, latencyMs: 0, downloadThroughputKbps: 0, uploadThroughputKbps: 0 }
54
+ };
55
+ function resolveNetworkConditions(conditions) {
56
+ if (conditions.profile) {
57
+ return { ...PROFILES[conditions.profile] };
58
+ }
59
+ return {
60
+ offline: conditions.offline ?? false,
61
+ latencyMs: conditions.latencyMs ?? 0,
62
+ downloadThroughputKbps: conditions.downloadThroughputKbps ?? -1,
63
+ uploadThroughputKbps: conditions.uploadThroughputKbps ?? -1
64
+ };
65
+ }
66
+
67
+ // src/drivers/playwright.ts
36
68
  var browserLaunchers = {
37
69
  chromium,
38
70
  firefox,
@@ -76,14 +108,11 @@ function buildMockResponse(response) {
76
108
  };
77
109
  }
78
110
  function toBytesPerSecond(kbps) {
79
- if (kbps === void 0) {
111
+ if (kbps < 0) {
80
112
  return -1;
81
113
  }
82
114
  return Math.max(Math.round(kbps * 1024 / 8), 0);
83
115
  }
84
- function requiresChromiumThrottling(conditions) {
85
- return conditions.latencyMs !== void 0 || conditions.downloadThroughputKbps !== void 0 || conditions.uploadThroughputKbps !== void 0;
86
- }
87
116
  function currentPageUrl(page) {
88
117
  try {
89
118
  return page.url();
@@ -360,23 +389,25 @@ function makePlaywrightDriver(config) {
360
389
  await page.evaluate(CLEAR_STORAGE_SCRIPT);
361
390
  };
362
391
  const applyNetworkConditions = async () => {
363
- if (browserName !== "chromium" && requiresChromiumThrottling(currentNetworkConditions)) {
392
+ const resolved = resolveNetworkConditions(currentNetworkConditions);
393
+ const needsThrottling = resolved.latencyMs > 0 || resolved.downloadThroughputKbps >= 0 || resolved.uploadThroughputKbps >= 0;
394
+ if (browserName !== "chromium" && needsThrottling) {
364
395
  throw new DriverError({
365
396
  message: "setNetworkConditions() latency and throughput controls are only supported with the chromium browser. Use offline mode only for firefox or webkit."
366
397
  });
367
398
  }
368
- await context.setOffline(currentNetworkConditions.offline ?? false);
369
- const shouldUseCDP = browserName === "chromium" && (requiresChromiumThrottling(currentNetworkConditions) || cdpSession !== void 0);
399
+ await context.setOffline(resolved.offline);
400
+ const shouldUseCDP = browserName === "chromium" && (needsThrottling || cdpSession !== void 0);
370
401
  if (!shouldUseCDP) {
371
402
  return;
372
403
  }
373
404
  const session = cdpSession ?? (cdpSession = await context.newCDPSession(page));
374
405
  await session.send("Network.enable");
375
406
  await session.send("Network.emulateNetworkConditions", {
376
- offline: currentNetworkConditions.offline ?? false,
377
- latency: currentNetworkConditions.latencyMs ?? 0,
378
- downloadThroughput: toBytesPerSecond(currentNetworkConditions.downloadThroughputKbps),
379
- uploadThroughput: toBytesPerSecond(currentNetworkConditions.uploadThroughputKbps)
407
+ offline: resolved.offline,
408
+ latency: resolved.latencyMs,
409
+ downloadThroughput: toBytesPerSecond(resolved.downloadThroughputKbps),
410
+ uploadThroughput: toBytesPerSecond(resolved.uploadThroughputKbps)
380
411
  });
381
412
  };
382
413
  const applyRouteDefinition = async (definition) => {
@@ -1301,7 +1332,7 @@ function createUiAutomator2Driver(host, port, serial, packageName) {
1301
1332
  adbForceStop(serial, bundleId);
1302
1333
  if (opts?.launchArguments && Object.keys(opts.launchArguments).length > 0) {
1303
1334
  const { execFileSync } = await import("child_process");
1304
- const { findADB: findADB2 } = await import("./android-PAPJJWVN.js");
1335
+ const { findADB: findADB2 } = await import("./android-GFW6OXPQ.js");
1305
1336
  const adb = findADB2();
1306
1337
  if (!adb) throw new Error("adb not found");
1307
1338
  const startArgs = [
@@ -1380,6 +1411,56 @@ function createUiAutomator2Driver(host, port, serial, packageName) {
1380
1411
  setContext: (contextId) => Effect2.tryPromise({
1381
1412
  try: () => client.setContext(contextId),
1382
1413
  catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
1414
+ }),
1415
+ // -----------------------------------------------------------------------
1416
+ // Network conditions
1417
+ // -----------------------------------------------------------------------
1418
+ setNetworkConditions: (conditions) => Effect2.tryPromise({
1419
+ try: async () => {
1420
+ const isEmulator = serial.startsWith("emulator-");
1421
+ const resolved = resolveNetworkConditions(conditions);
1422
+ const hasThrottling = conditions.profile !== void 0 || conditions.latencyMs !== void 0 || conditions.downloadThroughputKbps !== void 0 || conditions.uploadThroughputKbps !== void 0;
1423
+ if (!resolved.offline && !hasThrottling) {
1424
+ if (isEmulator) {
1425
+ adbResetNetwork(serial);
1426
+ } else {
1427
+ adbSetAirplaneMode(serial, false);
1428
+ }
1429
+ return;
1430
+ }
1431
+ if (resolved.offline) {
1432
+ if (isEmulator) {
1433
+ adbSetWifi(serial, false);
1434
+ adbSetData(serial, false);
1435
+ } else {
1436
+ adbSetAirplaneMode(serial, true);
1437
+ }
1438
+ return;
1439
+ }
1440
+ if (hasThrottling) {
1441
+ if (!isEmulator) {
1442
+ throw new DriverError({
1443
+ message: "Network throttling is not supported on physical Android devices. Use an emulator or a cloud provider."
1444
+ });
1445
+ }
1446
+ adbSetWifi(serial, true);
1447
+ adbSetData(serial, true);
1448
+ if (conditions.profile) {
1449
+ adbSetNetworkProfile(serial, conditions.profile);
1450
+ } else {
1451
+ adbSetCustomNetwork(
1452
+ serial,
1453
+ resolved.downloadThroughputKbps,
1454
+ resolved.uploadThroughputKbps,
1455
+ resolved.latencyMs
1456
+ );
1457
+ }
1458
+ }
1459
+ },
1460
+ catch: (e) => {
1461
+ if (e instanceof DriverError) return e;
1462
+ return new DriverError({ message: `setNetworkConditions failed: ${e}` });
1463
+ }
1383
1464
  })
1384
1465
  };
1385
1466
  return service;
@@ -2149,40 +2230,50 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
2149
2230
  new DriverError({
2150
2231
  message: "WebView context switching requires Appium mode. Use --driver appium with an Appium server that supports XCUITest."
2151
2232
  })
2152
- )
2233
+ ),
2234
+ // -----------------------------------------------------------------------
2235
+ // Network simulation
2236
+ // -----------------------------------------------------------------------
2237
+ setNetworkConditions: (conditions) => Effect3.tryPromise({
2238
+ try: async () => {
2239
+ if (!simulatorUdid) {
2240
+ throw new DriverError({
2241
+ message: "Network simulation is not supported on physical iOS devices. Use a cloud provider (BrowserStack, SauceLabs) for network profiles."
2242
+ });
2243
+ }
2244
+ const hasProfile = !!conditions.profile;
2245
+ const hasOffline = conditions.offline !== void 0;
2246
+ const hasCustom = conditions.latencyMs !== void 0 || conditions.downloadThroughputKbps !== void 0 || conditions.uploadThroughputKbps !== void 0;
2247
+ if (!hasProfile && !hasOffline && !hasCustom) {
2248
+ pfctlResetNetwork();
2249
+ return;
2250
+ }
2251
+ if (hasOffline && conditions.offline) {
2252
+ pfctlSetOffline(true);
2253
+ return;
2254
+ }
2255
+ if (hasProfile || hasCustom) {
2256
+ const resolved = resolveNetworkConditions(conditions);
2257
+ if (resolved.offline) {
2258
+ pfctlSetOffline(true);
2259
+ return;
2260
+ }
2261
+ const throughput = resolved.downloadThroughputKbps === -1 ? 0 : resolved.downloadThroughputKbps;
2262
+ pfctlSetThrottle(throughput, resolved.latencyMs);
2263
+ return;
2264
+ }
2265
+ pfctlSetOffline(false);
2266
+ },
2267
+ catch: (e) => {
2268
+ if (e instanceof DriverError) return e;
2269
+ return new DriverError({ message: `Set network conditions failed: ${e}` });
2270
+ }
2271
+ })
2153
2272
  };
2154
2273
  return service;
2155
2274
  });
2156
2275
  }
2157
2276
 
2158
- // src/drivers/playwright-parser.ts
2159
- function rawNodeToElement(node) {
2160
- const children = node.children && node.children.length > 0 ? node.children.map(rawNodeToElement) : void 0;
2161
- return {
2162
- ...node.id !== void 0 ? { id: node.id } : {},
2163
- ...node.text !== void 0 ? { text: node.text } : {},
2164
- ...node.value !== void 0 ? { value: node.value } : {},
2165
- ...node.accessibilityLabel !== void 0 ? { accessibilityLabel: node.accessibilityLabel } : {},
2166
- // Use role as elementType when present, otherwise fall back to HTML tag name
2167
- ...node.role !== void 0 ? { elementType: node.role } : node.tag !== void 0 ? { elementType: node.tag } : {},
2168
- bounds: {
2169
- x: node.bounds.x,
2170
- y: node.bounds.y,
2171
- width: node.bounds.width,
2172
- height: node.bounds.height
2173
- },
2174
- ...node.enabled !== void 0 ? { enabled: node.enabled } : {},
2175
- ...node.visible !== void 0 ? { visible: node.visible } : {},
2176
- ...node.clickable !== void 0 ? { clickable: node.clickable } : {},
2177
- ...node.attributes !== void 0 ? { attributes: node.attributes } : {},
2178
- ...children !== void 0 ? { children } : {}
2179
- };
2180
- }
2181
- function parseWebHierarchy(json) {
2182
- const raw = JSON.parse(json);
2183
- return rawNodeToElement(raw);
2184
- }
2185
-
2186
2277
  // src/drivers/common/xml-tokenizer.ts
2187
2278
  function parseAttributes(tagContent) {
2188
2279
  const attrs = {};
@@ -2326,7 +2417,7 @@ function prepareAndroidNode(node) {
2326
2417
  prepareAndroidNode(child);
2327
2418
  }
2328
2419
  }
2329
- function rawNodeToElement2(node) {
2420
+ function rawNodeToElement(node) {
2330
2421
  const a = node.attrs;
2331
2422
  const rawId = a["resource-id"] ?? "";
2332
2423
  const id = rawId ? stripResourceIdPrefix(rawId) : void 0;
@@ -2344,7 +2435,7 @@ function rawNodeToElement2(node) {
2344
2435
  for (const [key, val] of Object.entries(a)) {
2345
2436
  if (key !== "bounds") attributes[key] = val;
2346
2437
  }
2347
- const children = node.children.length > 0 ? node.children.map(rawNodeToElement2) : void 0;
2438
+ const children = node.children.length > 0 ? node.children.map(rawNodeToElement) : void 0;
2348
2439
  return {
2349
2440
  ...id !== void 0 ? { id } : {},
2350
2441
  ...text !== void 0 ? { text } : {},
@@ -2368,12 +2459,12 @@ function parseAndroidHierarchy(xml) {
2368
2459
  throw new Error("parseAndroidHierarchy: no root elements found in hierarchy");
2369
2460
  }
2370
2461
  if (roots.length === 1) {
2371
- return rawNodeToElement2(roots[0]);
2462
+ return rawNodeToElement(roots[0]);
2372
2463
  }
2373
2464
  return {
2374
2465
  elementType: "hierarchy",
2375
2466
  bounds: { x: 0, y: 0, width: 0, height: 0 },
2376
- children: roots.map(rawNodeToElement2)
2467
+ children: roots.map(rawNodeToElement)
2377
2468
  };
2378
2469
  }
2379
2470
 
@@ -2404,7 +2495,7 @@ function prepareIOSNode(node) {
2404
2495
  prepareIOSNode(child);
2405
2496
  }
2406
2497
  }
2407
- function rawNodeToElement3(node) {
2498
+ function rawNodeToElement2(node) {
2408
2499
  const a = node.attrs;
2409
2500
  const elementType = node.tagName || void 0;
2410
2501
  const id = a["name"] || void 0;
@@ -2425,7 +2516,7 @@ function rawNodeToElement3(node) {
2425
2516
  for (const [key, val] of Object.entries(a)) {
2426
2517
  attributes[key] = val;
2427
2518
  }
2428
- const children = node.children.length > 0 ? node.children.map(rawNodeToElement3) : void 0;
2519
+ const children = node.children.length > 0 ? node.children.map(rawNodeToElement2) : void 0;
2429
2520
  return {
2430
2521
  ...id !== void 0 ? { id } : {},
2431
2522
  ...text !== void 0 ? { text } : {},
@@ -2450,12 +2541,12 @@ function parseIOSHierarchy(xml) {
2450
2541
  throw new Error("parseIOSHierarchy: no elements found in page source");
2451
2542
  }
2452
2543
  if (roots.length === 1) {
2453
- return rawNodeToElement3(roots[0]);
2544
+ return rawNodeToElement2(roots[0]);
2454
2545
  }
2455
2546
  return {
2456
2547
  elementType: "AppiumAUT",
2457
2548
  bounds: { x: 0, y: 0, width: 0, height: 0 },
2458
- children: roots.map(rawNodeToElement3)
2549
+ children: roots.map(rawNodeToElement2)
2459
2550
  };
2460
2551
  }
2461
2552
 
@@ -2569,12 +2660,12 @@ async function setupUiAutomator2(serial, hostPort) {
2569
2660
  }
2570
2661
 
2571
2662
  export {
2663
+ resolveNetworkConditions,
2572
2664
  makePlaywrightDriver,
2573
2665
  createUiAutomator2Driver,
2574
2666
  createWDADriver,
2575
- parseWebHierarchy,
2576
2667
  parseAndroidHierarchy,
2577
2668
  parseIOSHierarchy,
2578
2669
  setupUiAutomator2
2579
2670
  };
2580
- //# sourceMappingURL=chunk-KAKHFSVA.js.map
2671
+ //# sourceMappingURL=chunk-MCT4DYDK.js.map