forked from jbramwell/VSTS-Tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.ps1
72 lines (63 loc) · 2.06 KB
/
test.ps1
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[CmdletBinding(PositionalBinding = $false)]
[OutputType([void])]
param(
[switch] $Integration,
[string] $TestName,
[string] $Tag,
[switch] $CodeCoverage,
[switch] $EnableExit
)
$ErrorActionPreference = "Stop"
# Import Pester module
$pesterModule = "Pester"
$pesterPath = Get-Item "$PSScriptRoot/Tests/ps_modules/$pesterModule" -ErrorAction SilentlyContinue
if ($pesterPath) {
$module = Get-Module $pesterModule
if ($module -and $module.ModuleBase -ne $pesterPath) {
Remove-Module $module
$module = $null
}
if (!$module) {
Import-Module $pesterPath
}
} else {
throw "Unable to import Pester. Please build the project first."
}
$name = if ($Integration) { "IntegrationTests" } else { "UnitTests" }
$parameters = @{
OutputFile = "$PSScriptRoot/TestResults-$name.xml"
OutputFormat = "NUnitXML"
}
if ($Integration) {
$parameters += @{
Script = "$PSScriptRoot/Tests/Integration-Tests.ps1"
}
}
if ($TestName) {
$parameters += @{
TestName = $TestName
}
}
if ($Tag) {
$parameters += @{
Tag = $Tag
}
}
if ($CodeCoverage) {
$excludedFiles = Get-Item "$PSScriptRoot/build.ps1", "$PSScriptRoot/test.ps1"
$excludedDirectories = Get-Item "$PSScriptRoot/_build", "$PSScriptRoot/.vscode", "$PSScriptRoot/Tests"
$excludedDirectories += Get-ChildItem "$PSScriptRoot/*/packages", "$PSScriptRoot/*/ps_modules" -Directory
$excludedDirectories += Join-Path $excludedDirectories "*"
$parameters += @{
CodeCoverage = Get-ChildItem -Include "*.ps1" -Exclude "*.Tests.ps1" -Recurse | Where-Object {
$file = $_.FullName
if ($excludedFiles | Where-Object { $file -like $_ }) { return $false }
$directory = $_.DirectoryName
if ($excludedDirectories | Where-Object { $directory -like $_ }) { return $false }
return $true
}
CodeCoverageOutputFile = "$PSScriptRoot/Coverage-$name.xml"
CodeCoverageOutputFileFormat = "JaCoCo"
}
}
Invoke-Pester @parameters -EnableExit:$EnableExit