Skip to content

Commit

Permalink
Move Microsoft.WinGet.Client E2E test to Pester framework (#3503)
Browse files Browse the repository at this point in the history
This PR finally uses all the refactor to run the Microsoft.WinGet.Client PowerShell module in Pester. The tests are done in the BuildPowerShellModule phase.

The E2E Test Source is built in the build phases, then it will be get published as artifacts under E2ETests\TestLocalIndex'. Other artifacts that are required as published in E2ETests` as well. Having the test source as a build artifacts will make it easier to perform repros without building the source all over again.

The BuildPowerShellModule phase will download the artifacts, move necessary files to around, install the dev package (and dependencies), start the localhost web server and run the Pester tests. Then it will publish the modules as it used to as well as the test results.

It is important to remember the modules published as artifacts target the dev package, so one cannot just download it and use it without it.

I port all the E2E tests to Pester tests except the ones dealing with the server shutdown.

Eventually we will run tests for Microsoft.WinGet.DSC and Microsoft.WinGet.Configuration.
  • Loading branch information
msftrubengu authored Aug 12, 2023
1 parent b1c432f commit a52f278
Show file tree
Hide file tree
Showing 7 changed files with 435 additions and 1,015 deletions.
3 changes: 3 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ EFGH
EFile
endregion
ENDSESSION
epth
EQU
errmsg
ERRORONEXIT
ESource
ESRB
ests
etest
etl
execustom
Expand Down Expand Up @@ -173,6 +175,7 @@ hmodule
Howto
hre
hresults
hrow
hwnd
IARP
IAttachment
Expand Down
51 changes: 49 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
variables:
BuildVer: $[counter(dependencies.GetReleaseTag.outputs['GetTag.tag'], 1)]
buildOutDir: $(Build.SourcesDirectory)\src\$(buildPlatform)\$(buildConfiguration)
buildOutDirAnyCpu: $(Build.SourcesDirectory)\src\AnyCPU\$(buildConfiguration)
artifactsDir: $(Build.ArtifactStagingDirectory)\$(buildPlatform)
packageLayoutDir: $(Build.BinariesDirectory)\WingetPackageLayout

Expand Down Expand Up @@ -218,8 +219,8 @@ jobs:

- template: templates/e2e-setup.yml
parameters:
source: $(Build.SourcesDirectory)
buildOutDir: $(buildOutDir)
sourceDir: $(Build.SourcesDirectory)
localhostWebServerArgs: '-BuildRoot $(buildOutDir)\LocalhostWebServer -StaticFileRoot $(Agent.TempDirectory)\TestLocalIndex -LocalSourceJson $(Build.SourcesDirectory)\src\AppInstallerCLIE2ETests\TestData\localsource.json -SourceCert $(Build.SourcesDirectory)\src\AppInstallerCLIE2ETests\TestData\AppInstallerTest.cer'

- template: templates/e2e-test.template.yml
parameters:
Expand Down Expand Up @@ -260,6 +261,20 @@ jobs:
TargetFolder: '$(artifactsDir)\E2ETests\TestData'
condition: succeededOrFailed()

- task: CopyFiles@2
displayName: 'Copy LocalhostWebServer'
inputs:
SourceFolder: '$(buildOutDir)\LocalhostWebServer'
TargetFolder: '$(artifactsDir)\E2ETests\LocalhostWebServer'
condition: succeededOrFailed()

- task: CopyFiles@2
displayName: 'Copy Dev Package Dependencies'
inputs:
SourceFolder: '$(appxPackageDir)\AppInstallerCLIPackage_0.0.2.0_Test\Dependencies\$(buildPlatform)\'
TargetFolder: '$(artifactsDir)\E2ETests\DevPackageDependencies'
condition: succeededOrFailed()

- task: CopyFiles@2
displayName: 'Copy Files: WinGetUtilInterop.UnitTests'
inputs:
Expand Down Expand Up @@ -335,6 +350,13 @@ jobs:
TargetFolder: '$(artifactsDir)\PowerShell'
condition: succeededOrFailed()

- task: CopyFiles@2
displayName: 'Copy PowerShell AnyCPU Module Files'
inputs:
SourceFolder: '$(buildOutDirAnyCpu)\PowerShell'
TargetFolder: '$(artifactsDir)\PowerShell'
condition: succeededOrFailed()

- task: CopyFiles@2
displayName: 'Copy Dev Package (Loose Files)'
inputs:
Expand Down Expand Up @@ -407,7 +429,32 @@ jobs:
Contents: '**\*'
TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PowerShell@2
displayName: Install Tests Dependencies
inputs:
targetType: 'inline'
script: |
Get-ChildItem E2ETests\DevPackageDependencies -Filter *.appx | %{ Add-AppxPackage $_.FullName }
workingDirectory: $(Pipeline.Workspace)\Build.x64release\

- template: templates/e2e-setup.yml
parameters:
sourceDir: $(Build.SourcesDirectory)
localhostWebServerArgs: '-BuildRoot $(Pipeline.Workspace)\Build.x64release\E2ETests\LocalhostWebServer -StaticFileRoot $(Pipeline.Workspace)\Build.x64release\E2ETests\TestLocalIndex -SourceCert $(Build.SourcesDirectory)\src\AppInstallerCLIE2ETests\TestData\AppInstallerTest.cer'

- pwsh: .\RunTests.ps1 -testModulesPath $(Build.ArtifactStagingDirectory) -outputPath $(Pipeline.Workspace)\PesterTest -packageLayoutPath $(Pipeline.Workspace)\Build.x64release\DevPackage
workingDirectory: $(Build.SourcesDirectory)\src\PowerShell\tests\
displayName: Run Tests

- task: PublishTestResults@2
displayName: Publish Pester Test Results
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '$(Pipeline.Workspace)\PesterTest\Test*.xml'
failTaskOnFailedTests: true

- task: PublishPipelineArtifact@1
displayName: Publish PowerShell Module Artifacts
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
condition: succeededOrFailed()
Loading

0 comments on commit a52f278

Please sign in to comment.