-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSJekyll.tests.ps1
58 lines (57 loc) · 2.64 KB
/
PSJekyll.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
describe PSJekyll {
beforeAll {
$jekyllInPath = $ExecutionContext.SessionState.InvokeCommand.GetCommand('jekyll', 'Application')
if (-not $jekyllInPath -and $env:GITHUB_WORKFLOW) {
"::group::Installing prerequites" | Out-Host
sudo apt update | Out-Host
sudo apt install ruby-full bundler -y | Out-Host
sudo gem install jekyll | Out-Host
"::endgroup::" | Out-Host
}
}
context 'New-PSJekyll' {
it 'Will create a jekyll site' {
$siteName = "MyRandomSite$(Get-Random)"
$creatingSite = New-PSJekyll -Name $siteName
if ($creatingSite -is [Management.Automation.Job]) {
$creatingSite | Wait-Job
$creatingSite = $creatingSite | Receive-Job
}
Push-Location $siteName
$PSJekyll.CurrentSite.SiteName | Should -Be $siteName
Pop-Location
Remove-Item -Recurse -Force $siteName
}
}
context 'Start-PSJekyll' {
it 'Will start a jekyll site' {
$siteName = "MyRandomSite$(Get-Random)"
$creatingSite = New-PSJekyll -Name $siteName
if ($creatingSite -is [Management.Automation.Job]) {
$creatingSite | Wait-Job
$creatingSite = $creatingSite | Receive-Job
}
Push-Location $siteName
$randomPort = (Get-Random -Min 5000 -Maximum 8000)
Add-Content -Path "_config.yml" -Value "permalink: pretty"
$psJekyll.CurrentSite.Data = @{"StartTime"=[DateTime]::Now}
$psJekyll.CurrentSite.Layout = "contentOnly", "{{content}}"
$psJekyll.CurrentSite.Page = "aPage.md", @{"title"="My Page";layout="contentOnly"}, "This is my page. It was started at {{ site.data.StartTime }}"
$startingSite = Start-PSJekyll -Port $randomPort
if ($startingSite -is [Management.Automation.Job]) {
$startingSite | Wait-Job -Timeout 15
$startingSite = $startingSite | Receive-Job
}
Invoke-RestMethod -Uri "http://localhost:$randomPort" | Should -Not -Be $Null
$aPageOutput = Invoke-RestMethod -Uri "http://localhost:$randomPort/aPage"
$aPageOutput | Should -Not -Be $null
if ($aPageOutput.OuterXml) {
$aPageOutput.OuterXml | Should -Match "$([DateTime]::now.ToString('yyyy-MM-dd'))"
}
Pop-Location
Get-Job | Stop-Job
Get-Job | Remove-Job
Remove-Item -Recurse -Force $siteName
}
}
}