Skip to content

Commit 69e91b3

Browse files
authored
perf: use advanced serialization (#792)
1 parent fc9393b commit 69e91b3

14 files changed

Lines changed: 47 additions & 58 deletions

File tree

.vscode/tasks.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
// for the documentation about the tasks.json format
33
{
44
"version": "2.0.0",
5-
"problemMatchers": [
6-
{
7-
"name": "rslib-watch",
8-
"owner": "rslib",
9-
"background": {
10-
"activeOnStart": true,
11-
"beginsPattern": "build started...",
12-
"endsPattern": "build completed, watching for changes..."
13-
},
14-
"pattern": {
15-
"regexp": "build failed in"
16-
}
17-
}
18-
],
195
"tasks": [
206
{
217
"label": "core dev",

packages/browser/src/protocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { DevicePreset } from '@rstest/core/browser';
22
import type {
33
RuntimeConfig,
4-
Test,
54
TestFileResult,
5+
TestInfo,
66
TestResult,
77
} from '@rstest/core/browser-runtime';
88
import type { SnapshotUpdateState } from '@vitest/snapshot';
@@ -96,7 +96,7 @@ export type BrowserClientMessage =
9696
// Collect mode messages
9797
| {
9898
type: 'collect-result';
99-
payload: { testPath: string; project: string; tests: Test[] };
99+
payload: { testPath: string; project: string; tests: TestInfo[] };
100100
}
101101
| { type: 'collect-complete' }
102102
// Unified RPC envelope for all runner -> container/host capability calls.

packages/core/src/browserRuntime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type {
2020
RuntimeConfig,
2121
Test,
2222
TestFileResult,
23+
TestInfo,
2324
TestResult,
2425
WorkerState,
2526
} from './types';

packages/core/src/core/globalSetup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function createSetupPool() {
3333
minThreads: 1,
3434
concurrentTasksPerWorker: 1,
3535
isolateWorkers: false,
36+
serialization: 'advanced',
3637
env: {
3738
NODE_ENV: 'test',
3839
...getForceColorEnv(),

packages/core/src/core/listTests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
Location,
99
ProjectContext,
1010
RstestContext,
11-
Test,
11+
TestInfo,
1212
} from '../types';
1313
import {
1414
bgColor,
@@ -348,7 +348,7 @@ export async function listTests(
348348
type: 'file' | 'suite' | 'case';
349349
}[] = [];
350350

351-
const traverseTests = (test: Test) => {
351+
const traverseTests = (test: TestInfo) => {
352352
if (['skip', 'todo'].includes(test.runMode)) {
353353
return;
354354
}

packages/core/src/pool/forks.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import EventEmitter from 'node:events';
22
import { fileURLToPath } from 'node:url';
3-
import v8 from 'node:v8';
43
import { createBirpc } from 'birpc';
54
import { dirname, resolve } from 'pathe';
65
import { type Options, Tinypool } from 'tinypool';
@@ -50,8 +49,6 @@ export function createForksChannel(
5049
};
5150

5251
const rpc = createBirpcImpl<ServerRPC, RuntimeRPC>(rpcMethods, {
53-
serialize: v8.serialize,
54-
deserialize: (v) => v8.deserialize(Buffer.from(v)),
5552
timeout: -1,
5653
post(v) {
5754
emitter.emit(events.message, v);
@@ -103,6 +100,7 @@ export const createForksPool = (poolOptions: {
103100
minThreads,
104101
concurrentTasksPerWorker: 1,
105102
isolateWorkers: isolate,
103+
serialization: 'advanced',
106104
};
107105

108106
const pool = new Tinypool(options);

packages/core/src/pool/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import type {
99
RstestContext,
1010
RuntimeConfig,
1111
RuntimeRPC,
12-
Test,
1312
TestCaseInfo,
1413
TestFileInfo,
1514
TestFileResult,
15+
TestInfo,
1616
TestResult,
1717
TestSuiteInfo,
1818
UserConsoleLog,
@@ -22,7 +22,6 @@ import {
2222
getForceColorEnv,
2323
isDeno,
2424
needFlagExperimentalDetectModule,
25-
serializableConfig,
2625
} from '../utils';
2726
import { isMemorySufficient } from '../utils/memory';
2827
import { createForksPool } from './forks';
@@ -158,7 +157,7 @@ export const createPool = async ({
158157
project: ProjectContext;
159158
}) => Promise<
160159
{
161-
tests: Test[];
160+
tests: TestInfo[];
162161
testPath: string;
163162
errors?: FormattedError[];
164163
project: string;
@@ -309,7 +308,7 @@ export const createPool = async ({
309308
project: projectName,
310309
rootPath: context.rootPath,
311310
projectRoot: project.rootPath,
312-
runtimeConfig: serializableConfig(runtimeConfig),
311+
runtimeConfig,
313312
},
314313
type: 'run',
315314
setupEntries,
@@ -417,7 +416,7 @@ export const createPool = async ({
417416
outputModule: project.outputModule,
418417
rootPath: context.rootPath,
419418
projectRoot: project.rootPath,
420-
runtimeConfig: serializableConfig(runtimeConfig),
419+
runtimeConfig,
421420
},
422421
type: 'collect',
423422
setupEntries,

packages/core/src/runtime/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type {
22
Rstest,
33
RstestExpect,
44
RunnerHooks,
5-
Test,
65
TestCase,
76
TestFileResult,
7+
TestInfo,
88
WorkerState,
99
} from '../../types';
1010
import { createRunner } from '../runner';
@@ -20,7 +20,7 @@ export const createRstestRuntime = async (
2020
hooks: RunnerHooks,
2121
api: Rstest,
2222
) => Promise<TestFileResult>;
23-
collectTests: () => Promise<Test[]>;
23+
collectTests: () => Promise<TestInfo[]>;
2424
getCurrentTest: () => TestCase | undefined;
2525
};
2626
api: Rstest;

packages/core/src/runtime/runner/index.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
1919
hooks: RunnerHooks,
2020
api: Rstest,
2121
) => Promise<TestFileResult>;
22-
collectTests: () => Promise<Test[]>;
22+
collectTests: () => Promise<TestInfo[]>;
2323
getCurrentTest: TestRunner['getCurrentTest'];
2424
};
2525
} {
@@ -55,18 +55,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
5555
traverseUpdateTest(tests, testNamePattern);
5656
hooks.onTestFileReady?.({
5757
testPath,
58-
tests: tests.map(function toTestInfo(test: Test): TestInfo {
59-
return {
60-
testId: test.testId,
61-
name: test.name,
62-
parentNames: test.parentNames,
63-
testPath: test.testPath,
64-
project: test.project,
65-
type: test.type,
66-
location: test.location,
67-
tests: test.type === 'suite' ? test.tests.map(toTestInfo) : [],
68-
};
69-
}),
58+
tests: tests.map(toTestInfo),
7059
});
7160
runtime.instance.updateStatus('running');
7261

@@ -85,9 +74,23 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
8574
const tests = await runtime.instance.getTests();
8675
traverseUpdateTest(tests, testNamePattern);
8776

88-
return tests;
77+
return tests.map(toTestInfo);
8978
},
9079
getCurrentTest: () => testRunner.getCurrentTest(),
9180
},
9281
};
9382
}
83+
84+
function toTestInfo(test: Test): TestInfo {
85+
return {
86+
testId: test.testId,
87+
name: test.name,
88+
parentNames: test.parentNames,
89+
testPath: test.testPath,
90+
project: test.project,
91+
type: test.type,
92+
location: test.location,
93+
tests: test.type === 'suite' ? test.tests.map(toTestInfo) : [],
94+
runMode: test.runMode,
95+
};
96+
}

packages/core/src/runtime/runner/runner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export class TestRunner {
302302
testId: test.testId,
303303
type: 'suite',
304304
location: test.location,
305+
runMode: test.runMode,
305306
});
306307

307308
if (test.tests.length === 0) {
@@ -393,6 +394,7 @@ export class TestRunner {
393394
project: test.project,
394395
type: 'case',
395396
location: test.location,
397+
runMode: test.runMode,
396398
});
397399

398400
do {

0 commit comments

Comments
 (0)