@@ -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 -Force -PassThru | Write-Host
315+ Import-Module -Name Pester -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+ await Task . Delay ( 10000 ) . ConfigureAwait ( true ) ;
323+
324+ using CancellationTokenSource cts = new ( 5000 ) ;
325+ while ( ! File . Exists ( pesterLog ) && ! cts . Token . IsCancellationRequested )
326+ {
327+ await Task . Delay ( 1000 ) . ConfigureAwait ( true ) ;
328+ }
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