test/module/manifest/Update-SemVer.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using module ..\..\.\TestRunnerSupportModule.psm1

Describe "Test Update-SemVer" {
    BeforeAll {
        $TestSupportModule = [TestRunnerSupportModule]::new('MockModuleB')
    }
    
    AfterAll {
        $TestSupportModule.Teardown()
    }

    Context "Calling Update-SemVer with Path to module directory" {

        It "Should start off with the expected version number" {
            $CurrentVersion = $(Import-PowerShellDataFile -Path ($TestSupportModule.MockManifestPath))['ModuleVersion']
            $CurrentVersion | Should -Be '0.0.1'
        }

        It "Should bump Major" {
            $Results = Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -BumpMajor
            $Results | Should -Be '1.0.1'
        }

        It "Should bump Patch" {
            $Results = Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -BumpPatch
            $Results | Should -Be '1.0.2'
        }

        It "Should bump Minor and Patch" {
            $Results = Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -BumpPatch -BumpMinor
            $Results | Should -Be '1.1.3'
        }

        It "Should change version to explict value" {
            $Results = Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -Value '2.0.0'
            $Results | Should -Be '2.0.0'
        }

        It "Should change version using positional parameter values for the trio" {
            $Results = Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) 1 2 3
            $Results | Should -Be '1.2.3'
        }

        It "Should change version using parameter values for the trio" {
            $Results = Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -Major 1 -Minor 0 -Patch 0
            $Results | Should -Be '1.0.0'
        }
    }

    Context "Calling Update-SemVer with -AutoUpdate" {
        Push-Location
        Set-Location $TestSupportModule.MockDirectoryPath
            
        Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -Value '3.0.0'
        Update-ModuleManifest -Path ($TestSupportModule.MockManifestPath) -HelpInfoUri "https://github.com/marckassay/MockModuleB/tree/3.0.0"

        It "Should change version to Git branch name - 3.0.1" {
            Invoke-Expression -Command 'git checkout -b 3.0.1'
            
            Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -AutoUpdate
            $Results = Test-ModuleManifest $TestSupportModule.MockManifestPath | `
                Select-Object -ExpandProperty Version 
         
            $Results.Major | Should -Be 3
            $Results.Minor | Should -Be 0
            $Results.Build | Should -Be 1
        }

        It "Should change HelpInfoUri to Git branch name - 3.0.1" {
            $HelpInfoUri = (Import-PowerShellDataFile -Path $TestSupportModule.MockManifestPath).HelpInfoUri
            $HelpInfoUri | Should -Be "https://github.com/marckassay/MockModuleB/tree/3.0.1"
        }

        It "Should change version to Git branch name - 3.1.1" {
 
            Invoke-Expression -Command 'git checkout -b 3.1.1'
            
            Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -AutoUpdate 
            $Results = Test-ModuleManifest $TestSupportModule.MockManifestPath | `
                Select-Object -ExpandProperty Version 
        
            $Results.Major | Should -Be 3
            $Results.Minor | Should -Be 1
            $Results.Build | Should -Be 1
        }

        It "Should change HelpInfoUri to Git branch name - 3.1.1" {
            $HelpInfoUri = (Import-PowerShellDataFile -Path $TestSupportModule.MockManifestPath).HelpInfoUri
            $HelpInfoUri | Should -Be "https://github.com/marckassay/MockModuleB/tree/3.1.1"
        }

        It "Should change version to Git branch name - 4.0.0" {
 
            Invoke-Expression -Command 'git checkout -b 4.0.0'
            
            Update-SemVer -Path ($TestSupportModule.MockDirectoryPath) -AutoUpdate
            $Results = Test-ModuleManifest $TestSupportModule.MockManifestPath | `
                Select-Object -ExpandProperty Version 
        
            $Results.Major | Should -Be 4
            $Results.Minor | Should -Be 0
            $Results.Build | Should -Be 0
        }

        
        It "Should change HelpInfoUri to Git branch name - 4.0.0" {
            $HelpInfoUri = (Import-PowerShellDataFile -Path $TestSupportModule.MockManifestPath).HelpInfoUri
            $HelpInfoUri | Should -Be "https://github.com/marckassay/MockModuleB/tree/4.0.0"
        }

        Pop-Location
    }
}