44import * as assert from "assert" ;
55import * as fs from "fs" ;
66import * as path from "path" ;
7- import { suiteSetup } from "mocha" ;
87import rewire = require( "rewire" ) ;
98import vscode = require( "vscode" ) ;
109import utils = require( "../utils" ) ;
10+ import { sleep } from "../../src/utils" ;
11+ import { IPowerShellExtensionClient } from "../../src/features/ExternalApi" ;
1112
1213// Setup function that is not exported.
1314const customViews = rewire ( "../../src/features/RunCode" ) ;
@@ -19,8 +20,6 @@ enum LaunchType {
1920}
2021
2122suite ( "RunCode tests" , ( ) => {
22- suiteSetup ( utils . ensureExtensionIsActivated ) ;
23-
2423 test ( "Can create the launch config" , ( ) => {
2524 const commandToRun : string = "Invoke-Build" ;
2625 const args : string [ ] = [ "Clean" ] ;
@@ -42,11 +41,33 @@ suite("RunCode tests", () => {
4241 assert . deepStrictEqual ( actual , expected ) ;
4342 } ) ;
4443
45- test ( "Can run Pester tests from file" , async ( ) => {
44+ test ( "Can run Pester tests from file" , async function ( ) {
45+ // PowerShell can take a while and is flaky, so try three times and set
46+ // the timeout to thirty seconds each.
47+ this . retries ( 3 ) ;
48+ this . timeout ( 30000 ) ;
49+
4650 const pesterTests = path . resolve ( __dirname , "../../../examples/Tests/SampleModule.Tests.ps1" ) ;
4751 assert ( fs . existsSync ( pesterTests ) ) ;
52+
53+ // Get interface to extension.
54+ const extension = await utils . ensureExtensionIsActivated ( ) ;
55+ const client = extension ! . exports as IPowerShellExtensionClient ;
56+ const sessionId = client . registerExternalExtension ( utils . extensionId ) ;
57+
58+ // Force PowerShell extension to finish connecting. This is necessary
59+ // because we can't start the PowerShell debugger until the session is
60+ // connected, which is different from the extension being activated. We
61+ // also need to open the file so the command has it as its argument.
4862 await vscode . commands . executeCommand ( "vscode.open" , vscode . Uri . file ( pesterTests ) ) ;
63+ await client . getPowerShellVersionDetails ( sessionId ) ;
64+ client . unregisterExternalExtension ( sessionId ) ;
65+
66+ // Now run the Pester tests, check the debugger started, wait a bit for
67+ // it to run, and then kill it for safety's sake.
4968 assert ( await vscode . commands . executeCommand ( "PowerShell.RunPesterTestsFromFile" ) ) ;
50- // Start up can take some time...so set the timeout to 30 seconds.
51- } ) . timeout ( 30000 ) ;
69+ assert ( vscode . debug . activeDebugSession !== undefined ) ;
70+ await sleep ( 5000 ) ;
71+ await vscode . debug . stopDebugging ( ) ;
72+ } ) ;
5273} ) ;
0 commit comments