This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-AfterEach { | |
Param( | |
[scriptblock[]]$ScriptBlock, | |
[scriptblock]$OnTaskComplete | |
) | |
$ScriptBlock | % { | |
Start-Job { | |
Param($action, $callback) | |
&$action | |
&$callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$modulesDir = $env:PSModulePath -split ":" | Select -First 1 | |
Move-Item .\MyModule $modulesDir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Assert-ArrayEquality($test, $expected) { | |
$test | Should -HaveCount $expected.Count | |
0..($test.Count - 1) | % {$test[$_] | Should -Be $expected[$_]} | |
} | |
function Assert-HashtableEquality($test, $expected) { | |
$test.Keys | Should -HaveCount $expected.Keys.Count | |
$test.Keys | % {$test[$_] | Should -Be $expected[$_]} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-WithStorageAccount { | |
Param( | |
[ValidateNotNullOrEmpty()] | |
[scriptblock]$ScriptBlock | |
) | |
$name = ("s$(New-Guid)" -replace "-").Substring(24) | |
$storageAccount = New-AzStorageAccount ` | |
-ResourceGroupName "ephemeral-storages" ` | |
-Name $name` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Invoke-InDirectory $RepoRoot { | |
Invoke-InContext "Build ReactJS App" { | |
Invoke-InContext "Validate" { | |
Invoke-InContext "Lint" { yarn lint } | |
Invoke-InContext "Test" { yarn test } | |
} | |
Invoke-InContext "Transpile" { yarn build:ts } | |
Invoke-InContext "Bundle" { yarn webpack } | |
} | |
Invoke-InContext "Build Container" { docker build . } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ContextLogger.psm1 | |
$ContextStack = [System.Collections.Stack]::new() | |
function Invoke-InContext { | |
Param( | |
[ValidateNotNullOrEmpty()] | |
[string] $Name, | |
[ValidateNotNullOrEmpty()] | |
[scriptblock] $ScriptBlock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# invoke in repo root | |
Invoke-InDirectory "$PSScriptRoot/.." { | |
Invoke-InDirectory "./components" { | |
npm install | |
npm build | |
} | |
Invoke-InDirectory "./server" { | |
npm install | |
npm build | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-InDirectory { | |
Param( | |
[ValidateScript( { Test-Path $_ -PathType Container } )] | |
[string] $Path, | |
[ValidateNotNullOrEmpty()] | |
[scriptblock] $ScriptBlock | |
) | |
try { | |
Push-Location $Path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
Push-Location "./path/I/need/to/be/in" | |
try { | |
# do something here | |
} finally { | |
Pop-Location | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# modified from https://github.com/chriskuech/functional | |
function recursiveEquality($a, $b) { | |
# recursive step for arrays | |
if ($a -is [array] -and $b -is [array]) { | |
if ($a.Count -ne $b.Count) { | |
return $false | |
} | |
$inequalIndexes = 0..($a.Count - 1) | ? { -not (recursiveEquality $a[$_] $b[$_]) } | |
return $inequalIndexes.Count -eq 0 | |
} |
NewerOlder