@rstest/browser 0.9.10 → 0.10.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 (37) hide show
  1. package/dist/augmentExpect.d.ts +1 -1
  2. package/dist/browser-container/container-static/js/{102.e63e4aa16d.js → 484.af891b432a.js} +666 -668
  3. package/dist/browser-container/container-static/js/484.af891b432a.js.LICENSE.txt +1 -0
  4. package/dist/browser-container/container-static/js/{index.af52585634.js → index.463ae8de87.js} +10 -10
  5. package/dist/browser-container/container-static/js/{lib-react.9e703e1b29.js → lib-react.5ae9b90ee5.js} +24 -24
  6. package/dist/browser-container/container-static/js/lib-react.5ae9b90ee5.js.LICENSE.txt +1 -0
  7. package/dist/browser-container/index.html +1 -1
  8. package/dist/browser.d.ts +2 -2
  9. package/dist/client/api.d.ts +2 -2
  10. package/dist/client/browserRpc.d.ts +2 -2
  11. package/dist/client/dispatchTransport.d.ts +1 -1
  12. package/dist/client/locator.d.ts +2 -2
  13. package/dist/concurrency.d.ts +1 -1
  14. package/dist/dispatchCapabilities.d.ts +2 -2
  15. package/dist/dispatchRouter.d.ts +1 -1
  16. package/dist/headlessTransport.d.ts +2 -2
  17. package/dist/hostController.d.ts +2 -2
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +204 -23
  20. package/dist/protocol.d.ts +6 -2
  21. package/dist/providers/index.d.ts +1 -1
  22. package/dist/providers/playwright/compileLocator.d.ts +1 -1
  23. package/dist/providers/playwright/dispatchBrowserRpc.d.ts +1 -1
  24. package/dist/providers/playwright/expectUtils.d.ts +1 -1
  25. package/dist/providers/playwright/implementation.d.ts +1 -1
  26. package/dist/providers/playwright/index.d.ts +1 -1
  27. package/dist/providers/playwright/runtime.d.ts +1 -1
  28. package/dist/providers/playwright/textMatcher.d.ts +2 -2
  29. package/dist/sessionRegistry.d.ts +1 -1
  30. package/dist/viewportPresets.d.ts +1 -1
  31. package/dist/watchRerunPlanner.d.ts +1 -1
  32. package/package.json +8 -8
  33. package/src/client/entry.ts +75 -14
  34. package/src/hostController.ts +403 -70
  35. package/src/protocol.ts +4 -0
  36. package/dist/browser-container/container-static/js/102.e63e4aa16d.js.LICENSE.txt +0 -1
  37. package/dist/browser-container/container-static/js/lib-react.9e703e1b29.js.LICENSE.txt +0 -1
@@ -8,11 +8,13 @@ import {
8
8
  } from '@rstest/browser-manifest';
9
9
  import type {
10
10
  CoverageMapData,
11
+ CurrentTaskInfo,
11
12
  RunnerHooks,
12
13
  RuntimeConfig,
13
14
  WorkerState,
14
15
  } from '@rstest/core/browser-runtime';
15
16
  import {
17
+ createBrowserTaskContext,
16
18
  createRstestRuntime,
17
19
  globalApis,
18
20
  setRealTimers,
@@ -146,19 +148,18 @@ const formatArg = (arg: unknown): string => {
146
148
  }
147
149
  };
148
150
 
151
+ const getFileTaskId = (testPath: string): string => {
152
+ return `file:${testPath}`;
153
+ };
154
+
149
155
  /**
150
156
  * Intercept console methods and forward to host via send().
151
157
  * Returns a restore function to revert console to original.
152
158
  */
153
159
  const interceptConsole = (
154
- testPath: string,
160
+ getCurrentTask: () => CurrentTaskInfo | undefined,
155
161
  printConsoleTrace: boolean,
156
- disableConsoleIntercept: boolean,
157
162
  ): (() => void) => {
158
- if (disableConsoleIntercept) {
159
- return () => {};
160
- }
161
-
162
163
  const originalConsole = {
163
164
  log: console.log.bind(console),
164
165
  warn: console.warn.bind(console),
@@ -183,6 +184,7 @@ const interceptConsole = (
183
184
 
184
185
  // Format message
185
186
  const content = args.map(formatArg).join(' ');
187
+ const currentTask = getCurrentTask();
186
188
 
187
189
  // Send to host
188
190
  send({
@@ -190,7 +192,11 @@ const interceptConsole = (
190
192
  payload: {
191
193
  level,
192
194
  content,
193
- testPath,
195
+ taskId: currentTask?.taskId,
196
+ taskName: currentTask?.taskName,
197
+ taskParentNames: currentTask?.taskParentNames,
198
+ taskType: currentTask?.taskType,
199
+ testPath: currentTask?.testPath ?? '',
194
200
  type: level === 'error' || level === 'warn' ? 'stderr' : 'stdout',
195
201
  trace: getConsoleTrace(),
196
202
  },
@@ -520,7 +526,9 @@ const run = async () => {
520
526
  },
521
527
  };
522
528
 
523
- const runtime = await createRstestRuntime(workerState);
529
+ const runtime = await createRstestRuntime(workerState, {
530
+ taskContext: createBrowserTaskContext(),
531
+ });
524
532
 
525
533
  // Register global APIs if globals config is enabled
526
534
  if (runtimeConfig.globals) {
@@ -570,13 +578,32 @@ const run = async () => {
570
578
  // 2. Run tests for each file
571
579
  for (const key of testKeysToRun) {
572
580
  const testPath = toAbsolutePath(key, currentProject.projectRoot);
581
+ const taskStack: CurrentTaskInfo[] = [
582
+ {
583
+ taskId: getFileTaskId(testPath),
584
+ taskType: 'file',
585
+ testPath,
586
+ },
587
+ ];
588
+
589
+ // Per-file TaskContext; taskStack supplies the concurrent attribution
590
+ // that the single-slot fallback can't.
591
+ const taskContext = createBrowserTaskContext();
592
+
593
+ const shouldInterceptConsole =
594
+ !runtimeConfig.disableConsoleIntercept ||
595
+ runtimeConfig.silent === true ||
596
+ runtimeConfig.silent === 'passed-only';
573
597
 
574
598
  // Intercept console methods to forward logs to host
575
- const restoreConsole = interceptConsole(
576
- testPath,
577
- runtimeConfig.printConsoleTrace ?? false,
578
- runtimeConfig.disableConsoleIntercept ?? false,
579
- );
599
+ const restoreConsole = shouldInterceptConsole
600
+ ? interceptConsole(
601
+ () => taskContext.getCurrent() ?? taskStack[taskStack.length - 1],
602
+ runtimeConfig.disableConsoleIntercept
603
+ ? false
604
+ : (runtimeConfig.printConsoleTrace ?? false),
605
+ )
606
+ : () => {};
580
607
 
581
608
  const workerState: WorkerState = {
582
609
  project: projectRuntime.name,
@@ -586,6 +613,7 @@ const run = async () => {
586
613
  taskId: 0,
587
614
  outputModule: false,
588
615
  environment: 'browser',
616
+ currentTask: taskStack[0],
589
617
  testPath,
590
618
  distPath: testPath,
591
619
  snapshotOptions: {
@@ -595,7 +623,22 @@ const run = async () => {
595
623
  },
596
624
  };
597
625
 
598
- const runtime = await createRstestRuntime(workerState);
626
+ const syncCurrentTask = (): void => {
627
+ workerState.currentTask = taskStack[taskStack.length - 1];
628
+ };
629
+
630
+ const removeTaskFromStack = (taskId: string): void => {
631
+ const taskIndex = taskStack.findLastIndex(
632
+ (task) => task.taskId === taskId,
633
+ );
634
+ if (taskIndex < 0) {
635
+ return;
636
+ }
637
+ taskStack.splice(taskIndex, 1);
638
+ syncCurrentTask();
639
+ };
640
+
641
+ const runtime = await createRstestRuntime(workerState, { taskContext });
599
642
 
600
643
  // Register global APIs if globals config is enabled
601
644
  if (runtimeConfig.globals) {
@@ -611,15 +654,33 @@ const run = async () => {
611
654
  dispatchRunnerLifecycle('file-ready', test);
612
655
  },
613
656
  onTestSuiteStart: async (test) => {
657
+ taskStack.push({
658
+ taskId: test.testId,
659
+ taskName: test.name,
660
+ taskParentNames: test.parentNames,
661
+ taskType: 'suite',
662
+ testPath: test.testPath,
663
+ });
664
+ syncCurrentTask();
614
665
  dispatchRunnerLifecycle('suite-start', test);
615
666
  },
616
667
  onTestSuiteResult: async (result) => {
668
+ removeTaskFromStack(result.testId);
617
669
  dispatchRunnerLifecycle('suite-result', result);
618
670
  },
619
671
  onTestCaseStart: async (test) => {
672
+ taskStack.push({
673
+ taskId: test.testId,
674
+ taskName: test.name,
675
+ taskParentNames: test.parentNames,
676
+ taskType: 'case',
677
+ testPath: test.testPath,
678
+ });
679
+ syncCurrentTask();
620
680
  dispatchRunnerLifecycle('case-start', test);
621
681
  },
622
682
  onTestCaseResult: async (result) => {
683
+ removeTaskFromStack(result.testId);
623
684
  if (result.status === 'fail') {
624
685
  failedTestsCount++;
625
686
  }