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
8 changes: 7 additions & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
mergeRsbuildConfig,
} from '@rsbuild/core';
import { dirname, isAbsolute, join, resolve } from 'pathe';
import type { NormalizedConfig, RstestConfig } from './types';
import type { NormalizedConfig, ProjectConfig, RstestConfig } from './types';
import {
castArray,
color,
Expand Down Expand Up @@ -76,6 +76,12 @@ export async function loadConfig({
return { content: content as RstestConfig, filePath: configFilePath };
}

export const mergeProjectConfig = (
...configs: ProjectConfig[]
): ProjectConfig => {
return mergeRstestConfig(...configs) as ProjectConfig;
Comment on lines +79 to +82
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type cast from RstestConfig to ProjectConfig is potentially unsafe. Since mergeRstestConfig can include properties like reporters, pool, coverage, etc. that are explicitly omitted from ProjectConfig, the returned object may contain properties that violate the ProjectConfig type contract. Consider implementing a proper merge function that only handles ProjectConfig properties, or add runtime filtering to remove the omitted properties before returning.

Suggested change
export const mergeProjectConfig = (
...configs: ProjectConfig[]
): ProjectConfig => {
return mergeRstestConfig(...configs) as ProjectConfig;
// Helper to pick only ProjectConfig properties from an object
function pickProjectConfigProps(obj: any): ProjectConfig {
// List of allowed ProjectConfig keys. Update this list if ProjectConfig changes.
const allowedKeys = [
'root',
'include',
'exclude',
'testTimeout',
'testMatch',
'testEnvironment',
'globals',
'setupFiles',
'teardownFiles',
'transform',
'moduleNameMapper',
'extensionsToTreatAsEsm',
'watch',
'silent',
'bail',
'maxWorkers',
'snapshotFormat',
'snapshotSerializers',
'resolver',
'testSequencer',
'testPathIgnorePatterns',
'testRegex',
'testRunner',
'testURL',
'verbose',
// Add more keys as needed if ProjectConfig changes
];
return Object.fromEntries(
Object.entries(obj).filter(([key]) => allowedKeys.includes(key))
) as ProjectConfig;
}
export const mergeProjectConfig = (
...configs: ProjectConfig[]
): ProjectConfig => {
const merged = mergeRstestConfig(...configs);
return pickProjectConfigProps(merged);

Copilot uses AI. Check for mistakes.
};
Comment on lines +79 to +83
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly exported mergeProjectConfig function lacks test coverage. Since the repository has comprehensive tests for mergeRstestConfig in packages/core/tests/config.test.ts, consider adding tests for mergeProjectConfig to ensure it correctly merges ProjectConfig objects and doesn't inadvertently include properties that should be omitted from ProjectConfig.

Copilot uses AI. Check for mistakes.

export const mergeRstestConfig = (...configs: RstestConfig[]): RstestConfig => {
return configs.reduce<RstestConfig>((result, config) => {
const merged = mergeRsbuildConfig(result, {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
} from './types';

export { initCli, runCLI } from './cli';
export { loadConfig, mergeRstestConfig } from './config';
export { loadConfig, mergeProjectConfig, mergeRstestConfig } from './config';
export { createRstest } from './core';

export * from './runtime/api/public';
Expand Down
Loading