From 89adc787df4aa1ecd379960010362e515f89695b Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 21 Dec 2022 20:01:35 -0800 Subject: [PATCH] test-provider: adjust workspace location handling The VSCode reported workspace path is unresolved (microsoft/vscode#18837). When the repository is hosted in a path substituted path (e.g. `subst X: C:`), the test path will not be properly translated as the drive is different. This may potentially also impact paths which are hosted within a NT junction. Explicitly resolve the workspace path to match the fact that `jest` will report paths which have been resolved to the real path. --- src/test-provider/test-item-data.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test-provider/test-item-data.ts b/src/test-provider/test-item-data.ts index 0cc2c0b65..1a88d5ebd 100644 --- a/src/test-provider/test-item-data.ts +++ b/src/test-provider/test-item-data.ts @@ -195,7 +195,15 @@ export class WorkspaceRoot extends TestItemDataBase { ); }; private addPath = (absoluteFileName: string): FolderData | undefined => { - const relativePath = path.relative(this.context.ext.workspace.uri.fsPath, absoluteFileName); + const fs = require('fs'); + + // On Windows, the workspace URI is not the real resolved path, however, the + // paths returned by the jest cli tool are resolved paths. Explicitly + // resolve the path to ensure that we get the proper relative path. Note + // that we must use `fs.realpath.native` as `fs.realpath` will only + // canonicalise the path, not resolve any path substitutions. + const workspace = fs.realpathSync.native(this.context.ext.workspace.uri.fsPath); + const relativePath = path.relative(workspace, absoluteFileName); const folders = relativePath.split(path.sep).slice(0, -1); return folders.reduce(this.addFolder, undefined);