Skip to content

Commit

Permalink
Add end-to-end Pester unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Jul 1, 2022
1 parent ecd2f26 commit ba30996
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,45 @@ public async Task CanLaunchScriptWithCommentedLastLineAsync()
Assert.Collection(await GetLog().ConfigureAwait(true),
(i) => Assert.Equal("a log statement", i));
}

[SkippableFact]
public async Task CanRunPesterTestFile()
{
Skip.If(s_isWindows, "Windows CI Pester is broken.");
/* TODO: Get this to work on Windows.
string pesterLog = Path.Combine(s_binDir, Path.GetRandomFileName() + ".log");
string testCommand = @"
Start-Transcript -Path '" + pesterLog + @"'
Install-Module -Name Pester -RequiredVersion 5.3.3 -Force -PassThru | Write-Host
Import-Module -Name Pester -RequiredVersion 5.3.3 -PassThru | Write-Host
Get-Content '" + pesterTest + @"'
Stop-Transcript";
using CancellationTokenSource cts = new(5000);
while (!File.Exists(pesterLog) && !cts.Token.IsCancellationRequested)
{
await Task.Delay(1000).ConfigureAwait(true);
}
await Task.Delay(15000).ConfigureAwait(true);
_output.WriteLine(File.ReadAllText(pesterLog));
*/

string pesterTest = NewTestFile(@"
Describe 'A' {
Context 'B' {
It 'C' {
{ throw 'error' } | Should -Throw
}
It 'D' {
" + GenerateScriptFromLoggingStatements("pester") + @"
}
}
}", isPester: true);

await PsesDebugAdapterClient.LaunchScript($"Invoke-Pester -Script '{pesterTest}'", Started).ConfigureAwait(true);
await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
Assert.Collection(await GetLog().ConfigureAwait(true), (i) => Assert.Equal("pester", i));
}
}
}

0 comments on commit ba30996

Please sign in to comment.