winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

RunTests.ps1 (2823B)


      1 # Copyright (c) Microsoft Corporation.
      2 # Licensed under the MIT License.
      3 [CmdletBinding()]
      4 param(
      5     [string]$testModulesPath,
      6     [string]$outputPath,
      7     [string]$packageLayoutPath,
      8     [switch]$TargetProduction,
      9     [string]$ConfigurationTestDataPath
     10 )
     11 
     12 # This updates pester not always necessary but worth noting
     13 Install-Module -Name Pester -Force -SkipPublisherCheck
     14 Import-Module Pester
     15 
     16 if (-not [System.String]::IsNullOrEmpty($testModulesPath))
     17 {
     18     $env:PSModulePath += ";$testModulesPath"
     19 }
     20 
     21 if (-not (Test-Path $outputPath))
     22 {
     23     New-Item -Path $outputPath -ItemType Directory
     24 }
     25 else
     26 {
     27     Remove-Item $outputPath\* -Recurse -Force
     28 }
     29 
     30 # Register the package
     31 if (-not [System.String]::IsNullOrEmpty($packageLayoutPath))
     32 {
     33     $local:packageManifestPath = Join-Path $packageLayoutPath "AppxManifest.xml"
     34 
     35     Import-Module Appx -UseWindowsPowerShell
     36     Add-AppxPackage -Register $local:packageManifestPath
     37 
     38     # Configure crash dump and log file settings
     39     if ($TargetProduction)
     40     {
     41         $local:wingetExeName = "winget.exe"
     42     }
     43     else
     44     {
     45         $local:wingetExeName = "wingetdev.exe"
     46     }
     47 
     48     $local:settingsExport = ConvertFrom-Json (& $local:wingetExeName settings export)
     49     $local:settingsFilePath = $local:settingsExport.userSettingsFile
     50     $local:settingsFileContent = ConvertTo-Json @{ debugging= @{ enableSelfInitiatedMinidump=$true ; keepAllLogFiles=$true } }
     51 
     52     Set-Content -Path $local:settingsFilePath -Value $local:settingsFileContent
     53 }
     54 
     55 $clientConfig = New-PesterConfiguration
     56 $clientConfig.TestResult.OutputFormat = "NUnitXML"
     57 $clientConfig.TestResult.OutputPath = "$outputPath\Tests-WinGetClient.XML"
     58 $clientConfig.TestResult.Enabled = $true
     59 $clientConfig.Run.Container = New-PesterContainer -Path "$PSScriptRoot\Microsoft.WinGet.Client.Tests.ps1" -Data @{ TargetProduction = $TargetProduction }
     60 
     61 Invoke-Pester -Configuration $clientConfig
     62 
     63 if ($PSEdition -eq "Core")
     64 {
     65     $configConfig = New-PesterConfiguration
     66     $configConfig.TestResult.OutputFormat = "NUnitXML"
     67     $configConfig.TestResult.OutputPath = "$outputPath\Tests-WinGetConfiguration.XML"
     68     $configConfig.TestResult.Enabled = $true
     69     $configConfig.Run.Container = New-PesterContainer -Path "$PSScriptRoot\Microsoft.WinGet.Configuration.Tests.ps1" -Data @{ ConfigurationTestDataPath = $ConfigurationTestDataPath }
     70 
     71     Invoke-Pester -Configuration $configConfig
     72 
     73     $dscConfig = New-PesterConfiguration
     74     $dscConfig.TestResult.OutputFormat = "NUnitXML"
     75     $dscConfig.TestResult.OutputPath = "$outputPath\Tests-WinGetDSC.XML"
     76     $dscConfig.TestResult.Enabled = $true
     77     $dscConfig.Run.Container = New-PesterContainer -Path "$PSScriptRoot\Microsoft.WinGet.DSC.Tests.ps1"
     78 
     79     Invoke-Pester -Configuration $dscConfig
     80 }