From 3a990c1fc7f15315c14f90c5207334d0a06c8292 Mon Sep 17 00:00:00 2001 From: "Michael (SPG) Weng" Date: Tue, 19 Nov 2024 14:53:35 -0500 Subject: [PATCH] Retain the old test lay out - Add in per test tear down and required test step for clean command test --- test/integration-tests/commands/build.test.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/integration-tests/commands/build.test.ts b/test/integration-tests/commands/build.test.ts index db2b71470..d63f59379 100644 --- a/test/integration-tests/commands/build.test.ts +++ b/test/integration-tests/commands/build.test.ts @@ -35,6 +35,7 @@ suite("Build Commands", function () { let folderContext: FolderContext; let workspaceContext: WorkspaceContext; let settingsTeardown: () => Promise; + 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))), @@ -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({ @@ -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);