4
4
import * as assert from "assert" ;
5
5
import * as fs from "fs" ;
6
6
import * as path from "path" ;
7
- import { suiteSetup } from "mocha" ;
8
7
import rewire = require( "rewire" ) ;
9
8
import vscode = require( "vscode" ) ;
10
9
import utils = require( "../utils" ) ;
10
+ import { sleep } from "../../src/utils" ;
11
+ import { IPowerShellExtensionClient } from "../../src/features/ExternalApi" ;
11
12
12
13
// Setup function that is not exported.
13
14
const customViews = rewire ( "../../src/features/RunCode" ) ;
@@ -19,8 +20,6 @@ enum LaunchType {
19
20
}
20
21
21
22
suite ( "RunCode tests" , ( ) => {
22
- suiteSetup ( utils . ensureExtensionIsActivated ) ;
23
-
24
23
test ( "Can create the launch config" , ( ) => {
25
24
const commandToRun : string = "Invoke-Build" ;
26
25
const args : string [ ] = [ "Clean" ] ;
@@ -45,8 +44,23 @@ suite("RunCode tests", () => {
45
44
test ( "Can run Pester tests from file" , async ( ) => {
46
45
const pesterTests = path . resolve ( __dirname , "../../../examples/Tests/SampleModule.Tests.ps1" ) ;
47
46
assert ( fs . existsSync ( pesterTests ) ) ;
47
+
48
+ // Get interface to extension.
49
+ const extension = await utils . ensureExtensionIsActivated ( ) ;
50
+ const client = extension ! . exports as IPowerShellExtensionClient ;
51
+ const sessionId = client . registerExternalExtension ( utils . extensionId ) ;
52
+
53
+ // Force PowerShell extension to finish connecting. This is necessary
54
+ // because we can't start the PowerShell debugger until the session is
55
+ // connected, which is different from the extension being activated. We
56
+ // also need to open the file so the command has it as its argument.
48
57
await vscode . commands . executeCommand ( "vscode.open" , vscode . Uri . file ( pesterTests ) ) ;
58
+ await client . getPowerShellVersionDetails ( sessionId ) ;
59
+
60
+ // Now run the Pester tests.
49
61
assert ( await vscode . commands . executeCommand ( "PowerShell.RunPesterTestsFromFile" ) ) ;
50
- // Start up can take some time...so set the timeout to 30 seconds.
51
- } ) . timeout ( 30000 ) ;
62
+ await sleep ( 5000 ) ;
63
+ await vscode . debug . stopDebugging ( ) ;
64
+ // PowerShell can take a while, so set the timeout to a full minute.
65
+ } ) . timeout ( 60000 ) ;
52
66
} ) ;
0 commit comments