Skip to content

Commit

Permalink
fix: include rootPath of virtual folders in testPathPattern value (#1080
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
akwodkiewicz authored Oct 22, 2023
1 parent 10414ab commit 1f33012
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 263 deletions.
10 changes: 7 additions & 3 deletions src/test-provider/test-item-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { JestExtOutput } from '../JestExt/output-terminal';
import { tiContextManager } from './test-item-context-manager';
import { toAbsoluteRootPath } from '../helpers';
import { runModeDescription } from '../JestExt/run-mode';
import { isVirtualWorkspaceFolder } from '../virtual-workspace-folder';

interface JestRunnable {
getJestRunRequest: () => JestExtRequestType;
Expand Down Expand Up @@ -129,10 +130,13 @@ export class WorkspaceRoot extends TestItemDataBase {
this.registerEvents();
}
createTestItem(): vscode.TestItem {
const workspaceFolder = this.context.ext.workspace;
const item = this.context.createTestItem(
`${extensionId}:${this.context.ext.workspace.name}`,
this.context.ext.workspace.name,
this.context.ext.workspace.uri,
`${extensionId}:${workspaceFolder.name}`,
workspaceFolder.name,
isVirtualWorkspaceFolder(workspaceFolder)
? workspaceFolder.effectiveUri
: workspaceFolder.uri,
this,
undefined,
['run']
Expand Down
11 changes: 6 additions & 5 deletions src/virtual-workspace-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ export class VirtualFolderBasedCache<T extends FolderAwareItem> {
}

/**
* a virtual workspace folder is a folder resides in a physical workspace folder but might have
* A virtual workspace folder is a folder resides in a physical workspace folder but might have
* different name and separate jest settings. A physical workspace folder can have multiple virtual folders.
* 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).
* Note: The class will have the same index and the uri as the actual workspace folder, but a different name.
*/
export class VirtualWorkspaceFolder implements vscode.WorkspaceFolder {
// the URI with the rootPath applied
private effectiveUri: vscode.Uri;
/** URI pointing to the virtual folder, including rootPath */
public readonly effectiveUri: vscode.Uri;

constructor(
public readonly actualWorkspaceFolder: vscode.WorkspaceFolder,
public readonly name: string,
Expand All @@ -110,7 +111,7 @@ export class VirtualWorkspaceFolder implements vscode.WorkspaceFolder {
return this.actualWorkspaceFolder.uri;
}

/** check if the given uri falls within the virtual folder's path */
/** Check if the given uri falls within the virtual folder's path */
isInWorkspaceFolder(uri: vscode.Uri): boolean {
return uri.fsPath.startsWith(this.effectiveUri.fsPath);
}
Expand Down
Loading

0 comments on commit 1f33012

Please sign in to comment.