@ricsam/isolate-client 0.1.19 → 0.1.21

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,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/isolate-client",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "type": "commonjs"
5
5
  }
@@ -17,6 +17,7 @@ import {
17
17
  deserializeResponse
18
18
  } from "@ricsam/isolate-protocol";
19
19
  import {
20
+ defaultPlaywrightHandler,
20
21
  getDefaultPlaywrightHandlerMetadata
21
22
  } from "@ricsam/isolate-playwright/client";
22
23
  var isolateWsCallbacks = new Map;
@@ -152,6 +153,7 @@ async function connect(options = {}) {
152
153
  testEnvironmentOption = true;
153
154
  }
154
155
  }
156
+ const playwrightOption = runtimeOptions.playwright?.timeout !== undefined ? { timeout: runtimeOptions.playwright.timeout } : undefined;
155
157
  const requestId = st.nextRequestId++;
156
158
  const request = {
157
159
  type: MessageType.CREATE_RUNTIME,
@@ -161,6 +163,7 @@ async function connect(options = {}) {
161
163
  cwd: runtimeOptions.cwd,
162
164
  callbacks,
163
165
  testEnvironment: testEnvironmentOption,
166
+ playwright: playwrightOption,
164
167
  namespaceId
165
168
  }
166
169
  };
@@ -471,7 +474,32 @@ function isBenignDisposeError(error) {
471
474
  const message = error instanceof Error ? error.message : String(error ?? "");
472
475
  return /isolate not owned by this connection|isolate not found|not connected|connection closed/i.test(message);
473
476
  }
477
+ function normalizePlaywrightOptions(playwrightOptions) {
478
+ if (!playwrightOptions || playwrightOptions.timeout === undefined) {
479
+ return playwrightOptions;
480
+ }
481
+ const metadata = getDefaultPlaywrightHandlerMetadata(playwrightOptions.handler);
482
+ if (!metadata?.page) {
483
+ return playwrightOptions;
484
+ }
485
+ const currentTimeout = metadata.options?.timeout ?? 30000;
486
+ if (currentTimeout === playwrightOptions.timeout) {
487
+ return playwrightOptions;
488
+ }
489
+ return {
490
+ ...playwrightOptions,
491
+ handler: defaultPlaywrightHandler(metadata.page, {
492
+ ...metadata.options,
493
+ timeout: playwrightOptions.timeout
494
+ })
495
+ };
496
+ }
474
497
  async function createRuntime(state, options = {}, namespaceId) {
498
+ const normalizedPlaywrightOptions = normalizePlaywrightOptions(options.playwright);
499
+ const runtimeOptionsForReconnect = normalizedPlaywrightOptions === options.playwright ? options : {
500
+ ...options,
501
+ playwright: normalizedPlaywrightOptions
502
+ };
475
503
  const callbacks = {};
476
504
  if (options.console) {
477
505
  callbacks.console = registerConsoleCallbacks(state, options.console);
@@ -493,8 +521,8 @@ async function createRuntime(state, options = {}, namespaceId) {
493
521
  const networkRequests = [];
494
522
  const networkResponses = [];
495
523
  const pageListenerCleanups = [];
496
- if (options.playwright) {
497
- playwrightHandler = options.playwright.handler;
524
+ if (normalizedPlaywrightOptions) {
525
+ playwrightHandler = normalizedPlaywrightOptions.handler;
498
526
  if (!playwrightHandler) {
499
527
  throw new Error("playwright.handler is required when using playwright options");
500
528
  }
@@ -513,18 +541,18 @@ async function createRuntime(state, options = {}, namespaceId) {
513
541
  timestamp: Date.now()
514
542
  };
515
543
  browserConsoleLogs.push(entry);
516
- if (options.playwright.onEvent) {
517
- options.playwright.onEvent({
544
+ if (normalizedPlaywrightOptions.onEvent) {
545
+ normalizedPlaywrightOptions.onEvent({
518
546
  type: "browserConsoleLog",
519
547
  ...entry
520
548
  });
521
549
  }
522
- if (options.playwright.console && options.console?.onEntry) {
550
+ if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
523
551
  options.console.onEntry({
524
552
  type: "browserOutput",
525
553
  ...entry
526
554
  });
527
- } else if (options.playwright.console) {
555
+ } else if (normalizedPlaywrightOptions.console) {
528
556
  const prefix = entry.level === "error" ? "[browser:error]" : "[browser]";
529
557
  console.log(prefix, entry.stdout);
530
558
  }
@@ -537,8 +565,8 @@ async function createRuntime(state, options = {}, namespaceId) {
537
565
  timestamp: Date.now()
538
566
  };
539
567
  networkRequests.push(info);
540
- if (options.playwright.onEvent) {
541
- options.playwright.onEvent({
568
+ if (normalizedPlaywrightOptions.onEvent) {
569
+ normalizedPlaywrightOptions.onEvent({
542
570
  type: "networkRequest",
543
571
  ...info
544
572
  });
@@ -552,8 +580,8 @@ async function createRuntime(state, options = {}, namespaceId) {
552
580
  timestamp: Date.now()
553
581
  };
554
582
  networkResponses.push(info);
555
- if (options.playwright.onEvent) {
556
- options.playwright.onEvent({
583
+ if (normalizedPlaywrightOptions.onEvent) {
584
+ normalizedPlaywrightOptions.onEvent({
557
585
  type: "networkResponse",
558
586
  ...info
559
587
  });
@@ -566,7 +594,7 @@ async function createRuntime(state, options = {}, namespaceId) {
566
594
  }
567
595
  callbacks.playwright = {
568
596
  handlerCallbackId,
569
- console: options.playwright.console && !options.console?.onEntry
597
+ console: normalizedPlaywrightOptions.console && !options.console?.onEntry
570
598
  };
571
599
  }
572
600
  let testEnvironmentOption;
@@ -594,6 +622,7 @@ async function createRuntime(state, options = {}, namespaceId) {
594
622
  testEnvironmentOption = true;
595
623
  }
596
624
  }
625
+ const playwrightOption = normalizedPlaywrightOptions?.timeout !== undefined ? { timeout: normalizedPlaywrightOptions.timeout } : undefined;
597
626
  const requestId = state.nextRequestId++;
598
627
  const request = {
599
628
  type: MessageType.CREATE_RUNTIME,
@@ -603,6 +632,7 @@ async function createRuntime(state, options = {}, namespaceId) {
603
632
  cwd: options.cwd,
604
633
  callbacks,
605
634
  testEnvironment: testEnvironmentOption,
635
+ playwright: playwrightOption,
606
636
  namespaceId
607
637
  }
608
638
  };
@@ -612,7 +642,7 @@ async function createRuntime(state, options = {}, namespaceId) {
612
642
  if (namespaceId != null) {
613
643
  state.namespacedRuntimes.set(namespaceId, {
614
644
  isolateId,
615
- runtimeOptions: options
645
+ runtimeOptions: runtimeOptionsForReconnect
616
646
  });
617
647
  }
618
648
  const wsCommandCallbacks = new Set;
@@ -825,7 +855,7 @@ async function createRuntime(state, options = {}, namespaceId) {
825
855
  }
826
856
  };
827
857
  const testEnvironmentEnabled = !!options.testEnvironment;
828
- const playwrightEnabled = !!options.playwright;
858
+ const playwrightEnabled = !!normalizedPlaywrightOptions;
829
859
  const testEnvironmentHandle = {
830
860
  async runTests(timeout) {
831
861
  if (!testEnvironmentEnabled) {
@@ -1664,4 +1694,4 @@ export {
1664
1694
  connect
1665
1695
  };
1666
1696
 
1667
- //# debugId=7EA890CF5E7314ED64756E2164756E21
1697
+ //# debugId=17E01CA2373935E664756E2164756E21