Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/runtime/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const preparePool = async ({

const cleanupFns: (() => MaybePromise<void>)[] = [];

const { rpc } = createRuntimeRpc(createForksRpcOptions());
const originalConsole = global.console;

const { rpc } = createRuntimeRpc(createForksRpcOptions(), {
originalConsole,
});
const {
runtimeConfig: {
globals,
Expand Down
33 changes: 31 additions & 2 deletions packages/core/src/runtime/worker/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import v8 from 'node:v8';
import { type BirpcOptions, type BirpcReturn, createBirpc } from 'birpc';
import type { TinypoolWorkerMessage } from 'tinypool';
import type { RuntimeRPC, ServerRPC } from '../../types';
import type { RuntimeRPC, ServerRPC, TestResult } from '../../types';

export type WorkerRPC = BirpcReturn<RuntimeRPC, ServerRPC>;

Expand Down Expand Up @@ -43,8 +43,37 @@ export function createRuntimeRpc(
BirpcOptions<void>,
'on' | 'post' | 'serialize' | 'deserialize'
>,
{
originalConsole,
}: {
originalConsole: Console;
},
): { rpc: WorkerRPC } {
const rpc = createBirpc<RuntimeRPC, ServerRPC>({}, options);
const rpc = createBirpc<RuntimeRPC, ServerRPC>(
{},
{
...options,
onTimeoutError: (functionName, error) => {
switch (functionName) {
case 'onTestCaseResult': {
const caseResult = error[0] as unknown as TestResult;
console.error(
`[Rstest] timeout on calling "onTestCaseResult" rpc method (Case: "${caseResult.name}", Result: "${caseResult.status}")`,
);
return true;
}
case 'onConsoleLog': {
originalConsole.error(
`[Rstest] timeout on calling "onConsoleLog" rpc method (Original log: ${error[0].content})`,
);
return true;
}
default:
return false;
}
},
},
);

return {
rpc,
Expand Down
Loading