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
14 changes: 0 additions & 14 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"problemMatchers": [
{
"name": "rslib-watch",
"owner": "rslib",
"background": {
"activeOnStart": true,
"beginsPattern": "build started...",
"endsPattern": "build completed, watching for changes..."
},
"pattern": {
"regexp": "build failed in"
}
}
],
"tasks": [
{
Comment thread
claneo marked this conversation as resolved.
"label": "core dev",
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { DevicePreset } from '@rstest/core/browser';
import type {
RuntimeConfig,
Test,
TestFileResult,
TestInfo,
TestResult,
} from '@rstest/core/browser-runtime';
import type { SnapshotUpdateState } from '@vitest/snapshot';
Expand Down Expand Up @@ -96,7 +96,7 @@ export type BrowserClientMessage =
// Collect mode messages
| {
type: 'collect-result';
payload: { testPath: string; project: string; tests: Test[] };
payload: { testPath: string; project: string; tests: TestInfo[] };
}
| { type: 'collect-complete' }
// Unified RPC envelope for all runner -> container/host capability calls.
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/browserRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type {
RuntimeConfig,
Test,
TestFileResult,
TestInfo,
TestResult,
WorkerState,
} from './types';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/core/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function createSetupPool() {
minThreads: 1,
concurrentTasksPerWorker: 1,
isolateWorkers: false,
serialization: 'advanced',
env: {
NODE_ENV: 'test',
...getForceColorEnv(),
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/core/listTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
Location,
ProjectContext,
RstestContext,
Test,
TestInfo,
} from '../types';
import {
bgColor,
Expand Down Expand Up @@ -348,7 +348,7 @@ export async function listTests(
type: 'file' | 'suite' | 'case';
}[] = [];

const traverseTests = (test: Test) => {
const traverseTests = (test: TestInfo) => {
if (['skip', 'todo'].includes(test.runMode)) {
return;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/pool/forks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EventEmitter from 'node:events';
import { fileURLToPath } from 'node:url';
import v8 from 'node:v8';
import { createBirpc } from 'birpc';
import { dirname, resolve } from 'pathe';
import { type Options, Tinypool } from 'tinypool';
Expand Down Expand Up @@ -50,8 +49,6 @@ export function createForksChannel(
};

const rpc = createBirpcImpl<ServerRPC, RuntimeRPC>(rpcMethods, {
serialize: v8.serialize,
deserialize: (v) => v8.deserialize(Buffer.from(v)),
timeout: -1,
post(v) {
emitter.emit(events.message, v);
Expand Down Expand Up @@ -103,6 +100,7 @@ export const createForksPool = (poolOptions: {
minThreads,
concurrentTasksPerWorker: 1,
isolateWorkers: isolate,
serialization: 'advanced',
};

const pool = new Tinypool(options);
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type {
RstestContext,
RuntimeConfig,
RuntimeRPC,
Test,
TestCaseInfo,
TestFileInfo,
TestFileResult,
TestInfo,
TestResult,
TestSuiteInfo,
UserConsoleLog,
Expand All @@ -22,7 +22,6 @@ import {
getForceColorEnv,
isDeno,
needFlagExperimentalDetectModule,
serializableConfig,
} from '../utils';
import { isMemorySufficient } from '../utils/memory';
import { createForksPool } from './forks';
Expand Down Expand Up @@ -158,7 +157,7 @@ export const createPool = async ({
project: ProjectContext;
}) => Promise<
{
tests: Test[];
tests: TestInfo[];
testPath: string;
errors?: FormattedError[];
project: string;
Expand Down Expand Up @@ -309,7 +308,7 @@ export const createPool = async ({
project: projectName,
rootPath: context.rootPath,
projectRoot: project.rootPath,
runtimeConfig: serializableConfig(runtimeConfig),
runtimeConfig,
},
type: 'run',
setupEntries,
Expand Down Expand Up @@ -417,7 +416,7 @@ export const createPool = async ({
outputModule: project.outputModule,
rootPath: context.rootPath,
projectRoot: project.rootPath,
runtimeConfig: serializableConfig(runtimeConfig),
runtimeConfig,
},
type: 'collect',
setupEntries,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/runtime/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type {
Rstest,
RstestExpect,
RunnerHooks,
Test,
TestCase,
TestFileResult,
TestInfo,
WorkerState,
} from '../../types';
import { createRunner } from '../runner';
Expand All @@ -20,7 +20,7 @@ export const createRstestRuntime = async (
hooks: RunnerHooks,
api: Rstest,
) => Promise<TestFileResult>;
collectTests: () => Promise<Test[]>;
collectTests: () => Promise<TestInfo[]>;
getCurrentTest: () => TestCase | undefined;
};
api: Rstest;
Expand Down
31 changes: 17 additions & 14 deletions packages/core/src/runtime/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
hooks: RunnerHooks,
api: Rstest,
) => Promise<TestFileResult>;
collectTests: () => Promise<Test[]>;
collectTests: () => Promise<TestInfo[]>;
getCurrentTest: TestRunner['getCurrentTest'];
};
} {
Expand Down Expand Up @@ -55,18 +55,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
traverseUpdateTest(tests, testNamePattern);
hooks.onTestFileReady?.({
testPath,
tests: tests.map(function toTestInfo(test: Test): TestInfo {
return {
testId: test.testId,
name: test.name,
parentNames: test.parentNames,
testPath: test.testPath,
project: test.project,
type: test.type,
location: test.location,
tests: test.type === 'suite' ? test.tests.map(toTestInfo) : [],
};
}),
tests: tests.map(toTestInfo),
});
runtime.instance.updateStatus('running');

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

return tests;
return tests.map(toTestInfo);
},
getCurrentTest: () => testRunner.getCurrentTest(),
},
};
}

function toTestInfo(test: Test): TestInfo {
return {
testId: test.testId,
name: test.name,
parentNames: test.parentNames,
testPath: test.testPath,
project: test.project,
type: test.type,
location: test.location,
tests: test.type === 'suite' ? test.tests.map(toTestInfo) : [],
runMode: test.runMode,
};
}
2 changes: 2 additions & 0 deletions packages/core/src/runtime/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class TestRunner {
testId: test.testId,
type: 'suite',
location: test.location,
runMode: test.runMode,
});

if (test.tests.length === 0) {
Expand Down Expand Up @@ -393,6 +394,7 @@ export class TestRunner {
project: test.project,
type: 'case',
location: test.location,
runMode: test.runMode,
});

do {
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/runtime/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import type {
MaybePromise,
Rstest,
RunWorkerOptions,
Test,
TestFileResult,
TestInfo,
WorkerState,
} from '../../types';
import './setup';
import type { FileCoverageData } from 'istanbul-lib-coverage';
import { install } from 'source-map-support';
import { createCoverageProvider } from '../../coverage';
import { createWorkerMetaMessage } from '../../pool/workerMeta';
import { globalApis } from '../../utils/constants';
import { undoSerializableConfig } from '../../utils/helper';
import { color } from '../../utils/logger';
import { formatTestError, getRealTimers, setRealTimers } from '../util';
import { createForksRpcOptions, createRuntimeRpc } from './rpc';
Expand Down Expand Up @@ -65,7 +65,6 @@ const preparePool = async ({
globalCleanups.length = 0;

setRealTimers();
context.runtimeConfig = undoSerializableConfig(context.runtimeConfig);

// Prefer public env var from tinypool, fallback to context.taskId
process.env.RSTEST_WORKER_ID = String(
Expand Down Expand Up @@ -273,7 +272,7 @@ const runInPool = async (
options: RunWorkerOptions['options'],
): Promise<
| {
tests: Test[];
tests: TestInfo[];
testPath: string;
}
| TestFileResult
Expand Down Expand Up @@ -462,7 +461,12 @@ const runInPool = async (
const coverageMap = coverageProvider.collect();
if (coverageMap) {
// Attach coverage data to test result
results.coverage = coverageMap.toJSON();
results.coverage = {};
Object.entries(coverageMap.toJSON()).forEach(([key, value]) => {
if ('toJSON' in value)
results.coverage![key] = value.toJSON() as FileCoverageData;
else results.coverage![key] = value;
});
}
// Cleanup
coverageProvider.cleanup();
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/runtime/worker/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import v8 from 'node:v8';
import { type BirpcOptions, type BirpcReturn, createBirpc } from 'birpc';
import type { TinypoolWorkerMessage } from 'tinypool';
import type { RuntimeRPC, ServerRPC } from '../../types';
Expand All @@ -15,15 +14,11 @@ export type WorkerRpcOptions = Pick<
>;

export function createForksRpcOptions({
nodeV8 = v8,
dispose = [],
}: {
nodeV8?: typeof v8;
dispose?: (() => void)[];
}): WorkerRpcOptions {
return {
serialize: nodeV8.serialize,
deserialize: (v) => nodeV8.deserialize(Buffer.from(v)),
post(v) {
processSend(v);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import type {
import type { Reporter } from './reporter';
import type {
FormattedError,
Test,
TestCaseInfo,
TestFileResult,
TestInfo,
TestResult,
} from './testSuite';

Expand Down Expand Up @@ -93,7 +93,7 @@ export type ListCommandOptions = {
};

export type ListCommandResult = {
tests: Test[];
tests: TestInfo[];
testPath: string;
project: string;
errors?: FormattedError[];
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/types/testSuite.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { SnapshotResult } from '@vitest/snapshot';
import type { FileCoverageData } from 'istanbul-lib-coverage';
import type {
NormalizedFixtures,
OnTestFailedHandler,
OnTestFinishedHandler,
TestContext,
} from './api';
import type { CoverageMapData } from './coverage';
import type { MaybePromise, TestPath } from './utils';

export type TestRunMode = 'run' | 'skip' | 'todo' | 'only';
Expand Down Expand Up @@ -43,12 +43,12 @@ export type TestCaseInfo = {
/** Only included when `includeTaskLocation` config is enabled */
location?: Location;
type: 'case';
runMode: TestRunMode;
};

export type TestCase = TestCaseInfo & {
originalFn?: (context: TestContext) => void | Promise<void>;
fn?: (context: TestContext) => void | Promise<void>;
runMode: TestRunMode;
fails?: boolean;
each?: boolean;
fixtures?: NormalizedFixtures;
Expand Down Expand Up @@ -98,10 +98,10 @@ export type TestSuiteInfo = {
type: 'suite';
/** Only included when `includeTaskLocation` config is enabled */
location?: Location;
runMode: TestRunMode;
};

export type TestSuite = TestSuiteInfo & {
runMode: TestRunMode;
each?: boolean;
inTestEach?: boolean;
concurrent?: boolean;
Expand Down Expand Up @@ -159,7 +159,7 @@ export type TestResult = {
export type TestFileResult = TestResult & {
results: TestResult[];
snapshotResult?: SnapshotResult;
coverage?: CoverageMapData;
coverage?: Record<string, FileCoverageData>;
};

export interface UserConsoleLog {
Expand Down
Loading