Skip to content

Commit 4e4fdc3

Browse files
Add end-to-end Pester unit test (#1846)
1 parent ecd2f26 commit 4e4fdc3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs

+40
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,45 @@ public async Task CanLaunchScriptWithCommentedLastLineAsync()
291291
Assert.Collection(await GetLog().ConfigureAwait(true),
292292
(i) => Assert.Equal("a log statement", i));
293293
}
294+
295+
[SkippableFact]
296+
public async Task CanRunPesterTestFile()
297+
{
298+
Skip.If(s_isWindows, "Windows CI Pester is broken.");
299+
/* TODO: Get this to work on Windows.
300+
string pesterLog = Path.Combine(s_binDir, Path.GetRandomFileName() + ".log");
301+
302+
string testCommand = @"
303+
Start-Transcript -Path '" + pesterLog + @"'
304+
Install-Module -Name Pester -RequiredVersion 5.3.3 -Force -PassThru | Write-Host
305+
Import-Module -Name Pester -RequiredVersion 5.3.3 -PassThru | Write-Host
306+
Get-Content '" + pesterTest + @"'
307+
Stop-Transcript";
308+
309+
using CancellationTokenSource cts = new(5000);
310+
while (!File.Exists(pesterLog) && !cts.Token.IsCancellationRequested)
311+
{
312+
await Task.Delay(1000).ConfigureAwait(true);
313+
}
314+
await Task.Delay(15000).ConfigureAwait(true);
315+
_output.WriteLine(File.ReadAllText(pesterLog));
316+
*/
317+
318+
string pesterTest = NewTestFile(@"
319+
Describe 'A' {
320+
Context 'B' {
321+
It 'C' {
322+
{ throw 'error' } | Should -Throw
323+
}
324+
It 'D' {
325+
" + GenerateScriptFromLoggingStatements("pester") + @"
326+
}
327+
}
328+
}", isPester: true);
329+
330+
await PsesDebugAdapterClient.LaunchScript($"Invoke-Pester -Script '{pesterTest}'", Started).ConfigureAwait(true);
331+
await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
332+
Assert.Collection(await GetLog().ConfigureAwait(true), (i) => Assert.Equal("pester", i));
333+
}
294334
}
295335
}

0 commit comments

Comments
 (0)