Remove directory from workspace by index

We were initially always removing the last folder in the workspace as
we assumed that would be the directory we use.

Now that we've switched to using a temporary directory, this is no longer
the case so we need to find the index of the directory in the list of
workspace folders and then use that index to remove the directory.
This commit is contained in:
Elena Tanasoiu
2023-02-14 18:02:22 +00:00
parent f1227dd2eb
commit 3e87a2d53c

View File

@@ -44,8 +44,14 @@ describe("QlPackGenerator", () => {
try {
dir.removeCallback();
const end = (workspace.workspaceFolders || []).length;
workspace.updateWorkspaceFolders(end - 1, 1);
const workspaceFolders = workspace.workspaceFolders || [];
const folderIndex = workspaceFolders.findIndex(
(workspaceFolder) => workspaceFolder.name === dir.name,
);
if (folderIndex !== undefined) {
workspace.updateWorkspaceFolders(folderIndex, 1);
}
} catch (e) {
console.log(
`Could not remove folder from workspace: ${getErrorMessage(e)}`,
@@ -63,7 +69,6 @@ describe("QlPackGenerator", () => {
expect(isFolderAlreadyInWorkspace(packFolderName)).toBe(true);
expect(existsSync(qlPackYamlFilePath)).toBe(true);
expect(existsSync(exampleQlFilePath)).toBe(true);
expect(packAddSpy).toHaveBeenCalledWith(packFolderPath, language);
});
});