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
2 changes: 2 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ export const withDefaultConfig = (config: RstestConfig): NormalizedConfig => {
tsconfigPaths: merged.source?.tsconfigPath
? [merged.source.tsconfigPath]
: [],
coverageEnabled: merged.coverage?.enabled,
coverageProvider: merged.coverage?.provider,
outputDistPathRoot: merged.output.distPath.root,
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/core/rstest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export class Rstest implements RstestContext {
outputDistPathRoot: rstestConfig.output.distPath.root,
environmentName,
browserEnabled: config.browser.enabled,
coverageEnabled: config.coverage?.enabled,
coverageProvider: config.coverage?.provider,
assumeNormalized: true,
});
}
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type BuildCacheInput = {
command?: string;
environmentName?: string;
browserEnabled?: boolean;
coverageEnabled?: boolean;
coverageProvider?: string;
outputDistPathRoot?: string;
assumeNormalized?: boolean;
};
Expand All @@ -83,6 +85,8 @@ export const normalizeBuildCache = ({
command,
environmentName,
browserEnabled,
coverageEnabled,
coverageProvider,
outputDistPathRoot,
assumeNormalized = false,
}: BuildCacheInput): false | RstestBuildCacheConfig => {
Expand Down Expand Up @@ -111,13 +115,17 @@ export const normalizeBuildCache = ({

const userCacheDigest =
assumeNormalized && userConfig.cacheDigest?.[0] === 'rstest'
? userConfig.cacheDigest.slice(5)
? userConfig.cacheDigest.slice(6)
: userConfig.cacheDigest || [];
const coverageDigest = coverageEnabled
? `coverage:${coverageProvider}`
: 'no-coverage';
const cacheDigest = [
'rstest',
command,
environmentName,
browserEnabled ? 'browser' : 'node',
coverageDigest,
outputDistPathRoot,
...userCacheDigest,
];
Expand Down Expand Up @@ -206,6 +214,8 @@ export const resolveProjectBuildCache = ({
command: context.command,
environmentName: project.environmentName,
browserEnabled: project.normalizedConfig.browser.enabled,
coverageEnabled: project.normalizedConfig.coverage?.enabled,
coverageProvider: project.normalizedConfig.coverage?.provider,
outputDistPathRoot: context.normalizedConfig.output.distPath.root,
assumeNormalized: true,
});
Expand Down
74 changes: 72 additions & 2 deletions packages/core/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'pathe';
import { mergeRstestConfig, withDefaultConfig } from '../src/config';
import { Rstest } from '../src/core/rstest';
import type { RstestConfig } from '../src/types';
import { resolveProjectBuildCache } from '../src/utils';
import { normalizeBuildCache, resolveProjectBuildCache } from '../src/utils';

// Mock std-env to ensure consistent snapshot across environments
rs.mock('std-env', () => ({
Expand Down Expand Up @@ -76,6 +76,7 @@ describe('mergeRstestConfig', () => {
undefined,
undefined,
'node',
'no-coverage',
'dist/.rstest-temp',
],
buildDependencies: [resolve(__dirname, 'tsconfig.custom.json')],
Expand Down Expand Up @@ -104,13 +105,73 @@ describe('mergeRstestConfig', () => {
undefined,
undefined,
'node',
'no-coverage',
'custom/.rstest-temp',
'user-digest',
],
buildDependencies: [resolve(__dirname, 'a.config.ts')],
});
});

it('should include coverage state and provider in buildCache digest', () => {
const withoutCoverage = withDefaultConfig({
root: __dirname,
performance: {
buildCache: true,
},
});
const withCoverage = withDefaultConfig({
root: __dirname,
coverage: {
enabled: true,
},
performance: {
buildCache: true,
},
});

expect(withoutCoverage.performance?.buildCache).toMatchObject({
cacheDigest: [
'rstest',
undefined,
undefined,
'node',
'no-coverage',
'dist/.rstest-temp',
],
});
expect(withCoverage.performance?.buildCache).toMatchObject({
cacheDigest: [
'rstest',
undefined,
undefined,
'node',
'coverage:istanbul',
'dist/.rstest-temp',
],
});

const withCustomProvider = normalizeBuildCache({
buildCache: true,
root: __dirname,
browserEnabled: false,
coverageEnabled: true,
coverageProvider: 'custom',
outputDistPathRoot: 'dist/.rstest-temp',
});

expect(withCustomProvider).toMatchObject({
cacheDigest: [
'rstest',
undefined,
undefined,
'node',
'coverage:custom',
'dist/.rstest-temp',
],
});
});

it('should resolve buildCache buildDependencies relative to config file directory', () => {
const rstest = new Rstest(
{
Expand All @@ -135,6 +196,7 @@ describe('mergeRstestConfig', () => {
undefined,
undefined,
'node',
'no-coverage',
'dist/.rstest-temp',
],
buildDependencies: ['/repo/configs/cache-flags.ts'],
Expand Down Expand Up @@ -249,6 +311,7 @@ describe('mergeRstestConfig', () => {
undefined,
'browser',
'node',
'no-coverage',
'dist/.rstest-temp',
],
buildDependencies: [],
Expand All @@ -257,7 +320,14 @@ describe('mergeRstestConfig', () => {
rstest.projects[1]?.normalizedConfig.performance?.buildCache,
).toEqual({
cacheDirectory: '/repo/projects/node/node_modules/.cache/rstest-node',
cacheDigest: ['rstest', undefined, 'node', 'node', 'dist/.rstest-temp'],
cacheDigest: [
'rstest',
undefined,
'node',
'node',
'no-coverage',
'dist/.rstest-temp',
],
buildDependencies: [],
});
expect(
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/core/rsbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ describe('prepareRsbuild', () => {
'run',
'test',
'node',
'no-coverage',
TEMP_RSTEST_OUTPUT_DIR,
'root-digest',
],
Expand Down
Loading