Skip to content

Commit

Permalink
Remove module after QA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Jul 18, 2022
1 parent 74a4506 commit 6524548
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions tests/QA/module.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,39 @@ BeforeAll {
).Directory.FullName
}

Describe 'Changelog Management' -Tag 'Changelog' {
It 'Changelog has been updated' -skip:(
!([bool](Get-Command git -EA SilentlyContinue) -and
[bool](&(Get-Process -id $PID).Path -NoProfile -Command 'git rev-parse --is-inside-work-tree 2>$null'))
) {
# Get the list of changed files compared with branch main
$HeadCommit = &git rev-parse HEAD
$defaultBranchCommit = &git rev-parse origin/main
$filesChanged = &git @('diff', "$defaultBranchCommit...$HeadCommit", '--name-only')
$filesStagedAndUnstaged = &git @('diff', "HEAD", '--name-only')

$filesChanged += $filesStagedAndUnstaged

# Only check if there are any changed files.
if ($filesChanged)
{
$filesChanged | Should -Contain 'CHANGELOG.md' -Because 'the CHANGELOG.md must be updated with at least one entry in the Unreleased section for each PR'
}
}
AfterAll {
Get-Module -Name 'DscResource.Common' -All | Remove-Module -Force
}

It 'Changelog format compliant with keepachangelog format' -skip:(![bool](Get-Command git -EA SilentlyContinue)) {
{ Get-ChangelogData (Join-Path $ProjectPath 'CHANGELOG.md') -ErrorAction Stop } | Should -Not -Throw
Describe 'Changelog Management' -Tag 'Changelog' {
It 'Changelog has been updated' -skip:(
!([bool](Get-Command git -EA SilentlyContinue) -and
[bool](&(Get-Process -id $PID).Path -NoProfile -Command 'git rev-parse --is-inside-work-tree 2>$null'))
) {
# Get the list of changed files compared with branch main
$HeadCommit = &git rev-parse HEAD
$defaultBranchCommit = &git rev-parse origin/main
$filesChanged = &git @('diff', "$defaultBranchCommit...$HeadCommit", '--name-only')
$filesStagedAndUnstaged = &git @('diff', "HEAD", '--name-only')

$filesChanged += $filesStagedAndUnstaged

# Only check if there are any changed files.
if ($filesChanged)
{
$filesChanged | Should -Contain 'CHANGELOG.md' -Because 'the CHANGELOG.md must be updated with at least one entry in the Unreleased section for each PR'
}
}

It 'Changelog should have an Unreleased header' -Skip:$skipTest {
(Get-ChangelogData -Path (Join-Path -Path $ProjectPath -ChildPath 'CHANGELOG.md') -ErrorAction 'Stop').Unreleased.RawData | Should -Not -BeNullOrEmpty
}
It 'Changelog format compliant with keepachangelog format' -skip:(![bool](Get-Command git -EA SilentlyContinue)) {
{ Get-ChangelogData (Join-Path $ProjectPath 'CHANGELOG.md') -ErrorAction Stop } | Should -Not -Throw
}

It 'Changelog should have an Unreleased header' -Skip:$skipTest {
(Get-ChangelogData -Path (Join-Path -Path $ProjectPath -ChildPath 'CHANGELOG.md') -ErrorAction 'Stop').Unreleased.RawData | Should -Not -BeNullOrEmpty
}
}

Describe 'General module control' -Tags 'FunctionalQuality' {
It 'Should import without errors' {
{ Import-Module -Name $script:moduleName -Force -ErrorAction Stop } | Should -Not -Throw
Expand Down

0 comments on commit 6524548

Please sign in to comment.