Skip to content

Commit e7f81c9

Browse files
authored
Address some issues found when running test locally (#1217)
* 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 * 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 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. * Minor clean up to the comment and unused import * Adjust to match latest backgroundCompilation change
1 parent 36cd225 commit e7f81c9

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

assets/test/.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"-Xswiftc",
77
"-DTEST_ARGUMENT_SET_VIA_TEST_BUILD_ARGUMENTS_SETTING"
88
],
9-
"lldb.verboseLogging": true
9+
"lldb.verboseLogging": true,
10+
"swift.backgroundCompilation": false
1011
}

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ import {
2929
folderInRootWorkspace,
3030
updateSettings,
3131
} from "../utilities/testutilities";
32-
import { pathExists } from "../../../src/utilities/filesystem";
3332

3433
suite("Build Commands", function () {
34+
// Default timeout is a bit too short, give it a little bit more time
35+
this.timeout(30 * 1000);
36+
3537
let folderContext: FolderContext;
3638
let workspaceContext: WorkspaceContext;
37-
let buildPath: string;
3839
const uri = testAssetUri("defaultPackage/Sources/PackageExe/main.swift");
3940
const breakpoints = [
4041
new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))),
@@ -45,7 +46,6 @@ suite("Build Commands", function () {
4546
workspaceContext = ctx;
4647
await waitForNoRunningTasks();
4748
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
48-
buildPath = path.join(folderContext.folder.fsPath, ".build");
4949
await workspaceContext.focusFolder(folderContext);
5050
await vscode.window.showTextDocument(uri);
5151
const settingsTeardown = await updateSettings({
@@ -59,13 +59,6 @@ suite("Build Commands", function () {
5959
},
6060
});
6161

62-
teardown(async () => {
63-
// Remove the build directory after each test case
64-
if (await pathExists(buildPath)) {
65-
await fs.rm(buildPath, { recursive: true, force: true });
66-
}
67-
});
68-
6962
test("Swift: Run Build", async () => {
7063
// A breakpoint will have not effect on the Run command.
7164
vscode.debug.addBreakpoints(breakpoints);
@@ -80,14 +73,14 @@ suite("Build Commands", function () {
8073
let result = await vscode.commands.executeCommand(Commands.RUN);
8174
expect(result).to.be.true;
8275

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

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

8882
const afterItemCount = (await fs.readdir(buildPath)).length;
89-
// This test will run in order after the Swift: Run Build test,
90-
// where .build folder is going to be filled with built artifacts.
83+
// .build folder is going to be filled with built artifacts after Commands.RUN command
9184
// After executing the clean command the build directory is guranteed to have less entry.
9285
expect(afterItemCount).to.be.lessThan(beforeItemCount);
9386
});

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,27 @@ suite("Dependency Commmands Test Suite", function () {
3636
// 15 seconds for each test should be more than enough
3737
this.timeout(15 * 1000);
3838

39-
suite("spm Resolve Update Contract Tests", function () {
39+
suite("spm Update Contract Tests", function () {
40+
let folderContext: FolderContext;
41+
let workspaceContext: WorkspaceContext;
42+
43+
activateExtensionForSuite({
44+
async setup(ctx) {
45+
workspaceContext = ctx;
46+
await waitForNoRunningTasks();
47+
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
48+
await workspaceContext.focusFolder(folderContext);
49+
},
50+
});
51+
52+
test("Contract: spm update", async function () {
53+
// Contract: spm update
54+
const result = await vscode.commands.executeCommand(Commands.UPDATE_DEPENDENCIES);
55+
expect(result).to.be.true;
56+
});
57+
});
58+
59+
suite("spm Resolve Contract Tests", function () {
4060
let folderContext: FolderContext;
4161
let workspaceContext: WorkspaceContext;
4262

@@ -100,10 +120,7 @@ suite("Dependency Commmands Test Suite", function () {
100120

101121
// This will now pass as we have the required library
102122
const { exitCode, output } = await executeTaskAndWaitForResult(tasks);
103-
if (exitCode !== 0) {
104-
console.warn("Exit code non zero, command output:\n", output);
105-
}
106-
expect(exitCode).to.equal(0);
123+
expect(exitCode, `${output}`).to.equal(0);
107124
expect(output).to.include("defaultpackage");
108125
expect(output).to.include("not used by any target");
109126
}
@@ -135,23 +152,5 @@ suite("Dependency Commmands Test Suite", function () {
135152

136153
await assertDependencyNoLongerExists();
137154
});
138-
139-
test("Contract: spm update", async function () {
140-
// This test is flaky, test in CI setting when the below change get merged in and find
141-
// out exactly where the command fails.
142-
// https://github.com/swiftlang/vscode-swift/pull/1194
143-
this.skip();
144-
await useLocalDependencyTest();
145-
146-
// Contract: spm update
147-
let result = await vscode.commands.executeCommand(Commands.UPDATE_DEPENDENCIES);
148-
expect(result).to.be.true;
149-
150-
// Clean up
151-
result = await vscode.commands.executeCommand(Commands.UNEDIT_DEPENDENCY, item);
152-
expect(result).to.be.true;
153-
154-
await assertDependencyNoLongerExists();
155-
});
156155
});
157156
});

0 commit comments

Comments
 (0)