Skip to content

Commit

Permalink
Await focus of test explorer (#1289)
Browse files Browse the repository at this point in the history
* Seeing if this resolves timing issues

Issue: #1260
  • Loading branch information
award999 authored Dec 20, 2024
1 parent 461dca6 commit a85e784
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import * as assert from "assert";
import * as vscode from "vscode";
import { beforeEach, afterEach } from "mocha";
import { testAssetUri } from "../../fixtures";
import { TestExplorer } from "../../../src/TestExplorer/TestExplorer";
import {
assertContains,
Expand All @@ -39,7 +38,11 @@ import {
reduceTestItemChildren,
} from "../../../src/TestExplorer/TestUtils";
import { runnableTag } from "../../../src/TestExplorer/TestDiscovery";
import { activateExtensionForSuite, updateSettings } from "../utilities/testutilities";
import {
activateExtensionForSuite,
folderInRootWorkspace,
updateSettings,
} from "../utilities/testutilities";
import { Commands } from "../../../src/commands";
import { SwiftToolchain } from "../../../src/toolchain/toolchain";

Expand All @@ -54,10 +57,7 @@ suite("Test Explorer Suite", function () {
activateExtensionForSuite({
async setup(ctx) {
workspaceContext = ctx;
const packageFolder = testAssetUri("defaultPackage");
const targetFolder = workspaceContext.folders.find(
folder => folder.folder.path === packageFolder.path
);
const targetFolder = await folderInRootWorkspace("defaultPackage", workspaceContext);

if (!targetFolder) {
throw new Error("Unable to find test explorer");
Expand Down
15 changes: 6 additions & 9 deletions test/integration-tests/testexplorer/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function assertTestResults(
);
}

function syncPromise(callback: () => void): Promise<void> {
export function syncPromise(callback: () => void): Promise<void> {
return new Promise(resolve => {
callback();
resolve();
Expand All @@ -188,14 +188,11 @@ export function eventPromise<T>(event: vscode.Event<T>): Promise<T> {
export async function waitForTestExplorerReady(
testExplorer: TestExplorer
): Promise<vscode.TestController> {
return (
await Promise.all([
testExplorer.controller.items.size === 0
? eventPromise(testExplorer.onTestItemsDidChange)
: Promise.resolve(testExplorer.controller),
syncPromise(() => vscode.commands.executeCommand("workbench.view.testing.focus")),
])
)[0];
await vscode.commands.executeCommand("workbench.view.testing.focus");
const controller = await (testExplorer.controller.items.size === 0
? eventPromise(testExplorer.onTestItemsDidChange)
: Promise.resolve(testExplorer.controller));
return controller;
}

/**
Expand Down

0 comments on commit a85e784

Please sign in to comment.