run-tests.ps1 884 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env pwsh
  2. <#
  3. .SYNOPSIS
  4. Runs unit tests. Outputs test results and code coverage report.
  5. #>
  6. # Get path.
  7. $scriptDir = Split-Path $PSCommandPath -Parent
  8. $projectDir = (Get-Item $scriptDir).Parent
  9. # Set working directory to root of project.
  10. Push-Location $projectDir
  11. $ExitCode = 0
  12. # Run unit tests.
  13. pytest wagtailcrx/
  14. $ExitCode = $LastExitCode
  15. # Print code coverage if succeeded.
  16. if ($ExitCode -eq 0) {
  17. [xml]$BranchXML = Get-Content coverage.xml
  18. $LineRate = [math]::Round([decimal]$BranchXML.coverage.'line-rate' * 100, 2)
  19. Write-Output "All unit tests passed! 🎉"
  20. Write-Output "Code coverage: $LineRate%"
  21. }
  22. else {
  23. # Write the error in a way that shows up as the failure reason in Azure Pipelines.
  24. Write-Host "##vso[task.LogIssue type=error;]Unit tests failed."
  25. }
  26. # Unset working directory and exit with pytest's code.
  27. Pop-Location
  28. exit $ExitCode