From c8de1eb72d112ab4822d795a18026de138fc1e31 Mon Sep 17 00:00:00 2001 From: "Michael (SPG) Weng" Date: Thu, 21 Nov 2024 11:45:14 -0500 Subject: [PATCH 1/5] Use expect message to make code more concise - Give a little bit more leeway for timeout since CI machine will be slower than development machine --- test/integration-tests/commands/build.test.ts | 3 +++ test/integration-tests/commands/dependency.test.ts | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration-tests/commands/build.test.ts b/test/integration-tests/commands/build.test.ts index 2fc2e178d..d4af6c67f 100644 --- a/test/integration-tests/commands/build.test.ts +++ b/test/integration-tests/commands/build.test.ts @@ -32,6 +32,9 @@ import { import { pathExists } from "../../../src/utilities/filesystem"; suite("Build Commands", function () { + // Default timeout is a bit too short, give it a little bit more time + this.timeout(30 * 1000); + let folderContext: FolderContext; let workspaceContext: WorkspaceContext; let buildPath: string; diff --git a/test/integration-tests/commands/dependency.test.ts b/test/integration-tests/commands/dependency.test.ts index a0f6592e6..5a89a9767 100644 --- a/test/integration-tests/commands/dependency.test.ts +++ b/test/integration-tests/commands/dependency.test.ts @@ -100,10 +100,7 @@ suite("Dependency Commmands Test Suite", function () { // This will now pass as we have the required library const { exitCode, output } = await executeTaskAndWaitForResult(tasks); - if (exitCode !== 0) { - console.warn("Exit code non zero, command output:\n", output); - } - expect(exitCode).to.equal(0); + expect(exitCode, `Exit code non zero, command output:\n${output}`).to.equal(0); expect(output).to.include("defaultpackage"); expect(output).to.include("not used by any target"); } From 97020fb8398746963291a781277540264e5d90d2 Mon Sep 17 00:00:00 2001 From: "Michael (SPG) Weng" Date: Thu, 21 Nov 2024 14:03:54 -0500 Subject: [PATCH 2/5] Shift test step around to improve test stabliltiy - We want to make sure we don't run spm command quickly in succession - Running unedit command right after spm update command sometime causes CI git to complain about git HEAD corruption --- test/integration-tests/commands/dependency.test.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/integration-tests/commands/dependency.test.ts b/test/integration-tests/commands/dependency.test.ts index 5a89a9767..b5d536e63 100644 --- a/test/integration-tests/commands/dependency.test.ts +++ b/test/integration-tests/commands/dependency.test.ts @@ -134,16 +134,12 @@ suite("Dependency Commmands Test Suite", function () { }); test("Contract: spm update", async function () { - // This test is flaky, test in CI setting when the below change get merged in and find - // out exactly where the command fails. - // https://github.com/swiftlang/vscode-swift/pull/1194 - this.skip(); - await useLocalDependencyTest(); - // Contract: spm update let result = await vscode.commands.executeCommand(Commands.UPDATE_DEPENDENCIES); expect(result).to.be.true; + await useLocalDependencyTest(); + // Clean up result = await vscode.commands.executeCommand(Commands.UNEDIT_DEPENDENCY, item); expect(result).to.be.true; From aa796c9415649f75ec3a6822548d6b47e3008428 Mon Sep 17 00:00:00 2001 From: "Michael (SPG) Weng" Date: Thu, 21 Nov 2024 15:57:02 -0500 Subject: [PATCH 3/5] Test spm update on a simple default package - The spm update command is not stable when used alongside with spm edit, so let's just keep things simple by running the command on defaultPackage instead. --- .../commands/dependency.test.ts | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/integration-tests/commands/dependency.test.ts b/test/integration-tests/commands/dependency.test.ts index b5d536e63..0e2418b5d 100644 --- a/test/integration-tests/commands/dependency.test.ts +++ b/test/integration-tests/commands/dependency.test.ts @@ -36,7 +36,27 @@ suite("Dependency Commmands Test Suite", function () { // 15 seconds for each test should be more than enough this.timeout(15 * 1000); - suite("spm Resolve Update Contract Tests", function () { + suite("spm Update Contract Tests", function () { + let folderContext: FolderContext; + let workspaceContext: WorkspaceContext; + + activateExtensionForSuite({ + async setup(ctx) { + workspaceContext = ctx; + await waitForNoRunningTasks(); + folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext); + await workspaceContext.focusFolder(folderContext); + }, + }); + + test("Contract: spm update", async function () { + // Contract: spm update + const result = await vscode.commands.executeCommand(Commands.UPDATE_DEPENDENCIES); + expect(result).to.be.true; + }); + }); + + suite("spm Resolve Contract Tests", function () { let folderContext: FolderContext; let workspaceContext: WorkspaceContext; @@ -132,19 +152,5 @@ suite("Dependency Commmands Test Suite", function () { await assertDependencyNoLongerExists(); }); - - test("Contract: spm update", async function () { - // Contract: spm update - let result = await vscode.commands.executeCommand(Commands.UPDATE_DEPENDENCIES); - expect(result).to.be.true; - - await useLocalDependencyTest(); - - // Clean up - result = await vscode.commands.executeCommand(Commands.UNEDIT_DEPENDENCY, item); - expect(result).to.be.true; - - await assertDependencyNoLongerExists(); - }); }); }); From ab0773b62b58e1122b45ad620a07c757c246baf9 Mon Sep 17 00:00:00 2001 From: "Michael (SPG) Weng" Date: Tue, 3 Dec 2024 12:12:19 -0500 Subject: [PATCH 4/5] Minor clean up to the comment and unused import --- test/integration-tests/commands/build.test.ts | 14 ++------------ test/integration-tests/commands/dependency.test.ts | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/test/integration-tests/commands/build.test.ts b/test/integration-tests/commands/build.test.ts index d4af6c67f..0b5d5e9e2 100644 --- a/test/integration-tests/commands/build.test.ts +++ b/test/integration-tests/commands/build.test.ts @@ -29,7 +29,6 @@ import { folderInRootWorkspace, updateSettings, } from "../utilities/testutilities"; -import { pathExists } from "../../../src/utilities/filesystem"; suite("Build Commands", function () { // Default timeout is a bit too short, give it a little bit more time @@ -37,7 +36,6 @@ suite("Build Commands", function () { let folderContext: FolderContext; let workspaceContext: WorkspaceContext; - 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))), @@ -48,7 +46,6 @@ suite("Build Commands", function () { workspaceContext = ctx; await waitForNoRunningTasks(); folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext); - buildPath = path.join(folderContext.folder.fsPath, ".build"); await workspaceContext.focusFolder(folderContext); await vscode.window.showTextDocument(uri); const settingsTeardown = await updateSettings({ @@ -62,13 +59,6 @@ suite("Build Commands", function () { }, }); - teardown(async () => { - // Remove the build directory after each test case - if (await pathExists(buildPath)) { - await fs.rm(buildPath, { recursive: true, force: true }); - } - }); - test("Swift: Run Build", async () => { // A breakpoint will have not effect on the Run command. vscode.debug.addBreakpoints(breakpoints); @@ -83,14 +73,14 @@ suite("Build Commands", function () { 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); expect(result).to.be.true; const afterItemCount = (await fs.readdir(buildPath)).length; - // This test will run in order after the Swift: Run Build test, - // where .build folder is going to be filled with built artifacts. + // .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); }); diff --git a/test/integration-tests/commands/dependency.test.ts b/test/integration-tests/commands/dependency.test.ts index 0e2418b5d..55d5543c0 100644 --- a/test/integration-tests/commands/dependency.test.ts +++ b/test/integration-tests/commands/dependency.test.ts @@ -120,7 +120,7 @@ suite("Dependency Commmands Test Suite", function () { // This will now pass as we have the required library const { exitCode, output } = await executeTaskAndWaitForResult(tasks); - expect(exitCode, `Exit code non zero, command output:\n${output}`).to.equal(0); + expect(exitCode, `${output}`).to.equal(0); expect(output).to.include("defaultpackage"); expect(output).to.include("not used by any target"); } From 3db18d13fcda5d90cbe242ca9836d8257d811750 Mon Sep 17 00:00:00 2001 From: "Michael (SPG) Weng" Date: Tue, 3 Dec 2024 13:33:00 -0500 Subject: [PATCH 5/5] Adjust to match latest backgroundCompilation change --- assets/test/.vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/test/.vscode/settings.json b/assets/test/.vscode/settings.json index 500511990..4a09afde5 100644 --- a/assets/test/.vscode/settings.json +++ b/assets/test/.vscode/settings.json @@ -6,5 +6,6 @@ "-Xswiftc", "-DTEST_ARGUMENT_SET_VIA_TEST_BUILD_ARGUMENTS_SETTING" ], - "lldb.verboseLogging": true + "lldb.verboseLogging": true, + "swift.backgroundCompilation": false } \ No newline at end of file