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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fixtures-test/
fixtures-test-*/
.rslib/
!packages/core/src/coverage
!packages/core/tests/coverage
tests-dist/
.vscode-test/
packages/vscode/*.vsix
Expand Down
23 changes: 12 additions & 11 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,47 @@
"test": "npx rstest --globals"
},
"dependencies": {
"@types/chai": "^5.2.3",
"@rsbuild/core": "1.7.1",
"@types/chai": "^5.2.3",
"tinypool": "^1.1.1"
},
"devDependencies": {
"chai": "^5.3.3",
"pathe": "^2.0.3",
"birpc": "2.9.0",
"@vitest/expect": "^3.2.4",
"@vitest/snapshot": "^3.2.4",
"@babel/code-frame": "^7.27.1",
"@jridgewell/trace-mapping": "0.3.31",
"@microsoft/api-extractor": "^7.55.2",
"@rslib/core": "^0.19.0",
"@rstest/tsconfig": "workspace:*",
"@sinonjs/fake-timers": "^15.1.0",
"@types/babel__code-frame": "^7.0.6",
"@types/istanbul-reports": "^3.0.4",
"@types/istanbul-lib-coverage": "^2.0.6",
"@types/istanbul-lib-report": "^3.0.3",
"@types/istanbul-reports": "^3.0.4",
"@types/jsdom": "^21.1.7",
"@types/picomatch": "^4.0.2",
"@types/sinonjs__fake-timers": "^8.1.5",
"@types/source-map-support": "^0.5.10",
"@types/picomatch": "^4.0.2",
"@vitest/expect": "^3.2.4",
"@vitest/snapshot": "^3.2.4",
"birpc": "2.9.0",
"cac": "^6.7.14",
"chai": "^5.3.3",
"chokidar": "^4.0.3",
"happy-dom": "^20.0.11",
"jest-diff": "^30.2.0",
"jsdom": "^26.1.0",
"webpack-license-plugin": "^4.5.1",
"memfs": "^4.51.1",
"pathe": "^2.0.3",
"picocolors": "^1.1.1",
"picomatch": "^4.0.3",
"pretty-format": "^30.2.0",
"rslog": "^1.3.2",
"source-map-support": "^0.5.21",
"std-env": "^3.10.0",
"stacktrace-parser": "0.1.11",
"std-env": "^3.10.0",
"strip-ansi": "^7.1.2",
"tinyglobby": "^0.2.15",
"tinyspy": "^4.0.4",
"picomatch": "^4.0.3"
"webpack-license-plugin": "^4.5.1"
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The alphabetical reordering of dependencies in package.json is not related to the bug fix and should be separated into its own commit or PR. Mixing code formatting/organization changes with functional changes makes it harder to review and understand what's actually necessary for the fix.

The only functional change needed here is adding "memfs": "^4.51.1" to devDependencies. The reordering of existing entries like moving @types/chai, chai, pathe, birpc, etc. is purely cosmetic.

Suggested change
"webpack-license-plugin": "^4.5.1"
"webpack-license-plugin": "^4.5.1",
"memfs": "^4.51.1"

Copilot uses AI. Check for mistakes.
},
"peerDependencies": {
"happy-dom": "*",
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ const createDefaultConfig = (): NormalizedConfig => ({
coverage: {
exclude: [
'**/node_modules/**',
'**/[.]*',
'**/dist/**',
'**/test/**',
'**/__tests__/**',
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/coverage/generate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { normalize } from 'pathe';
import { glob, isDynamicPattern } from 'tinyglobby';
import { type GlobOptions, glob, isDynamicPattern } from 'tinyglobby';
import type { RstestContext, TestFileResult } from '../types';
import type {
CoverageMap,
Expand All @@ -8,9 +8,10 @@ import type {
} from '../types/coverage';
import { logger } from '../utils';

const getIncludedFiles = async (
export const getIncludedFiles = async (
coverage: CoverageOptions,
rootPath: string,
fs?: GlobOptions['fs'],
): Promise<string[]> => {
// fix issue with glob not working correctly when exclude path was not in the cwd
const ignoredPatterns = coverage.exclude?.filter(
Expand All @@ -24,8 +25,8 @@ const getIncludedFiles = async (
absolute: true,
onlyFiles: true,
ignore: ignoredPatterns,
dot: true,
expandDirectories: false,
fs,
});

// 'a.ts' should match 'src/a.ts'
Expand Down
1 change: 0 additions & 1 deletion packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports[`mergeRstestConfig > should merge config correctly with default config 1
"enabled": false,
"exclude": [
"**/node_modules/**",
"**/[.]*",
"**/dist/**",
"**/test/**",
"**/__tests__/**",
Expand Down
3 changes: 0 additions & 3 deletions packages/core/tests/core/__snapshots__/rstest.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports[`rstest context > should generate rstest context correctly 1`] = `
"enabled": false,
"exclude": [
"**/node_modules/**",
"**/[.]*",
"**/dist/**",
"**/test/**",
"**/__tests__/**",
Expand Down Expand Up @@ -88,7 +87,6 @@ exports[`rstest context > should generate rstest context correctly with multiple
"enabled": false,
"exclude": [
"**/node_modules/**",
"**/[.]*",
"**/dist/**",
"**/test/**",
"**/__tests__/**",
Expand Down Expand Up @@ -170,7 +168,6 @@ exports[`rstest context > should generate rstest context correctly with multiple
"enabled": false,
"exclude": [
"**/node_modules/**",
"**/[.]*",
"**/dist/**",
"**/test/**",
"**/__tests__/**",
Expand Down
98 changes: 98 additions & 0 deletions packages/core/tests/coverage/include.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import path from 'node:path';
import type { GlobOptions } from 'tinyglobby';
import { withDefaultConfig } from '../../src/config';
import { getIncludedFiles } from '../../src/coverage/generate';

describe('getIncludedFiles', () => {
let defaultExclude: string[] = [];
let memfs!: GlobOptions['fs'];
beforeAll(async () => {
const { fs } = await import('memfs');
defaultExclude = withDefaultConfig({}).coverage.exclude;
memfs = fs as any;

// There's a bug in tinyglobby: if the computed common root path cannot be the root of the Windows volume, the root path will be resolved to pwd.
[
'/root/apps/a.ts',
'/root/apps/b.js',
'/root/apps/.c.ts',
'/root/apps/node_modules/a.ts',
'/root/apps/dist/a.ts',
'/root/apps/test/a.ts',
'/root/apps/__tests__/a.ts',
'/root/apps/__mocks__/a.ts',
'/root/apps/a.d.ts',
'/root/apps/a.test.ts',
'/root/apps/a.spec.ts',
'/root/apps/a.test.js',
'/root/apps/a.spec.js',
'/root/apps/a.test.mts',
'/root/apps/a.spec.mts',
'/root/apps/a.test.cts',
'/root/apps/a.spec.cts',
'/root/apps/a.test.tsx',
'/root/apps/a.spec.tsx',
'/root/packages/a.ts',
'/root/packages/b.js',
'/root/packages/.c.ts',
].forEach((file) => {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, '');
});
});

const glob = async (include: string[], exclude: string[] = []) => {
const files = await getIncludedFiles(
{
include,
exclude: [...defaultExclude, ...exclude],
},
'/root/apps',
memfs,
);
// ensure consistent paths across platforms
return files
.map((file) => path.relative('/root', file).replaceAll(path.sep, '/'))
.sort();
};

it('should include visible files by default', async () => {
expect(
await glob(['**/*.{js,ts}', '../packages/*.{js,ts}']),
).toMatchInlineSnapshot(`
[
"apps/a.ts",
"apps/b.js",
"packages/a.ts",
"packages/b.js",
]
`);
});

it('should include hidden files if explicitly specified', async () => {
expect(await glob(['**/*.{js,ts}', '**/.c.ts'])).toMatchInlineSnapshot(`
[
"apps/.c.ts",
"apps/a.ts",
"apps/b.js",
]
`);
});

it('should exclude node_modules, dist, test, __tests__, __mocks__ by default', async () => {
expect(await glob(['**/*'])).toMatchInlineSnapshot(`
[
"apps/a.ts",
"apps/b.js",
]
`);
});

it('should exclude .d.ts files by default', async () => {
expect(await glob(['**/*.d.ts'])).toMatchInlineSnapshot('[]');
});

it('should exclude test and spec files by default', async () => {
expect(await glob(['**/*.{test,spec}.*'])).toMatchInlineSnapshot('[]');
});
});
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion website/docs/en/config/test/coverage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export default defineConfig({
'**/test/**',
'**/__tests__/**',
'**/__mocks__/**',
'**/[.]*',
'**/*.d.ts',
'**/*.{test,spec}.[jt]s',
'**/*.{test,spec}.[cm][jt]s',
Expand Down
1 change: 0 additions & 1 deletion website/docs/zh/config/test/coverage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export default defineConfig({
'**/test/**',
'**/__tests__/**',
'**/__mocks__/**',
'**/[.]*',
'**/*.d.ts',
'**/*.{test,spec}.[jt]s',
'**/*.{test,spec}.[cm][jt]s',
Expand Down
Loading