From a85e784357c2afa56551b486e33efa62ff122d05 Mon Sep 17 00:00:00 2001 From: award999 Date: Fri, 20 Dec 2024 15:27:09 -0500 Subject: [PATCH] Await focus of test explorer (#1289) * Seeing if this resolves timing issues Issue: #1260 --- .../testexplorer/TestExplorerIntegration.test.ts | 12 ++++++------ test/integration-tests/testexplorer/utilities.ts | 15 ++++++--------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/test/integration-tests/testexplorer/TestExplorerIntegration.test.ts b/test/integration-tests/testexplorer/TestExplorerIntegration.test.ts index f963e84d8..cd86355c3 100644 --- a/test/integration-tests/testexplorer/TestExplorerIntegration.test.ts +++ b/test/integration-tests/testexplorer/TestExplorerIntegration.test.ts @@ -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, @@ -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"; @@ -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"); diff --git a/test/integration-tests/testexplorer/utilities.ts b/test/integration-tests/testexplorer/utilities.ts index af64c6731..20662258c 100644 --- a/test/integration-tests/testexplorer/utilities.ts +++ b/test/integration-tests/testexplorer/utilities.ts @@ -164,7 +164,7 @@ export function assertTestResults( ); } -function syncPromise(callback: () => void): Promise { +export function syncPromise(callback: () => void): Promise { return new Promise(resolve => { callback(); resolve(); @@ -188,14 +188,11 @@ export function eventPromise(event: vscode.Event): Promise { export async function waitForTestExplorerReady( testExplorer: TestExplorer ): Promise { - 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; } /**