__tests__/ConvertFromReadmeMD.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
115
Describe "Convertfrom ReadmdMD" {

    BeforeAll {
        Import-Module $PSScriptRoot\..\ConvertFromMarkdown.psm1 -Force
    }

    AfterEach {
        Remove-Item $env:TEMP\manuscript -Recurse -Force -ErrorAction Ignore
        Remove-Item $env:TEMP\lintThis.ps1 -Force -ErrorAction Ignore
    }

    It "Should create a manuscript folder" {
        ConvertFrom-Markdown $PSScriptRoot\README.md $env:TEMP

        Test-Path $env:TEMP\manuscript | Should Be $true
        Test-Path $env:TEMP\lintThis.ps1 | Should Be $true
    }

    It "Should have six files in the manuscript directory" {
        ConvertFrom-Markdown $PSScriptRoot\README.md $env:TEMP

        (Get-ChildItem $env:TEMP\manuscript | Measure-Object ).Count | Should Be 6
    }

    It "Read from the web, should have six files in the manuscript directory" {
        ConvertFrom-Markdown https://raw.githubusercontent.com/dfinke/ConvertFromMarkdown/master/__tests__/README.md $env:TEMP
        (Get-ChildItem $env:TEMP\manuscript | Measure-Object ).Count | Should Be 6
    }

    It "Should have book.md in the manuscript directory" {
        ConvertFrom-Markdown $PSScriptRoot\README.md $env:TEMP

        Test-Path $env:TEMP\manuscript\book.txt | Should Be $true
    }

    It "Should have five chapter files in the manuscript directory" {
        ConvertFrom-Markdown $PSScriptRoot\README.md $env:TEMP

        (Get-ChildItem $env:TEMP\manuscript chapter*.txt | Measure-Object ).Count | Should Be 5
    }

    It "Should create a manuscript folder no code blocks" {
        ConvertFrom-Markdown $PSScriptRoot\READMEOneChapterNoCode.md $env:TEMP

        Test-Path $env:TEMP\manuscript | Should Be $true
        Test-Path $env:TEMP\lintThis.ps1 | Should Be $false
    }

    It "Should create a test code blocks and delete lint file" {
        $actual = Test-PSCodeBlock $PSScriptRoot\READMEGoodCode.md $env:TEMP
        $actual | Should Be "all analyzed - no issues"
        Test-Path $env:TEMP\lintThis.ps1 | Should Be $false
    }

    It "Reads from the web, should create a test code blocks and delete lint file" {
        $actual = Test-PSCodeBlock https://raw.githubusercontent.com/dfinke/ConvertFromMarkdown/master/__tests__/READMEGoodCode.md $env:TEMP
        $actual | Should Be "all analyzed - no issues"
        Test-Path $env:TEMP\lintThis.ps1 | Should Be $false
    }

    It "Should keep lint file" {
        $actual = Test-PSCodeBlock $PSScriptRoot\READMEGoodCode.md $env:TEMP -KeepLintFile
        $actual | Should Be "all analyzed - no issues"

        Test-Path $env:TEMP\lintThis.ps1 | Should Be $true
    }

    It "Should handle errors in the fenced blocks" {
        $actual = Test-PSCodeBlock $PSScriptRoot\READMECodeThatErrors.md $env:TEMP
        $actual | Should Not Be "all analyzed - no issues"

        Test-Path $env:TEMP\lintThis.ps1 | Should Be $true
    }

    It "Should respect excluded blocks" {
        $actual = Test-PSCodeBlock $PSScriptRoot\READMEExcludeCode.md $env:TEMP
        $actual | Should Be "all analyzed - no issues"

        Test-Path $env:TEMP\lintThis.ps1 | Should Be $false
    }

    It "Should fail as a Uri" {
        Test-IsUri .\README.md | Should Be $false
    }

    It "Should be a Uri" {
        Test-IsUri https://raw.githubusercontent.com/dfinke/ConvertFromMarkdown/master/README.md | Should Be $true
    }

    AfterAll {
        Remove-Item $env:TEMP\manuscript -Recurse -Force -ErrorAction Ignore
        Remove-Item $env:TEMP\lintThis.ps1 -Force -ErrorAction Ignore
    }
}

Describe "Test markdown file with no chapters and no code" {
    BeforeAll {
        Import-Module $PSScriptRoot\..\ConvertFromMarkdown.psm1 -Force
    }

    It "Should report no code" {
        $actual = ConvertFrom-Markdown $PSScriptRoot\changelog.md -OutputType PDF

        $actual.Count | Should Be 2

        $actual[0] | Should Be 'no code found'
        $actual[1] | Should Be 'No chapters found'
    }

    AfterAll {
        Remove-Item $env:TEMP\manuscript -Recurse -Force -ErrorAction Ignore
        Remove-Item $env:TEMP\lintThis.ps1 -Force -ErrorAction Ignore
    }

}