test/documentation/Build-Documentation.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
using module ..\.\TestRunnerSupportModule.psm1

Describe "Test Build-Documentation" {
    BeforeAll {
        $TestSupportModule = [TestRunnerSupportModule]::new('MockModuleB')
        $MockDocDirectoryPath = Join-Path -Path $TestSupportModule.MockDirectoryPath -ChildPath 'docs' -Resolve

        # this test file needs the .git repo but not the docs folder
        Remove-Item -Path $MockDocDirectoryPath -Recurse
    }
    
    AfterAll {
        $TestSupportModule.Teardown()
    }

    Context "Given a value for Path, this function internally contains the following pipeline: Build-PlatyPSMarkdown | New-ExternalHelpFromPlatyPSMarkdown | Update-ReadmeFromPlatyPSMarkdown" {

        $Files = "Get-AFunction.md", "Get-BFunction.md", "Get-CFunction.md", "Set-CFunction.md" | `
            Sort-Object
        
        # NOTE: if this functions re-imports, it will import into a different scope or session.
        # Although it will still pass, it will write warnings and errors
        Build-Documentation -Path $TestSupportModule.MockDirectoryPath -NoReImportModule

        $FileNames = Get-ChildItem $MockDocDirectoryPath -Recurse | `
            ForEach-Object {$_.Name} | `
            Sort-Object

        It "Should generate correct number of files." {
            $FileNames.Count | Should -Be 4
        }

        It "Should generate exactly filenames." {
            $FileNames | Should -BeExactly $Files
        }

        It "Should have modified the new ReadMe file." {
            (Get-Content "$($TestSupportModule.MockDirectoryPath)\README.md" -Raw) -like "*API*" | Should -Be $true
        }

        It "Should modify Get-AFunction.md file at line number <Index> with: {<Expected>} " -TestCases @(
            @{ Index = 0; Expected = "---" },
            @{ Index = 1; Expected = "external help file: MockModuleB-help.xml" },
            @{ Index = 2; Expected = "Module Name: MockModuleB" },
            @{ Index = 3; Expected = "online version: https://github.com/marckassay/MockModuleB/blob/master/docs/Get-AFunction.md"},
            @{ Index = 4; Expected = "schema: 2.0.0" }
            @{ Index = 5; Expected = "---" }
            @{ Index = 6; Expected = "" }
            @{ Index = 7; Expected = "# Get-AFunction" }
            @{ Index = 8; Expected = "" }
            @{ Index = 9; Expected = "## SYNOPSIS" }
            @{ Index = 10; Expected = "{{Fill in the Synopsis}}" }
        ) {
            Param($Index, $Expected)
            $Actual = (Get-Content "$MockDocDirectoryPath\Get-AFunction.md")[$Index]
            $Actual.Replace('```', '`') | Should -BeExactly $Expected
        }

        # TODO: comment this out, since this will need to be in a different context. context of updating
        # existing files
        <#
        It "Should modify README.md file at line number <Index> with: {<Expected>} " -TestCases @(
            @{ Index = 0; Expected = "" },
            @{ Index = 1; Expected = "" },
            @{ Index = 2; Expected = "## Functions" },
            @{ Index = 3; Expected = "" },
            @{ Index = 4; Expected = "#### [```Get-AFunction```]()" }
            @{ Index = 5; Expected = "" }
            @{ Index = 6; Expected = " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam." }
            @{ Index = 7; Expected = " " }
            @{ Index = 8; Expected = "#### [```Get-BFunction```]()" }
        ) {
            Param($Index, $Expected)
            $Actual = (Get-Content "$TestDrive\MockModuleB\README.md")[$Index]
            $Actual.Replace('```', '`') | Should -BeExactly $Expected
        } #>

    }
}