Skip to content
Closed
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
f26755f
Revert "Fix #827 Pester TestName w/expandable str returns nothing (#8…
bergmeister Jan 20, 2019
a034574
Revert "Revert "Fix #827 Pester TestName w/expandable str returns not…
bergmeister Jan 20, 2019
c978a6f
send describe block line and info whether pester 4.6.0 is available t…
bergmeister Jan 22, 2019
725f643
send only describeBlockLineNumber as nullable int over the wire to PS…
bergmeister Jan 22, 2019
62b101b
use clearer way of passing in null when int is nullable
bergmeister Jan 23, 2019
b6b4b4c
address stylistic nitpicks by Patrick
bergmeister Jan 24, 2019
dbd42b5
Use lazy initialisation to query pester version only when it is neede…
bergmeister Jan 26, 2019
61f62f5
Merge branch 'master' of https://github.com/PowerShell/PowerShellEdit…
bergmeister Jan 29, 2019
ba32b20
use pscommand instead
bergmeister Jan 29, 2019
565f2f8
Merge branch 'master' of https://github.com/PowerShell/PowerShellEdit…
bergmeister Feb 1, 2019
32c69aa
Update src/PowerShellEditorServices.Host/CodeLens/PesterCodeLensProvi…
rjmholt Feb 8, 2019
69e7260
Merge branch 'PesterDescribeLine' of https://github.com/bergmeister/P…
bergmeister Feb 9, 2019
e5bddd0
adress style PR comments
bergmeister Feb 9, 2019
39290a2
Merge branch 'master' of https://github.com/PowerShell/PowerShellEdit…
bergmeister Feb 19, 2019
7245bd6
Use Get-Command and make calls to GetPesterCodeLens async/await to th…
bergmeister Feb 20, 2019
4ec3b3f
Oops, I did it again...
bergmeister Feb 20, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -25,6 +26,12 @@ internal class PesterCodeLensProvider : FeatureProviderBase, ICodeLensProvider
/// </summary>
private IDocumentSymbolProvider _symbolProvider;

/// <summary>
/// Pester 4.6.0 introduced a new ScriptblockFilter parameter to be able to run a test based on a line,
/// therefore knowing this information is important.
/// </summary>
private bool _pesterV4_6_0_OrHigherAvailable;

/// <summary>
/// Create a new Pester CodeLens provider for a given editor session.
/// </summary>
Expand All @@ -33,6 +40,38 @@ public PesterCodeLensProvider(EditorSession editorSession)
{
_editorSession = editorSession;
_symbolProvider = new PesterDocumentSymbolProvider();

DeterminePesterVersion();
}

/// <summary>
/// Used to determine the value of <see cref="_pesterV4_6_0_OrHigherAvailable"/> as a background task.
/// </summary>
private void DeterminePesterVersion()
{
Task.Run(() =>
{
using (var powerShell = System.Management.Automation.PowerShell.Create())
{
powerShell.AddCommand("Get-Module")
.AddParameter("ListAvailable")
.AddParameter("Name", "Pester");
var result = powerShell.Invoke();
if (result != null && result.Count > 0)
{
foreach (var module in result)
{
if (module.BaseObject is PSModuleInfo psmoduleInfo)
{
if (psmoduleInfo.Version > new Version(4, 6))
{
_pesterV4_6_0_OrHigherAvailable = true;
}
}
}
}
}
});
}

/// <summary>
Expand All @@ -45,6 +84,9 @@ private CodeLens[] GetPesterLens(
PesterSymbolReference pesterSymbol,
ScriptFile scriptFile)
{
// A value of null is a signal to PSES that the available Pester version does not support
// running Describe blocks by name (the test name will used instead then)
int? describeBlockLineNumber = _pesterV4_6_0_OrHigherAvailable ? pesterSymbol.ScriptRegion.StartLineNumber : default(int?);
var codeLensResults = new CodeLens[]
{
new CodeLens(
Expand All @@ -54,7 +96,7 @@ private CodeLens[] GetPesterLens(
new ClientCommand(
"PowerShell.RunPesterTests",
"Run tests",
new object[] { scriptFile.ClientFilePath, false /* No debug */, pesterSymbol.TestName })),
new object[] { scriptFile.ClientFilePath, false /* No debug */, pesterSymbol.TestName, describeBlockLineNumber })),

new CodeLens(
this,
Expand All @@ -63,7 +105,7 @@ private CodeLens[] GetPesterLens(
new ClientCommand(
"PowerShell.RunPesterTests",
"Debug tests",
new object[] { scriptFile.ClientFilePath, true /* Run in debugger */, pesterSymbol.TestName })),
new object[] { scriptFile.ClientFilePath, true /* Run in debugger */, pesterSymbol.TestName, describeBlockLineNumber })),
};

return codeLensResults;
Expand Down