Skip to content

Support adding an OutputFile and allow running from command pallet #2730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion InvokePesterStub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ param(
[switch] $MinimumVersion5,

[Parameter(Mandatory)]
[string] $Output
[string] $Output,

[Parameter()]
[string] $OutputPath
)

$pesterModule = Microsoft.PowerShell.Core\Get-Module Pester
Expand Down Expand Up @@ -103,6 +106,14 @@ if ($All) {
if ("FromPreference" -ne $Output) {
$configuration.Add('Output', @{ Verbosity = $Output })
}

if ($OutputPath) {
$configuration.Add('TestResult', @{
Enabled = $true
OutputFormat = "NUnit2.5"
OutputPath = $OutputPath
})
}
Pester\Invoke-Pester -Configuration $configuration | Out-Null
}
elseif ($pesterModule.Version -ge '3.4.5') {
Expand Down Expand Up @@ -132,6 +143,15 @@ elseif (($LineNumber -match '\d+') -and ($pesterModule.Version -ge '4.6.0')) {
if ("FromPreference" -ne $Output) {
$configuration.Add('Output', @{ Verbosity = $Output })
}

if ($OutputPath) {
$configuration.Add('TestResult', @{
Enabled = $true
OutputFormat = "NUnit2.5"
OutputPath = $OutputPath
})
}

Pester\Invoke-Pester -Configuration $configuration | Out-Null
}
else {
Expand Down
30 changes: 20 additions & 10 deletions src/features/PesterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class PesterTestsFeature implements IFeature {
// This command is provided for usage by PowerShellEditorServices (PSES) only
this.command = vscode.commands.registerCommand(
"PowerShell.RunPesterTests",
(uriString, runInDebugger, describeBlockName?, describeBlockLineNumber?) => {
this.launchTests(uriString, runInDebugger, describeBlockName, describeBlockLineNumber);
(uriString, runInDebugger, describeBlockName?, describeBlockLineNumber?, outputPath?) => {
this.launchTests(uriString, runInDebugger, describeBlockName, describeBlockLineNumber, outputPath);
});
}

Expand All @@ -52,24 +52,30 @@ export class PesterTestsFeature implements IFeature {
}

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

private async launchTests(
uriString: string,
runInDebugger: boolean,
describeBlockName?: string,
describeBlockLineNumber?: number) {
describeBlockLineNumber?: number,
outputPath?: string) {

const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run;
const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, describeBlockLineNumber);
const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, describeBlockLineNumber, outputPath);
this.launch(launchConfig);
}

private createLaunchConfig(uriString: string, launchType: LaunchType, testName?: string, lineNum?: number) {
private createLaunchConfig(
uriString: string,
launchType: LaunchType,
testName?: string,
lineNum?: number,
outputPath?: string) {

const uri = vscode.Uri.parse(uriString);
const currentDocument = vscode.window.activeTextEditor.document;
const settings = Settings.load();
Expand Down Expand Up @@ -98,15 +104,15 @@ export class PesterTestsFeature implements IFeature {

if (lineNum) {
launchConfig.args.push("-LineNumber", `${lineNum}`);
}

if (testName) {
} else if (testName) {
// Escape single quotes inside double quotes by doubling them up
if (testName.includes("'")) {
testName = testName.replace(/'/g, "''");
}

launchConfig.args.push("-TestName", `'${testName}'`);
} else {
launchConfig.args.push("-All");
}

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

if (outputPath) {
launchConfig.args.push("-OutputPath", `'${outputPath}'`);
}

return launchConfig;
}

Expand Down
2 changes: 1 addition & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class SessionManager implements Middleware {
const resolvedCodeLens = next(codeLens, token);
const resolveFunc =
(codeLensToFix: vscode.CodeLens): vscode.CodeLens => {
if (codeLensToFix.command.command === "editor.action.showReferences") {
if (codeLensToFix.command?.command === "editor.action.showReferences") {
const oldArgs = codeLensToFix.command.arguments;

// Our JSON objects don't get handled correctly by
Expand Down