Skip to content

Commit bdafa1c

Browse files
9aoyCopilot
andauthored
chore(vscode-extension): update default test file glob pattern (#694)
Co-authored-by: Copilot <[email protected]>
1 parent 8adf325 commit bdafa1c

File tree

13 files changed

+82
-23
lines changed

13 files changed

+82
-23
lines changed

packages/core/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ const createDefaultConfig = (): NormalizedConfig => ({
161161
// This option accepts an array of wax(https://crates.io/crates/wax)-compatible glob patterns
162162
// not support `?()`: '**/*.{test,spec}.?(c|m)[jt]s?(x)',
163163
'**/*.{test,spec}.[jt]s',
164-
'**/*.{test,spec}.[c|m][jt]s',
164+
'**/*.{test,spec}.[cm][jt]s',
165165
'**/*.{test,spec}.[jt]sx',
166-
'**/*.{test,spec}.[c|m][jt]sx',
166+
'**/*.{test,spec}.[cm][jt]sx',
167167
],
168168
enabled: false,
169169
provider: 'istanbul',

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ exports[`mergeRstestConfig > should merge config correctly with default config 1
1616
"**/__mocks__/**",
1717
"**/*.d.ts",
1818
"**/*.{test,spec}.[jt]s",
19-
"**/*.{test,spec}.[c|m][jt]s",
19+
"**/*.{test,spec}.[cm][jt]s",
2020
"**/*.{test,spec}.[jt]sx",
21-
"**/*.{test,spec}.[c|m][jt]sx",
21+
"**/*.{test,spec}.[cm][jt]sx",
2222
],
2323
"provider": "istanbul",
2424
"reportOnFailure": false,

packages/core/tests/core/__snapshots__/rstest.test.ts.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ exports[`rstest context > should generate rstest context correctly 1`] = `
1616
"**/__mocks__/**",
1717
"**/*.d.ts",
1818
"**/*.{test,spec}.[jt]s",
19-
"**/*.{test,spec}.[c|m][jt]s",
19+
"**/*.{test,spec}.[cm][jt]s",
2020
"**/*.{test,spec}.[jt]sx",
21-
"**/*.{test,spec}.[c|m][jt]sx",
21+
"**/*.{test,spec}.[cm][jt]sx",
2222
],
2323
"provider": "istanbul",
2424
"reportOnFailure": false,
@@ -93,9 +93,9 @@ exports[`rstest context > should generate rstest context correctly with multiple
9393
"**/__mocks__/**",
9494
"**/*.d.ts",
9595
"**/*.{test,spec}.[jt]s",
96-
"**/*.{test,spec}.[c|m][jt]s",
96+
"**/*.{test,spec}.[cm][jt]s",
9797
"**/*.{test,spec}.[jt]sx",
98-
"**/*.{test,spec}.[c|m][jt]sx",
98+
"**/*.{test,spec}.[cm][jt]sx",
9999
],
100100
"provider": "istanbul",
101101
"reportOnFailure": false,
@@ -173,9 +173,9 @@ exports[`rstest context > should generate rstest context correctly with multiple
173173
"**/__mocks__/**",
174174
"**/*.d.ts",
175175
"**/*.{test,spec}.[jt]s",
176-
"**/*.{test,spec}.[c|m][jt]s",
176+
"**/*.{test,spec}.[cm][jt]s",
177177
"**/*.{test,spec}.[jt]sx",
178-
"**/*.{test,spec}.[c|m][jt]sx",
178+
"**/*.{test,spec}.[cm][jt]sx",
179179
],
180180
"provider": "istanbul",
181181
"reportOnFailure": false,

packages/vscode/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
"type": "string"
3636
},
3737
"default": [
38-
"**/*.test.*",
39-
"**/*.spec.*"
38+
"**/*.{test,spec}.[jt]s",
39+
"**/*.{test,spec}.[cm][jt]s",
40+
"**/*.{test,spec}.[jt]sx",
41+
"**/*.{test,spec}.[cm][jt]sx"
4042
]
4143
},
4244
"rstest.rstestPackagePath": {

packages/vscode/src/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ export type ExtensionConfig = {
1212
};
1313

1414
export const defaultConfig: ExtensionConfig = {
15-
testFileGlobPattern: ['**/*.test.*', '**/*.spec.*'],
15+
// https://code.visualstudio.com/docs/editor/glob-patterns
16+
testFileGlobPattern: [
17+
'**/*.{test,spec}.[jt]s',
18+
'**/*.{test,spec}.[cm][jt]s',
19+
'**/*.{test,spec}.[jt]sx',
20+
'**/*.{test,spec}.[cm][jt]sx',
21+
],
1622
};
1723

1824
// Type-safe getter for a single config value with priority:

packages/vscode/src/extension.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
TestFile,
1010
testData,
1111
} from './testTree';
12-
import { getWorkspaceTestPatterns, shouldIgnorePath } from './utils';
12+
import {
13+
getWorkspaceTestPatterns,
14+
isTestFile,
15+
shouldIgnorePath,
16+
} from './utils';
1317

1418
export async function activate(context: vscode.ExtensionContext) {
1519
const rstest = new Rstest(context);
@@ -322,8 +326,7 @@ function startWatchingWorkspace(
322326
}
323327

324328
function isTestFilePath(uri: vscode.Uri): boolean {
325-
const filename = uri.path.split('/').pop() || uri.path;
326-
return filename.includes('.test.') || filename.includes('.spec.');
329+
return isTestFile(uri.path.split('/').pop() || uri.path);
327330
}
328331

329332
class RstestFileCoverage extends vscode.FileCoverage {

packages/vscode/src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export function shouldIgnorePath(path: string) {
99
);
1010
}
1111

12+
export function isTestFile(filename: string): boolean {
13+
const regex = /.*\.(test|spec)\.(c|m)?[jt]sx?$/;
14+
return regex.test(filename);
15+
}
16+
1217
export type WorkspaceTestPattern = {
1318
workspaceFolder: vscode.WorkspaceFolder;
1419
pattern: vscode.GlobPattern;

packages/vscode/tests/fixtures/.vscode/settings.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Test fixture file to verify that non-JS/TS files are excluded from test discovery
2+
const { describe, it, expect } = require('@rstest/core');
3+
4+
describe('JS', () => {
5+
it('should run in JS', () => {
6+
expect(1).toBe(1);
7+
});
8+
});

packages/vscode/tests/suite/config.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,23 @@ suite('Configuration Integration', () => {
3232
const prev = config.get('testFileGlobPattern');
3333

3434
try {
35-
// 1) Only discover *.spec.* files
35+
await testController.resolveHandler?.(undefined as any);
36+
await delay(200);
37+
38+
const defaultRootsSpec: vscode.TestItem[] = [];
39+
testController.items.forEach((it) => {
40+
defaultRootsSpec.push(it);
41+
});
42+
assert.equal(
43+
defaultRootsSpec.length,
44+
5,
45+
'Should discover all test files',
46+
);
47+
48+
// 1) Only discover *.spec.js/ts files
3649
await config.update(
3750
'testFileGlobPattern',
38-
['**/*.spec.*'],
51+
['**/*.spec.[jt]s'],
3952
vscode.ConfigurationTarget.Workspace,
4053
);
4154

@@ -54,6 +67,12 @@ suite('Configuration Integration', () => {
5467
),
5568
'Should include jsFile.spec.js',
5669
);
70+
assert.ok(
71+
!rootsSpec.some((it) =>
72+
it.id.endsWith('/tests/fixtures/test/jsFile.spec.js.txt'),
73+
),
74+
'Should not include jsFile.spec.js.txt',
75+
);
5776
// Ensure no duplicate non-spec-only additions by counting unique suffixes
5877
assert.ok(
5978
!rootsSpec.some((it) =>

0 commit comments

Comments
 (0)