Skip to content

Commit 0291818

Browse files
Support adding an OutputFile and allow running from command pallet (#2730)
* Support adding OutputPath and run file * refactor all logic
1 parent a210bb4 commit 0291818

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

InvokePesterStub.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ param(
5353
[switch] $MinimumVersion5,
5454

5555
[Parameter(Mandatory)]
56-
[string] $Output
56+
[string] $Output,
57+
58+
[Parameter()]
59+
[string] $OutputPath
5760
)
5861

5962
$pesterModule = Microsoft.PowerShell.Core\Get-Module Pester
@@ -103,6 +106,14 @@ if ($All) {
103106
if ("FromPreference" -ne $Output) {
104107
$configuration.Add('Output', @{ Verbosity = $Output })
105108
}
109+
110+
if ($OutputPath) {
111+
$configuration.Add('TestResult', @{
112+
Enabled = $true
113+
OutputFormat = "NUnit2.5"
114+
OutputPath = $OutputPath
115+
})
116+
}
106117
Pester\Invoke-Pester -Configuration $configuration | Out-Null
107118
}
108119
elseif ($pesterModule.Version -ge '3.4.5') {
@@ -132,6 +143,15 @@ elseif (($LineNumber -match '\d+') -and ($pesterModule.Version -ge '4.6.0')) {
132143
if ("FromPreference" -ne $Output) {
133144
$configuration.Add('Output', @{ Verbosity = $Output })
134145
}
146+
147+
if ($OutputPath) {
148+
$configuration.Add('TestResult', @{
149+
Enabled = $true
150+
OutputFormat = "NUnit2.5"
151+
OutputPath = $OutputPath
152+
})
153+
}
154+
135155
Pester\Invoke-Pester -Configuration $configuration | Out-Null
136156
}
137157
else {

src/features/PesterTests.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export class PesterTestsFeature implements IFeature {
3838
// This command is provided for usage by PowerShellEditorServices (PSES) only
3939
this.command = vscode.commands.registerCommand(
4040
"PowerShell.RunPesterTests",
41-
(uriString, runInDebugger, describeBlockName?, describeBlockLineNumber?) => {
42-
this.launchTests(uriString, runInDebugger, describeBlockName, describeBlockLineNumber);
41+
(uriString, runInDebugger, describeBlockName?, describeBlockLineNumber?, outputPath?) => {
42+
this.launchTests(uriString, runInDebugger, describeBlockName, describeBlockLineNumber, outputPath);
4343
});
4444
}
4545

@@ -52,24 +52,30 @@ export class PesterTestsFeature implements IFeature {
5252
}
5353

5454
private launchAllTestsInActiveEditor(launchType: LaunchType, fileUri: vscode.Uri) {
55-
const uriString = fileUri.toString();
55+
const uriString = (fileUri || vscode.window.activeTextEditor.document.uri).toString();
5656
const launchConfig = this.createLaunchConfig(uriString, launchType);
57-
launchConfig.args.push("-All");
5857
this.launch(launchConfig);
5958
}
6059

6160
private async launchTests(
6261
uriString: string,
6362
runInDebugger: boolean,
6463
describeBlockName?: string,
65-
describeBlockLineNumber?: number) {
64+
describeBlockLineNumber?: number,
65+
outputPath?: string) {
6666

6767
const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run;
68-
const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, describeBlockLineNumber);
68+
const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, describeBlockLineNumber, outputPath);
6969
this.launch(launchConfig);
7070
}
7171

72-
private createLaunchConfig(uriString: string, launchType: LaunchType, testName?: string, lineNum?: number) {
72+
private createLaunchConfig(
73+
uriString: string,
74+
launchType: LaunchType,
75+
testName?: string,
76+
lineNum?: number,
77+
outputPath?: string) {
78+
7379
const uri = vscode.Uri.parse(uriString);
7480
const currentDocument = vscode.window.activeTextEditor.document;
7581
const settings = Settings.load();
@@ -98,15 +104,15 @@ export class PesterTestsFeature implements IFeature {
98104

99105
if (lineNum) {
100106
launchConfig.args.push("-LineNumber", `${lineNum}`);
101-
}
102-
103-
if (testName) {
107+
} else if (testName) {
104108
// Escape single quotes inside double quotes by doubling them up
105109
if (testName.includes("'")) {
106110
testName = testName.replace(/'/g, "''");
107111
}
108112

109113
launchConfig.args.push("-TestName", `'${testName}'`);
114+
} else {
115+
launchConfig.args.push("-All");
110116
}
111117

112118
if (!settings.pester.useLegacyCodeLens) {
@@ -120,6 +126,10 @@ export class PesterTestsFeature implements IFeature {
120126
launchConfig.args.push("-Output", `'${settings.pester.outputVerbosity}'`);
121127
}
122128

129+
if (outputPath) {
130+
launchConfig.args.push("-OutputPath", `'${outputPath}'`);
131+
}
132+
123133
return launchConfig;
124134
}
125135

src/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export class SessionManager implements Middleware {
283283
const resolvedCodeLens = next(codeLens, token);
284284
const resolveFunc =
285285
(codeLensToFix: vscode.CodeLens): vscode.CodeLens => {
286-
if (codeLensToFix.command.command === "editor.action.showReferences") {
286+
if (codeLensToFix.command?.command === "editor.action.showReferences") {
287287
const oldArgs = codeLensToFix.command.arguments;
288288

289289
// Our JSON objects don't get handled correctly by

0 commit comments

Comments
 (0)