Skip to content

Commit eac634a

Browse files
authored
Fix build commands test (#1552)
- Provide target name as context instead of open editor - Retry mechanism for debugging
1 parent 5c5177d commit eac634a

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

test/integration-tests/commands/build.test.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { testAssetUri } from "../../fixtures";
2121
import { FolderContext } from "../../../src/FolderContext";
2222
import { WorkspaceContext } from "../../../src/WorkspaceContext";
2323
import { Commands } from "../../../src/commands";
24-
import { Workbench } from "../../../src/utilities/commands";
2524
import { continueSession, waitForDebugAdapterRequest } from "../../utilities/debug";
2625
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
2726
import { Version } from "../../../src/utilities/version";
@@ -42,51 +41,31 @@ suite("Build Commands @slow", function () {
4241
// The description of this package is crashing on Windows with Swift 5.9.x and below
4342
if (
4443
process.platform === "win32" &&
45-
ctx.globalToolchain.swiftVersion.isLessThanOrEqual(new Version(5, 9, 0))
44+
ctx.globalToolchain.swiftVersion.isLessThan(new Version(5, 10, 0))
4645
) {
4746
this.skip();
4847
}
48+
// A breakpoint will have not effect on the Run command.
49+
vscode.debug.addBreakpoints(breakpoints);
4950

5051
workspaceContext = ctx;
5152
await waitForNoRunningTasks();
5253
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
5354
await workspaceContext.focusFolder(folderContext);
54-
await vscode.window.showTextDocument(uri);
55-
},
56-
async teardown() {
57-
await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS);
5855
},
5956
requiresDebugger: true,
6057
});
6158

62-
test("Swift: Run Build", async () => {
63-
// A breakpoint will have not effect on the Run command.
64-
vscode.debug.addBreakpoints(breakpoints);
65-
66-
const result = await vscode.commands.executeCommand(Commands.RUN);
67-
expect(result).to.be.true;
68-
59+
suiteTeardown(async () => {
6960
vscode.debug.removeBreakpoints(breakpoints);
7061
});
7162

72-
test("Swift: Clean Build", async () => {
73-
let result = await vscode.commands.executeCommand(Commands.RUN);
74-
expect(result).to.be.true;
75-
76-
const buildPath = path.join(folderContext.folder.fsPath, ".build");
77-
const beforeItemCount = (await fs.readdir(buildPath)).length;
78-
79-
result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD);
63+
test("Swift: Run Build", async () => {
64+
const result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
8065
expect(result).to.be.true;
81-
82-
const afterItemCount = (await fs.readdir(buildPath)).length;
83-
// .build folder is going to be filled with built artifacts after Commands.RUN command
84-
// After executing the clean command the build directory is guranteed to have less entry.
85-
expect(afterItemCount).to.be.lessThan(beforeItemCount);
8666
});
8767

8868
test("Swift: Debug Build", async () => {
89-
vscode.debug.addBreakpoints(breakpoints);
9069
// Promise used to indicate we hit the break point.
9170
// NB: "stopped" is the exact command when debuggee has stopped due to break point,
9271
// but "stackTrace" is the deterministic sync point we will use to make sure we can execute continue
@@ -96,12 +75,34 @@ suite("Build Commands @slow", function () {
9675
"stackTrace"
9776
);
9877

99-
const result = vscode.commands.executeCommand(Commands.DEBUG);
100-
expect(result).to.eventually.be.true;
78+
const resultPromise: Thenable<boolean> = vscode.commands.executeCommand(
79+
Commands.DEBUG,
80+
"PackageExe"
81+
);
10182

10283
await bpPromise;
103-
await continueSession();
84+
let succeeded = false;
85+
resultPromise.then(s => (succeeded = s));
86+
while (!succeeded) {
87+
await continueSession();
88+
await new Promise(r => setTimeout(r, 500));
89+
}
90+
await expect(resultPromise).to.eventually.be.true;
91+
});
10492

105-
vscode.debug.removeBreakpoints(breakpoints);
93+
test("Swift: Clean Build", async () => {
94+
let result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
95+
expect(result).to.be.true;
96+
97+
const buildPath = path.join(folderContext.folder.fsPath, ".build");
98+
const beforeItemCount = (await fs.readdir(buildPath)).length;
99+
100+
result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD);
101+
expect(result).to.be.true;
102+
103+
const afterItemCount = (await fs.readdir(buildPath)).length;
104+
// .build folder is going to be filled with built artifacts after Commands.RUN command
105+
// After executing the clean command the build directory is guranteed to have less entry.
106+
expect(afterItemCount).to.be.lessThan(beforeItemCount);
106107
});
107108
});

0 commit comments

Comments
 (0)