@@ -13,75 +13,81 @@ enum LaunchType {
13
13
}
14
14
15
15
export class PesterTestsFeature implements vscode . Disposable {
16
-
17
- private command : vscode . Disposable ;
16
+ private commands : vscode . Disposable [ ] ;
18
17
private invokePesterStubScriptPath : string ;
19
18
20
19
constructor ( private sessionManager : SessionManager ) {
21
20
this . invokePesterStubScriptPath = path . resolve ( __dirname , "../modules/PowerShellEditorServices/InvokePesterStub.ps1" ) ;
22
-
23
- // File context-menu command - Run Pester Tests
24
- this . command = vscode . commands . registerCommand (
25
- "PowerShell.RunPesterTestsFromFile" ,
26
- ( fileUri ) => {
27
- return this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
28
- } ) ;
29
- // File context-menu command - Debug Pester Tests
30
- this . command = vscode . commands . registerCommand (
31
- "PowerShell.DebugPesterTestsFromFile" ,
32
- ( fileUri ) => {
33
- return this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
34
- } ) ;
35
- // This command is provided for usage by PowerShellEditorServices (PSES) only
36
- this . command = vscode . commands . registerCommand (
37
- "PowerShell.RunPesterTests" ,
38
- ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ?, outputPath ?) => {
39
- return this . launchTests ( uriString , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
40
- } ) ;
21
+ this . commands = [
22
+ // File context-menu command - Run Pester Tests
23
+ vscode . commands . registerCommand (
24
+ "PowerShell.RunPesterTestsFromFile" ,
25
+ ( fileUri ?) => {
26
+ return this . launchAllTestsInActiveEditor ( LaunchType . Run , fileUri ) ;
27
+ } ) ,
28
+
29
+ // File context-menu command - Debug Pester Tests
30
+ vscode . commands . registerCommand (
31
+ "PowerShell.DebugPesterTestsFromFile" ,
32
+ ( fileUri ?) => {
33
+ return this . launchAllTestsInActiveEditor ( LaunchType . Debug , fileUri ) ;
34
+ } ) ,
35
+
36
+ // This command is provided for usage by PowerShellEditorServices (PSES) only
37
+ vscode . commands . registerCommand (
38
+ "PowerShell.RunPesterTests" ,
39
+ ( uriString , runInDebugger , describeBlockName ?, describeBlockLineNumber ?, outputPath ?) => {
40
+ return this . launchTests ( vscode . Uri . parse ( uriString ) , runInDebugger , describeBlockName , describeBlockLineNumber , outputPath ) ;
41
+ } )
42
+ ] ;
41
43
}
42
44
43
45
public dispose ( ) {
44
- this . command . dispose ( ) ;
46
+ for ( const command of this . commands ) {
47
+ command . dispose ( ) ;
48
+ }
45
49
}
46
50
47
51
private async launchAllTestsInActiveEditor (
48
52
launchType : LaunchType ,
49
- fileUri : vscode . Uri ) : Promise < boolean > {
53
+ fileUri ?: vscode . Uri ) : Promise < boolean > {
54
+
55
+ if ( fileUri === undefined ) {
56
+ fileUri = vscode . window . activeTextEditor ?. document . uri ;
57
+ }
50
58
51
- if ( fileUri === undefined && vscode . window . activeTextEditor === undefined ) {
59
+ if ( fileUri === undefined ) {
52
60
return false ;
53
61
}
54
62
55
- const uriString = ( fileUri || vscode . window . activeTextEditor ! . document . uri ) . toString ( ) ;
56
- const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
63
+ const launchConfig = this . createLaunchConfig ( fileUri , launchType ) ;
57
64
return this . launch ( launchConfig ) ;
58
65
}
59
66
60
67
private async launchTests (
61
- uriString : string ,
68
+ fileUri : vscode . Uri ,
62
69
runInDebugger : boolean ,
63
70
describeBlockName ?: string ,
64
71
describeBlockLineNumber ?: number ,
65
72
outputPath ?: string ) : Promise < boolean > {
66
73
67
74
const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
68
- const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
75
+ const launchConfig = this . createLaunchConfig ( fileUri , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
69
76
return this . launch ( launchConfig ) ;
70
77
}
71
78
72
79
private createLaunchConfig (
73
- uriString : string ,
80
+ fileUri : vscode . Uri ,
74
81
launchType : LaunchType ,
75
82
testName ?: string ,
76
83
lineNum ?: number ,
77
84
outputPath ?: string ) : vscode . DebugConfiguration {
78
85
79
- const uri = vscode . Uri . parse ( uriString ) ;
80
86
const settings = Settings . load ( ) ;
81
87
82
88
// Since we pass the script path to PSES in single quotes to avoid issues with PowerShell
83
89
// special chars like & $ @ () [], we do have to double up the interior single quotes.
84
- const scriptPath = uri . fsPath . replace ( / ' / g, "''" ) ;
90
+ const scriptPath = fileUri . fsPath . replace ( / ' / g, "''" ) ;
85
91
86
92
const launchConfig = {
87
93
request : "launch" ,
0 commit comments