Skip to content

Commit

Permalink
Retain the old test lay out
Browse files Browse the repository at this point in the history
- Add in per test tear down and required test step for clean command
test
  • Loading branch information
michael-weng committed Nov 19, 2024
1 parent dabe01e commit 3a990c1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions test/integration-tests/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ suite("Build Commands", function () {
let folderContext: FolderContext;
let workspaceContext: WorkspaceContext;
let settingsTeardown: () => Promise<void>;
let buildPath: string;
const uri = testAssetUri("defaultPackage/Sources/PackageExe/main.swift");
const breakpoints = [
new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))),
Expand All @@ -44,6 +45,7 @@ suite("Build Commands", function () {
workspaceContext = await activateExtension();
await waitForNoRunningTasks();
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
buildPath = path.join(folderContext.folder.fsPath, ".build");
await workspaceContext.focusFolder(folderContext);
await vscode.window.showTextDocument(uri);
settingsTeardown = await updateSettings({
Expand All @@ -58,23 +60,34 @@ suite("Build Commands", function () {
await deactivateExtension();
});

test("Swift: Run Build, Swift: Clean Build", async () => {
teardown(() => {
// Remove the build directory after each test case
if (fs.existsSync(buildPath)) {
fs.rmSync(buildPath, { recursive: true, force: true });
}
});

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

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

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 = fs.readdirSync(buildPath).length;

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

const afterItemCount = fs.readdirSync(buildPath).length;
// This test step will run in order after the Swift: Run Build test step,
// This test will run in order after the Swift: Run Build test,
// where .build folder is going to be filled with built artifacts.
// After executing the clean command the build directory is guranteed to have less entry.
expect(afterItemCount).to.be.lessThan(beforeItemCount);
Expand Down

0 comments on commit 3a990c1

Please sign in to comment.