Skip to content

Commit

Permalink
Support adding an OutputFile and allow running from command pallet (#…
Browse files Browse the repository at this point in the history
…2730)

* Support adding OutputPath and run file

* refactor all logic
  • Loading branch information
TylerLeonhardt authored Jun 1, 2020
1 parent a210bb4 commit 0291818
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
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

0 comments on commit 0291818

Please sign in to comment.