forked from OctopusDeploy/Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoke-PesterTests.ps1
More file actions
50 lines (40 loc) · 1.97 KB
/
Invoke-PesterTests.ps1
File metadata and controls
50 lines (40 loc) · 1.97 KB
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
param(
[string] $Filter = "*"
)
$ErrorActionPreference = "Stop";
Set-StrictMode -Version "Latest";
$thisScript = $MyInvocation.MyCommand.Path;
$thisFolder = [System.IO.Path]::GetDirectoryName($thisScript);
$rootFolder = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($thisFolder, "..", "..")); # Adjust to always point to the root
$sharedRunner = Join-Path $rootFolder "tools" "Invoke-SharedPesterTests.ps1"
function Unpack-Scripts-Under-Test {
$testFiles = Get-ChildItem -Path "$thisFolder" -Filter "*.tests.ps1" -Recurse
foreach ($testFile in $testFiles) {
$baseName = $testFile.BaseName -replace "\.ScriptBody.Tests$"
$scriptFileName = "$baseName.ScriptBody.ps1"
$scriptFilePath = [System.IO.Path]::Combine($rootFolder, "step-templates", $scriptFileName)
# If the .ps1 file is missing, find the corresponding .json file and unpack it
if (-not [System.IO.File]::Exists($scriptFilePath)) {
Write-Host "Unpacking script for $($testFile.Name) since $scriptFileName is missing..."
$jsonFileName = "$baseName.json"
$jsonFilePath = [System.IO.Path]::Combine($rootFolder, "step-templates", $jsonFileName)
if (-not [System.IO.File]::Exists($jsonFilePath)) {
throw "JSON file $jsonFileName not found. Cannot unpack script."
}
$converter = [System.IO.Path]::Combine($rootFolder, "tools", "Converter.ps1")
& $converter -operation unpack -searchpattern $baseName
if (-not [System.IO.File]::Exists($scriptFilePath)) {
throw "Failed to unpack $scriptFileName. Make sure the JSON template exists and the unpack operation succeeded."
}
} else {
Write-Host "Script $scriptFileName already exists, no need to unpack."
}
}
}
& $sharedRunner `
-TestRoot $thisFolder `
-Filter $Filter `
-BeforeRun ${function:Unpack-Scripts-Under-Test} `
-UsePassThruFailureCheck `
-PreferredPesterVersion "3.4.0" `
-SuiteName "step-templates"