Skip to content

Commit 3e87a2d

Browse files
committed
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.
1 parent f1227dd commit 3e87a2d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

extensions/ql-vscode/test/vscode-tests/minimal-workspace/qlpack-generator.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ describe("QlPackGenerator", () => {
4444
try {
4545
dir.removeCallback();
4646

47-
const end = (workspace.workspaceFolders || []).length;
48-
workspace.updateWorkspaceFolders(end - 1, 1);
47+
const workspaceFolders = workspace.workspaceFolders || [];
48+
const folderIndex = workspaceFolders.findIndex(
49+
(workspaceFolder) => workspaceFolder.name === dir.name,
50+
);
51+
52+
if (folderIndex !== undefined) {
53+
workspace.updateWorkspaceFolders(folderIndex, 1);
54+
}
4955
} catch (e) {
5056
console.log(
5157
`Could not remove folder from workspace: ${getErrorMessage(e)}`,
@@ -63,7 +69,6 @@ describe("QlPackGenerator", () => {
6369
expect(isFolderAlreadyInWorkspace(packFolderName)).toBe(true);
6470
expect(existsSync(qlPackYamlFilePath)).toBe(true);
6571
expect(existsSync(exampleQlFilePath)).toBe(true);
66-
6772
expect(packAddSpy).toHaveBeenCalledWith(packFolderPath, language);
6873
});
6974
});

0 commit comments

Comments
 (0)