Skip to content

Commit

Permalink
Pester v5 (#366)
Browse files Browse the repository at this point in the history
Updated all Pester tests in the project to support Pester v5.  The main benefit that we get out of this, besides just moving on to the currently supported version of the test framework, is that we can now execute individual tests directly within VS Code.

In the process of doing this migration:

* Removed repository Code of Conduct tests from GitHubMiscellaneous.tests.ps1 since the command has been deprecated by GitHub
* Updated GitHubReleases.tests.ps1 to account for pre-releases
* Updated run-unitTests.yaml and CONTRIBUTING.md to have the Pester v5.3.3 install command, as well as to update its invocation commands.
* Removed the language-specific error messages in some `-Throws` tests because the wording keeps changing.
* Updated this project's VSCode settings.json to take advantage of the fact that the tests are now Pester 5 compatible.  This allows each individual block to have a Run/Debug link associated with it.  ([More info](https://pester.dev/docs/usage/vscode)).
* Disabled all of the Projects/ProjectCards/ProjectColumns tests because Classic Projects have been deprecated by GitHub (#380 for more info)

Fixes #194 

Co-authored-by: Howard Wolosky <HowardWolosky@users.noreply.github.com>
  • Loading branch information
tigerfansga and HowardWolosky authored Dec 16, 2022
1 parent 9388967 commit 5e1a4b3
Show file tree
Hide file tree
Showing 30 changed files with 8,917 additions and 8,186 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"files.trimTrailingWhitespace": true
},
"powershell.codeFormatting.openBraceOnSameLine": false,
"powershell.codeFormatting.alignPropertyValuePairs": false
}
"powershell.codeFormatting.alignPropertyValuePairs": false,
"powershell.pester.useLegacyCodeLens": false
}
21 changes: 15 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ This module supports testing using the [Pester UT framework](https://github.com/
To install it:

```powershell
Install-Module -Name Pester -RequiredVersion 4.10.1 -AllowClobber -SkipPublisherCheck -Force
Install-Module -Name Pester -MinimumVersion 5.3.3 -AllowClobber -SkipPublisherCheck -Force
```

#### Configuring Your Environment
Expand Down Expand Up @@ -421,21 +421,29 @@ Please keep in mind some tests may fail on your machine, as they test private it
Pester can also be used to test code-coverage, like so:

```powershell
Invoke-Pester -CodeCoverage "$root\GitHubLabels.ps1" -TestName "*"
$pesterConfig = New-PesterConfiguration
$pesterConfig.CodeCoverage.Path = @("$root\GitHubLabels.ps1")
$pesterConfig.CodeCoverage.Enabled = $true
Invoke-Pester -Configuration $pesterConfig
# Be sure you're not passing this in to -PesterOption, since that's different than the configuration.
```

This command tells Pester to check the `GitHubLabels.ps1` file for code-coverage.
The `-TestName` parameter tells Pester to run any `Describe` blocks with a `Name` like
`"*"` (which in this case, is every test, but can be made more specific).

The code-coverage object can be captured and interacted with, like so:

```powershell
$cc = (Invoke-Pester -CodeCoverage "$root\GitHubLabels.ps1" -TestName "*" -PassThru -Quiet).CodeCoverage
$pesterConfig = New-PesterConfiguration
$pesterConfig.CodeCoverage.Path = @("$root\GitHubLabels.ps1")
$pesterConfig.CodeCoverage.Enabled = $true
$pesterConfig.Run.PassThru = $true
$cc = (Invoke-Pester -Configuration $pesterConfig).CodeCoverage
```

There are many more nuances to code-coverage, see
[its documentation](https://github.com/pester/Pester/wiki/Code-Coverage) for more details.
[its documentation](https://pester.dev/docs/usage/code-coverage) for more details.

#### Automated Tests
[![Build status](https://dev.azure.com/ms/PowerShellForGitHub/_apis/build/status/PowerShellForGitHub-CI?branchName=master)](https://dev.azure.com/ms/PowerShellForGitHub/_build/latest?definitionId=109&branchName=master)
Expand Down Expand Up @@ -615,6 +623,7 @@ Thank you to all of our contributors, no matter how big or small the contributio
- **[Christoph Bergmeister (@bergmeister)](https://github.com/bergmeister)**
- **[Simon Heather (@X-Guardian)](https://github.com/X-Guardian)**
- **[Neil White (@variableresistor)](https://github.com/variableresistor)**
- **[Mark Curole(@tigerfansga)](https://github.com/tigerfansga)**

----------

Expand Down
4 changes: 2 additions & 2 deletions Tests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $script:originalConfigFile = $null

function Initialize-CommonTestSetup
{
<#
<#
.SYNOPSIS
Configures the tests to run with the authentication information stored in the project's
Azure DevOps pipeline (if that information exists in the environment).
Expand All @@ -38,7 +38,7 @@ function Initialize-CommonTestSetup
This method is invoked immediately after the declaration.
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification="Needed to configure with the stored, encrypted string value in Azure DevOps.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "Needed to configure with the stored, encrypted string value in Azure DevOps.")]
param()

$script:moduleName = 'PowerShellForGitHub'
Expand Down
19 changes: 9 additions & 10 deletions Tests/GitHubAnalytics.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@

[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '',
Justification='Suppress false positives in Pester code blocks')]
Justification = 'Suppress false positives in Pester code blocks')]
param()

# This is common test code setup logic for all Pester test files
$moduleRootPath = Split-Path -Path $PSScriptRoot -Parent
. (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1')

try
{
# TODO
BeforeAll {
# This is common test code setup logic for all Pester test files
$moduleRootPath = Split-Path -Path $PSScriptRoot -Parent
. (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1')
}
finally
{

# TODO

AfterAll {
if (Test-Path -Path $script:originalConfigFile -PathType Leaf)
{
# Restore the user's configuration to its pre-test state
Expand Down
Loading

0 comments on commit 5e1a4b3

Please sign in to comment.