-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertTo-MarkdownFromHtml.Tests.ps1
More file actions
90 lines (72 loc) · 2.59 KB
/
Copy pathConvertTo-MarkdownFromHtml.Tests.ps1
File metadata and controls
90 lines (72 loc) · 2.59 KB
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
Describe "ConvertTo-MarkdownFromHtml" {
BeforeAll {
Import-Module $PSScriptRoot\_TestHelpers.ps1 -Force
$script:inFile = "TestDrive:\123.html"
$script:outFile = "TestDrive:\123.md"
$script:htmlContent = "<h1>Hello World</h1>"
Set-Content -Path $script:inFile -Value $script:htmlContent
}
BeforeEach {
Import-Module $PSScriptRoot\..\PSBlogger.psm1 -Force
}
AfterEach {
if (Test-Path $outFile) {
Remove-Item $outFile -Force
}
}
Context "Using Content" {
It "Should convert HTML content to Markdown file" {
# act
ConvertTo-MarkdownFromHtml -Content $script:htmlContent -OutFile $script:outFile
# assert
Test-Path $script:outFile | Should -BeTrue
$content = (Get-Content -Path $script:outFile -Raw).Split("`r")
$content[0] | Should -BeLike "# Hello World*"
}
It "Should not persist to disk if OutFile is not specified" {
# act
$content = ConvertTo-MarkdownFromHtml -Content $script:htmlContent
# assert
$content | Should -Not -BeNullOrEmpty
Test-Path $script:outFile | Should -BeFalse
}
It "Should return content when writing to disk if PassThru is specified" {
# act
$content = ConvertTo-MarkdownFromHtml -Content $script:htmlContent -OutFile $script:outFile -PassThru
# assert
$content | Should -Not -BeNullOrEmpty
Test-Path $script:outFile | Should -BeTrue
}
}
Context "Using File" {
It "Should convert HTML content to Markdown and persist to OutFile" {
# act
ConvertTo-MarkdownFromHtml -File $script:inFile -OutFile $script:outFile
# assert
Test-Path $script:outFile | Should -BeTrue
$content = (Get-Content -Path $script:outFile -Raw).Split("`r")
$content[0] | Should -BeLike "# Hello World*"
}
It "Should convert HTML file to Markdown" {
# act
$content = ConvertTo-MarkdownFromHtml -File $script:inFile
# assert
$content | Should -Not -BeNullOrEmpty
$content | Should -BeLike "# Hello World*"
}
It "Should delete temporary OutFile if OutFile is not specified" {
# act
$content = ConvertTo-MarkdownFromHtml -File $script:inFile
# assert
$content | Should -Not -BeNullOrEmpty
Test-Path $script:outFile | Should -BeFalse
}
It "Should return content when writing to disk if PassThru is specified" {
# act
$content = ConvertTo-MarkdownFromHtml -File $script:inFile -OutFile $script:outFile -PassThru
# assert
$content | Should -Not -BeNullOrEmpty
Test-Path $script:outFile | Should -BeTrue
}
}
}