Skip to content

Commit 1f33012

Browse files
authored
fix: include rootPath of virtual folders in testPathPattern value (#1080)
* expose readonly VirtualWorkspaceFolder.effectiveUri * use effectiveUri for virtual folders when creating test items * test: add unit tests for VirtualWorkspaceFolder.effectiveUri * ref: nest WorkspaceRoot tests into a separate suite This commit's purpose is to separate the code style changes from the actual modifications (new tests) added in the next commit. * test: add WorkspaceRoot.createTestItem tests for item's URI
1 parent 10414ab commit 1f33012

File tree

4 files changed

+333
-263
lines changed

4 files changed

+333
-263
lines changed

src/test-provider/test-item-data.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { JestExtOutput } from '../JestExt/output-terminal';
1616
import { tiContextManager } from './test-item-context-manager';
1717
import { toAbsoluteRootPath } from '../helpers';
1818
import { runModeDescription } from '../JestExt/run-mode';
19+
import { isVirtualWorkspaceFolder } from '../virtual-workspace-folder';
1920

2021
interface JestRunnable {
2122
getJestRunRequest: () => JestExtRequestType;
@@ -129,10 +130,13 @@ export class WorkspaceRoot extends TestItemDataBase {
129130
this.registerEvents();
130131
}
131132
createTestItem(): vscode.TestItem {
133+
const workspaceFolder = this.context.ext.workspace;
132134
const item = this.context.createTestItem(
133-
`${extensionId}:${this.context.ext.workspace.name}`,
134-
this.context.ext.workspace.name,
135-
this.context.ext.workspace.uri,
135+
`${extensionId}:${workspaceFolder.name}`,
136+
workspaceFolder.name,
137+
isVirtualWorkspaceFolder(workspaceFolder)
138+
? workspaceFolder.effectiveUri
139+
: workspaceFolder.uri,
136140
this,
137141
undefined,
138142
['run']

src/virtual-workspace-folder.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ export class VirtualFolderBasedCache<T extends FolderAwareItem> {
8585
}
8686

8787
/**
88-
* a virtual workspace folder is a folder resides in a physical workspace folder but might have
88+
* A virtual workspace folder is a folder resides in a physical workspace folder but might have
8989
* different name and separate jest settings. A physical workspace folder can have multiple virtual folders.
9090
91-
* Note: The class will have the same index as the actual workspace folder, but different name and uri (if it has set a different rootPath).
91+
* Note: The class will have the same index and the uri as the actual workspace folder, but a different name.
9292
*/
9393
export class VirtualWorkspaceFolder implements vscode.WorkspaceFolder {
94-
// the URI with the rootPath applied
95-
private effectiveUri: vscode.Uri;
94+
/** URI pointing to the virtual folder, including rootPath */
95+
public readonly effectiveUri: vscode.Uri;
96+
9697
constructor(
9798
public readonly actualWorkspaceFolder: vscode.WorkspaceFolder,
9899
public readonly name: string,
@@ -110,7 +111,7 @@ export class VirtualWorkspaceFolder implements vscode.WorkspaceFolder {
110111
return this.actualWorkspaceFolder.uri;
111112
}
112113

113-
/** check if the given uri falls within the virtual folder's path */
114+
/** Check if the given uri falls within the virtual folder's path */
114115
isInWorkspaceFolder(uri: vscode.Uri): boolean {
115116
return uri.fsPath.startsWith(this.effectiveUri.fsPath);
116117
}

0 commit comments

Comments
 (0)