Skip to content

Commit f5b370a

Browse files
committed
Import Pester separately
1 parent a1aa699 commit f5b370a

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -144,7 +144,8 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
144144

145145
private static async Task<string[]> GetLog()
146146
{
147-
while (!File.Exists(s_testOutputPath))
147+
using CancellationTokenSource cts = new(30000);
148+
while (!File.Exists(s_testOutputPath) && !cts.Token.IsCancellationRequested)
148149
{
149150
await Task.Delay(1000).ConfigureAwait(true);
150151
}
@@ -294,25 +295,40 @@ public async Task CanLaunchScriptWithCommentedLastLineAsync()
294295
[Fact]
295296
public async Task CanRunPesterTestFile()
296297
{
297-
string logStatement = GenerateScriptFromLoggingStatements("pester");
298-
string filePath = NewTestFile(@"
299-
Install-Module -Name Pester -Scope CurrentUser -Force | Import-Module -Force
300-
298+
string pesterTest = NewTestFile(@"
301299
Describe 'A' {
302300
Context 'B' {
303301
It 'C' {
304-
" + logStatement + @"
302+
{ throw 'error' } | Should -Throw
303+
}
304+
It 'D' {
305+
" + GenerateScriptFromLoggingStatements("pester") + @"
305306
}
306307
}
307-
}
308-
");
308+
}", isPester: true);
309309

310-
await PsesDebugAdapterClient.LaunchScript(filePath, Started).ConfigureAwait(true);
311-
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
312-
Assert.NotNull(configDoneResponse);
310+
string pesterLog = Path.Combine(s_binDir, Path.GetRandomFileName() + ".log");
313311

314-
Assert.Collection(await GetLog().ConfigureAwait(true),
315-
(i) => Assert.Equal("pester", i));
312+
string testCommand = @"
313+
Start-Transcript -Path '" + pesterLog + @"'
314+
Install-Module -Name Pester -RequiredVersion 5.3.3 -Force -PassThru | Write-Host
315+
Import-Module -Name Pester -RequiredVersion 5.3.3 -PassThru | Write-Host
316+
Invoke-Pester -Script '" + pesterTest + @"'
317+
Stop-Transcript";
318+
319+
string testFile = NewTestFile(testCommand);
320+
await PsesDebugAdapterClient.LaunchScript(testFile, Started).ConfigureAwait(true);
321+
await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
322+
323+
using CancellationTokenSource cts = new(5000);
324+
while (!File.Exists(pesterLog) && !cts.Token.IsCancellationRequested)
325+
{
326+
await Task.Delay(1000).ConfigureAwait(true);
327+
}
328+
await Task.Delay(15000).ConfigureAwait(true);
329+
_output.WriteLine(File.ReadAllText(pesterLog));
330+
331+
Assert.Collection(await GetLog().ConfigureAwait(true), (i) => Assert.Equal("pester", i));
316332
}
317333
}
318334
}

0 commit comments

Comments
 (0)