@@ -21,46 +21,9 @@ import { reduceTestItemChildren } from "@src/TestExplorer/TestUtils";
2121import { WorkspaceContext } from "@src/WorkspaceContext" ;
2222import { SwiftLogger } from "@src/logging/SwiftLogger" ;
2323
24- import { testAssetUri } from "../../fixtures" ;
25- import {
26- SettingsMap ,
27- activateExtension ,
28- deactivateExtension ,
29- updateSettings ,
30- } from "../utilities/testutilities" ;
31-
3224// eslint-disable-next-line @typescript-eslint/no-require-imports
3325import stripAnsi = require( "strip-ansi" ) ;
3426
35- /**
36- * Sets up a test that leverages the TestExplorer, returning the TestExplorer,
37- * WorkspaceContext and a callback to revert the settings back to their original values.
38- * @param settings Optional extension settings to set before the test starts.
39- * @returns Object containing the TestExplorer, WorkspaceContext and a callback to revert
40- * the settings back to their original values.
41- */
42- export async function setupTestExplorerTest ( currentTest ?: Mocha . Test , settings : SettingsMap = { } ) {
43- const settingsTeardown = await updateSettings ( settings ) ;
44-
45- const testProject = testAssetUri ( "defaultPackage" ) ;
46-
47- const workspaceContext = await activateExtension ( currentTest ) ;
48- const testExplorer = testExplorerFor ( workspaceContext , testProject ) ;
49-
50- // Set up the listener before bringing the text explorer in to focus,
51- // which starts searching the workspace for tests.
52- await waitForTestExplorerReady ( testExplorer ) ;
53-
54- return {
55- settingsTeardown : async ( ) => {
56- await settingsTeardown ( ) ;
57- await deactivateExtension ( ) ;
58- } ,
59- workspaceContext,
60- testExplorer,
61- } ;
62- }
63-
6427/**
6528 * Returns the TestExplorer for the given workspace and package folder.
6629 *
@@ -215,10 +178,15 @@ export function eventPromise<T>(event: vscode.Event<T>): Promise<T> {
215178 * @returns The initialized test controller
216179 */
217180export async function waitForTestExplorerReady (
218- testExplorer : TestExplorer
181+ testExplorer : TestExplorer ,
182+ logger : SwiftLogger
219183) : Promise < vscode . TestController > {
220184 await vscode . commands . executeCommand ( "workbench.view.testing.focus" ) ;
221- const controller = await ( testExplorer . controller . items . size === 0
185+ const noExistingTests = testExplorer . controller . items . size === 0 ;
186+ logger . info (
187+ `waitForTestExplorerReady: Found ${ testExplorer . controller . items . size } existing top level test(s)`
188+ ) ;
189+ const controller = await ( noExistingTests
222190 ? eventPromise ( testExplorer . onTestItemsDidChange )
223191 : Promise . resolve ( testExplorer . controller ) ) ;
224192 return controller ;
@@ -311,22 +279,37 @@ export async function runTest(
311279 const testItems = gatherTests ( testExplorer . controller , ...tests ) ;
312280 const request = new vscode . TestRunRequest ( testItems ) ;
313281
314- logger . info ( `runTest: configuring test run with ${ testItems } ` ) ;
282+ logger . info ( `runTest: configuring test run with ${ testItems . map ( t => t . id ) } ` ) ;
315283
316284 // The first promise is the return value, the second promise builds and runs
317285 // the tests, populating the TestRunProxy with results and blocking the return
318286 // of that TestRunProxy until the test run is complete.
319287 return (
320288 await Promise . all ( [
321289 eventPromise ( testExplorer . onCreateTestRun ) . then ( run => {
322- logger . info ( `runTest: created test run with items ${ run . testItems } ` ) ;
290+ logger . info ( `runTest: created test run with items ${ run . testItems . map ( t => t . id ) } ` ) ;
323291 return run ;
324292 } ) ,
325- targetProfile
326- . runHandler ( request , new vscode . CancellationTokenSource ( ) . token )
327- ?. then ( ( ) => {
328- logger . info ( `runTest: completed running tests` ) ;
329- } ) ,
293+ performRun ( targetProfile , request , logger ) ,
330294 ] )
331295 ) [ 0 ] ;
332296}
297+
298+ async function performRun (
299+ targetProfile : vscode . TestRunProfile ,
300+ request : vscode . TestRunRequest ,
301+ logger : SwiftLogger
302+ ) : Promise < void > {
303+ const run = targetProfile . runHandler ( request , new vscode . CancellationTokenSource ( ) . token ) ;
304+ if ( ! run ) {
305+ throw new Error ( "No test run was created" ) ;
306+ }
307+ logger . info ( `runTest: starting running tests` ) ;
308+ try {
309+ await run ;
310+ logger . info ( `runTest: completed running tests` ) ;
311+ } catch ( e ) {
312+ logger . error ( `runTest: error running tests: ${ e } ` ) ;
313+ throw e ;
314+ }
315+ }
0 commit comments