Skip to content

Commit cecfaed

Browse files
authored
Improve the debugging on expect statement in test (#1239)
* Improve the debugging on expect statement in test - This is true especially on flaky test, sometimes we check for the exit code but not print out the output from the command on failure. - Fix it for a bunch of asserts where sporadic failures were observed to better understand what went wrong. * Address some expected failure and added comment where applicable * Rebase main and resolve conflict
1 parent bc430fe commit cecfaed

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

test/integration-tests/DiagnosticsManager.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ suite("DiagnosticsManager Test Suite", async function () {
211211
suiteSetup(async function () {
212212
this.timeout(2 * 60 * 1000); // Allow 2 minutes to build
213213
const task = createBuildAllTask(folderContext);
214+
// This return exit code and output for the task but we will omit it here
215+
// because the failures are expected and we just want the task to build
214216
await executeTaskAndWaitForResult(task);
215217
});
216218

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ suite("Dependency Commmands Test Suite", function () {
8989

9090
tasks = (await getBuildAllTask(folderContext)) as SwiftTask;
9191
const { exitCode, output } = await executeTaskAndWaitForResult(tasks);
92-
expect(exitCode).to.not.equal(0);
92+
expect(exitCode, `${output}`).to.not.equal(0);
9393
expect(output).to.include("PackageLib");
9494
expect(output).to.include("required");
9595

@@ -125,7 +125,7 @@ suite("Dependency Commmands Test Suite", function () {
125125
async function assertDependencyNoLongerExists() {
126126
// Expect to fail again now dependency is missing
127127
const { exitCode, output } = await executeTaskAndWaitForResult(tasks);
128-
expect(exitCode).to.not.equal(0);
128+
expect(exitCode, `${output}`).to.not.equal(0);
129129
expect(output).to.include("PackageLib");
130130
expect(output).to.include("required");
131131
}

test/integration-tests/tasks/SwiftPluginTaskProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ suite("SwiftPluginTaskProvider Test Suite", () => {
6969
}
7070
);
7171
mutable(task.execution).command = "/definitely/not/swift";
72-
const { exitCode } = await executeTaskAndWaitForResult(task);
73-
expect(exitCode).to.not.equal(0);
72+
const { exitCode, output } = await executeTaskAndWaitForResult(task);
73+
expect(exitCode, `${output}`).to.not.equal(0);
7474
}).timeout(10000);
7575
});
7676

test/integration-tests/ui/PackageDependencyProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ suite("PackageDependencyProvider Test Suite", function () {
4747
const items = await treeProvider.getChildren();
4848

4949
const dep = items.find(n => n.name === "swift-markdown") as PackageNode;
50-
expect(dep).to.not.be.undefined;
50+
expect(dep, `${JSON.stringify(items, null, 2)}`).to.not.be.undefined;
5151
expect(dep?.location).to.equal("https://github.com/swiftlang/swift-markdown.git");
5252
assertPathsEqual(
5353
dep?.path,
@@ -105,7 +105,7 @@ suite("PackageDependencyProvider Test Suite", function () {
105105
const items = await treeProvider.getChildren();
106106

107107
const dep = items.find(n => n.name === "swift-markdown") as PackageNode;
108-
expect(dep).to.not.be.undefined;
108+
expect(dep, `${JSON.stringify(items, null, 2)}`).to.not.be.undefined;
109109

110110
const folders = await treeProvider.getChildren(dep);
111111
const folder = folders.find(n => n.name === "Sources");

0 commit comments

Comments
 (0)