@@ -13,75 +13,73 @@ 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
53
fileUri : vscode . Uri ) : Promise < boolean > {
50
54
51
- if ( fileUri === undefined && vscode . window . activeTextEditor === undefined ) {
52
- return false ;
53
- }
54
-
55
- const uriString = ( fileUri || vscode . window . activeTextEditor ! . document . uri ) . toString ( ) ;
56
- const launchConfig = this . createLaunchConfig ( uriString , launchType ) ;
55
+ const launchConfig = this . createLaunchConfig ( fileUri , launchType ) ;
57
56
return this . launch ( launchConfig ) ;
58
57
}
59
58
60
59
private async launchTests (
61
- uriString : string ,
60
+ fileUri : vscode . Uri ,
62
61
runInDebugger : boolean ,
63
62
describeBlockName ?: string ,
64
63
describeBlockLineNumber ?: number ,
65
64
outputPath ?: string ) : Promise < boolean > {
66
65
67
66
const launchType = runInDebugger ? LaunchType . Debug : LaunchType . Run ;
68
- const launchConfig = this . createLaunchConfig ( uriString , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
67
+ const launchConfig = this . createLaunchConfig ( fileUri , launchType , describeBlockName , describeBlockLineNumber , outputPath ) ;
69
68
return this . launch ( launchConfig ) ;
70
69
}
71
70
72
71
private createLaunchConfig (
73
- uriString : string ,
72
+ fileUri : vscode . Uri ,
74
73
launchType : LaunchType ,
75
74
testName ?: string ,
76
75
lineNum ?: number ,
77
76
outputPath ?: string ) : vscode . DebugConfiguration {
78
77
79
- const uri = vscode . Uri . parse ( uriString ) ;
80
78
const settings = Settings . load ( ) ;
81
79
82
80
// Since we pass the script path to PSES in single quotes to avoid issues with PowerShell
83
81
// special chars like & $ @ () [], we do have to double up the interior single quotes.
84
- const scriptPath = uri . fsPath . replace ( / ' / g, "''" ) ;
82
+ const scriptPath = fileUri . fsPath . replace ( / ' / g, "''" ) ;
85
83
86
84
const launchConfig = {
87
85
request : "launch" ,
0 commit comments