From 6524548b43d3e2baf19a04db46b523c067107a83 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 18 Jul 2022 20:58:13 +0200 Subject: [PATCH] Remove module after QA tests --- tests/QA/module.tests.ps1 | 52 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/tests/QA/module.tests.ps1 b/tests/QA/module.tests.ps1 index f736563..d356085 100644 --- a/tests/QA/module.tests.ps1 +++ b/tests/QA/module.tests.ps1 @@ -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