11Describe " ConvertTo-MarkdownFromHtml" {
22 BeforeAll {
33 Import-Module $PSScriptRoot \_TestHelpers.ps1 - Force
4-
4+ $script :inFile = " TestDrive:\123.html"
5+ $script :outFile = " TestDrive:\123.md"
6+ $script :htmlContent = " <h1>Hello World</h1>"
7+ Set-Content - Path $script :inFile - Value $script :htmlContent
58 }
69
710 BeforeEach {
811 Import-Module $PSScriptRoot \..\PSBlogger.psm1 - Force
912 }
1013
11- Context " Using Content" {
12-
13- BeforeEach {
14- $outFile = " TestDrive:\123.md"
15- $htmlContent = " <h1>Hello World</h1>"
14+ AfterEach {
15+ if (Test-Path $outFile ) {
16+ Remove-Item $outFile - Force
1617 }
18+ }
1719
18- AfterEach {
19- if (Test-Path $outFile ) {
20- Remove-Item $outFile - Force
21- }
22- }
20+ Context " Using Content" {
2321
24- It " Should save HTML content to a markdown file" {
22+ It " Should convert HTML content to Markdown file" {
2523 # act
26- ConvertTo-MarkdownFromHtml - Content $htmlContent - OutFile $outFile
24+ ConvertTo-MarkdownFromHtml - Content $script : htmlContent - OutFile $script : outFile
2725
2826 # assert
29- Test-Path $outFile | Should - BeTrue
27+ Test-Path $script :outFile | Should - BeTrue
28+ $content = (Get-Content - Path $script :outFile - Raw).Split(" `r " )
29+ $content [0 ] | Should - Be " # Hello World"
3030 }
3131
32- It " Should convert HTML content to Markdown file " {
32+ It " Should not persist to disk if OutFile is not specified " {
3333 # act
34- $content = ConvertTo-MarkdownFromHtml - Content $htmlContent - OutFile $outFile
34+ $content = ConvertTo-MarkdownFromHtml - Content $script : htmlContent
3535
3636 # assert
37- $content = ( Get-Content - Path $outFile - Raw).Split( " `r " )
38- $content [ 0 ] | Should - Be " # Hello World "
37+ $content | Should -Not - BeNullOrEmpty
38+ Test-Path $ script :outFile | Should - BeFalse
3939 }
4040
41- It " Should not persist to disk if OutFile is not specified" {
41+ It " Should return content when writing to disk if PassThru is specified" {
4242 # act
43- $content = ConvertTo-MarkdownFromHtml - Content $htmlContent
43+ $content = ConvertTo-MarkdownFromHtml - Content $script : htmlContent - OutFile $ script :outFile - PassThru
4444
4545 # assert
4646 $content | Should -Not - BeNullOrEmpty
47- Test-Path $outFile | Should - BeFalse
47+ Test-Path $script : outFile | Should - BeTrue
4848 }
4949 }
5050
5151 Context " Using File" {
5252
53- BeforeEach {
54- $htmlContent = " <h1>Hello World</h1>"
55- $htmlFile = " TestDrive:\123.html"
56- $markdownFile = " TestDrive:\123.md"
57- Set-Content - Path $htmlFile - Value $htmlContent
53+ It " Should convert HTML content to Markdown and persist to OutFile" {
54+ # act
55+ ConvertTo-MarkdownFromHtml - File $script :inFile - OutFile $script :outFile
56+
57+ # assert
58+ Test-Path $script :outFile | Should - BeTrue
59+ $content = (Get-Content - Path $script :outFile - Raw).Split(" `r " )
60+ $content [0 ] | Should - Be " # Hello World"
5861 }
5962
6063 It " Should convert HTML file to Markdown" {
6164 # act
62- $content = ConvertTo-MarkdownFromHtml - File $htmlFile - OutFile $markdownFile
65+ $content = ConvertTo-MarkdownFromHtml - File $script :inFile
6366
6467 # assert
65- Test-Path $markdownFile | Should - BeTrue
66- $content = (Get-Content - Path $markdownFile - Raw).Split(" `r " )
67- $content [0 ] | Should - Be " # Hello World"
68+ $content | Should -Not - BeNullOrEmpty
69+ $content | Should - BeLike " # Hello World*"
70+ }
71+
72+ It " Should delete temporary OutFile if OutFile is not specified" {
73+ # act
74+ $content = ConvertTo-MarkdownFromHtml - File $script :inFile
75+
76+ # assert
77+ $content | Should -Not - BeNullOrEmpty
78+ Test-Path $script :outFile | Should - BeFalse
6879 }
6980
70- It " Should delete temporary file " {
81+ It " Should return content when writing to disk if PassThru is specified " {
7182 # act
72- $content = ConvertTo-MarkdownFromHtml - File $htmlFile
83+ $content = ConvertTo-MarkdownFromHtml - File $script :inFile - OutFile $ script :outFile - PassThru
7384
7485 # assert
7586 $content | Should -Not - BeNullOrEmpty
76- Test-Path $markdownFile | Should - BeFalse
87+ Test-Path $script :outFile | Should - BeTrue
7788 }
7889 }
7990}
0 commit comments