- Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathTestModule.ps1
39 lines (32 loc) · 1.61 KB
/
TestModule.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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
[CmdletBinding()]
param([string] $ModulePath, [string] $ModuleName, [string] $ModuleTestsPath, [switch]$Isolated)
$ErrorActionPreference='Stop'
# Install Pester
if (!(Get-Module-Name Pester -ListAvailable)) {
Install-Module-Name Pester -Force -SkipPublisherCheck
}
if(-not$Isolated) {
Write-Debug'Creating isolated process...'
$pwsh= [System.Diagnostics.Process]::GetCurrentProcess().Path
&"$pwsh"-NonInteractive -NoLogo -NoProfile -File $MyInvocation.MyCommand.Path@PSBoundParameters-Isolated
return
}
$modulePsd1=Get-Item-Path (Join-Path$ModulePath"./$ModuleName.psd1")
$LocalLoadEnvPS1=Join-Path$PSScriptRoot'Tests/loadEnv.ps1'
$AuthModulePSd1=Join-Path$PSScriptRoot"../src/Authentication/Authentication/artifacts/Microsoft.Graph.Authentication.psd1"
# Import required modules.
Import-Module-Name Pester
Import-Module$AuthModulePSd1
Import-Module-Name $modulePsd1.FullName
# Replace AutoREST loadEnv.ps1 with our local script.
Copy-Item-Path $LocalLoadEnvPS1-Destination $ModuleTestsPath
$PesterConfiguration= [PesterConfiguration]::Default
$PesterConfiguration.Run.Path=$ModuleTestsPath
$PesterConfiguration.Run.PassThru=$true
$PesterConfiguration.CodeCoverage.Enabled=$true
$PesterConfiguration.TestResult.Enabled=$true
$PesterConfiguration.TestResult.OutputPath= (Join-Path$ModuleTestsPath"$moduleName-TestResults.xml")
$TestResults=Invoke-Pester-Configuration $PesterConfiguration
If ($TestResults.FailedCount-gt0) { Write-Error"$($TestResults.FailedCount) tests failed." }