Skip to content

Fix build commands test #1552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions test/integration-tests/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { testAssetUri } from "../../fixtures";
import { FolderContext } from "../../../src/FolderContext";
import { WorkspaceContext } from "../../../src/WorkspaceContext";
import { Commands } from "../../../src/commands";
import { Workbench } from "../../../src/utilities/commands";
import { continueSession, waitForDebugAdapterRequest } from "../../utilities/debug";
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
import { Version } from "../../../src/utilities/version";
Expand All @@ -42,51 +41,31 @@ suite("Build Commands @slow", function () {
// The description of this package is crashing on Windows with Swift 5.9.x and below
if (
process.platform === "win32" &&
ctx.globalToolchain.swiftVersion.isLessThanOrEqual(new Version(5, 9, 0))
ctx.globalToolchain.swiftVersion.isLessThan(new Version(5, 10, 0))
) {
this.skip();
}
// A breakpoint will have not effect on the Run command.
vscode.debug.addBreakpoints(breakpoints);

workspaceContext = ctx;
await waitForNoRunningTasks();
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
await workspaceContext.focusFolder(folderContext);
await vscode.window.showTextDocument(uri);
},
async teardown() {
await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS);
},
requiresDebugger: true,
});

test("Swift: Run Build", async () => {
// A breakpoint will have not effect on the Run command.
vscode.debug.addBreakpoints(breakpoints);

const result = await vscode.commands.executeCommand(Commands.RUN);
expect(result).to.be.true;

suiteTeardown(async () => {
vscode.debug.removeBreakpoints(breakpoints);
});

test("Swift: Clean Build", async () => {
let result = await vscode.commands.executeCommand(Commands.RUN);
expect(result).to.be.true;

const buildPath = path.join(folderContext.folder.fsPath, ".build");
const beforeItemCount = (await fs.readdir(buildPath)).length;

result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD);
test("Swift: Run Build", async () => {
const result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
expect(result).to.be.true;

const afterItemCount = (await fs.readdir(buildPath)).length;
// .build folder is going to be filled with built artifacts after Commands.RUN command
// After executing the clean command the build directory is guranteed to have less entry.
expect(afterItemCount).to.be.lessThan(beforeItemCount);
});

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

const result = vscode.commands.executeCommand(Commands.DEBUG);
expect(result).to.eventually.be.true;
const resultPromise: Thenable<boolean> = vscode.commands.executeCommand(
Commands.DEBUG,
"PackageExe"
);

await bpPromise;
await continueSession();
let succeeded = false;
resultPromise.then(s => (succeeded = s));
while (!succeeded) {
await continueSession();
await new Promise(r => setTimeout(r, 500));
}
await expect(resultPromise).to.eventually.be.true;
});

vscode.debug.removeBreakpoints(breakpoints);
test("Swift: Clean Build", async () => {
let result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
expect(result).to.be.true;

const buildPath = path.join(folderContext.folder.fsPath, ".build");
const beforeItemCount = (await fs.readdir(buildPath)).length;

result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD);
expect(result).to.be.true;

const afterItemCount = (await fs.readdir(buildPath)).length;
// .build folder is going to be filled with built artifacts after Commands.RUN command
// After executing the clean command the build directory is guranteed to have less entry.
expect(afterItemCount).to.be.lessThan(beforeItemCount);
});
});