-
Notifications
You must be signed in to change notification settings - Fork 8
/
IsePester.psm1
57 lines (38 loc) · 1.42 KB
/
IsePester.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function Add-PesterMenu {
$sb = {
if(!$psISE.CurrentFile.IsUntitled) {
$psISE.CurrentFile.Save()
$fileName = $psISE.CurrentFile.FullPath
if($filename -notmatch '\.tests\.') {
$parts = $filename -split '\.'
$testFilename = "{0}.tests.ps1" -f ($parts[0..($parts.Count-2)] -join '.')
Write-Debug $testFilename
if(Test-Path $testFilename) {
$filename = $testFilename
}
Write-Debug $filename
}
} else {
$fileName = [io.path]::GetTempFileName().Replace(".tmp", ".tests.ps1")
$psISE.CurrentFile.Editor.Text | Set-Content -Path $fileName
}
Import-Module Pester
cls
Write-Debug $fileName
Invoke-Pester -relative_path $fileName
if(!$psISE.CurrentFile.IsSaved) { Remove-Item $fileName -Force -ErrorAction SilentlyContinue }
}
Remove-PesterMenu
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("_Pester", $sb, "CTRL+F5")
}
function Get-PesterMenu {
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus |
Where DisplayName -Match "pester"
}
function Remove-PesterMenu {
$menu = Get-PesterMenu
if($menu) {
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Remove($menu)
}
}
Add-PesterMenu