@rstest/browser 0.9.10 → 0.10.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.
- package/dist/augmentExpect.d.ts +1 -1
- package/dist/browser-container/container-static/js/{102.e63e4aa16d.js → 188.480c3c49b5.js} +4543 -4250
- package/dist/browser-container/container-static/js/188.480c3c49b5.js.LICENSE.txt +1 -0
- package/dist/browser-container/container-static/js/{index.af52585634.js → index.29fc60be33.js} +10 -10
- package/dist/browser-container/container-static/js/{lib-react.9e703e1b29.js → lib-react.5ae9b90ee5.js} +24 -24
- package/dist/browser-container/container-static/js/lib-react.5ae9b90ee5.js.LICENSE.txt +1 -0
- package/dist/browser-container/index.html +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/client/api.d.ts +2 -2
- package/dist/client/browserRpc.d.ts +2 -2
- package/dist/client/dispatchTransport.d.ts +1 -1
- package/dist/client/locator.d.ts +2 -2
- package/dist/concurrency.d.ts +1 -1
- package/dist/dispatchCapabilities.d.ts +2 -2
- package/dist/dispatchRouter.d.ts +1 -1
- package/dist/headlessTransport.d.ts +2 -2
- package/dist/hostController.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +205 -23
- package/dist/protocol.d.ts +6 -2
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/playwright/compileLocator.d.ts +1 -1
- package/dist/providers/playwright/dispatchBrowserRpc.d.ts +1 -1
- package/dist/providers/playwright/expectUtils.d.ts +1 -1
- package/dist/providers/playwright/implementation.d.ts +1 -1
- package/dist/providers/playwright/index.d.ts +1 -1
- package/dist/providers/playwright/runtime.d.ts +1 -1
- package/dist/providers/playwright/textMatcher.d.ts +2 -2
- package/dist/sessionRegistry.d.ts +1 -1
- package/dist/viewportPresets.d.ts +1 -1
- package/dist/watchRerunPlanner.d.ts +1 -1
- package/package.json +9 -9
- package/src/client/entry.ts +75 -14
- package/src/hostController.ts +405 -70
- package/src/protocol.ts +4 -0
- package/dist/browser-container/container-static/js/102.e63e4aa16d.js.LICENSE.txt +0 -1
- package/dist/browser-container/container-static/js/lib-react.9e703e1b29.js.LICENSE.txt +0 -1
package/src/client/entry.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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 =
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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
|
|
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
|
}
|