@@ -144,7 +144,8 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
144
144
145
145
private static async Task < string [ ] > GetLog ( )
146
146
{
147
- while ( ! File . Exists ( s_testOutputPath ) )
147
+ using CancellationTokenSource cts = new ( 30000 ) ;
148
+ while ( ! File . Exists ( s_testOutputPath ) && ! cts . Token . IsCancellationRequested )
148
149
{
149
150
await Task . Delay ( 1000 ) . ConfigureAwait ( true ) ;
150
151
}
@@ -294,25 +295,40 @@ public async Task CanLaunchScriptWithCommentedLastLineAsync()
294
295
[ Fact ]
295
296
public async Task CanRunPesterTestFile ( )
296
297
{
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 ( @"
301
299
Describe 'A' {
302
300
Context 'B' {
303
301
It 'C' {
304
- " + logStatement + @"
302
+ { throw 'error' } | Should -Throw
303
+ }
304
+ It 'D' {
305
+ " + GenerateScriptFromLoggingStatements ( "pester" ) + @"
305
306
}
306
307
}
307
- }
308
- " ) ;
308
+ }" , isPester : true ) ;
309
309
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" ) ;
313
311
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 ) ) ;
316
332
}
317
333
}
318
334
}
0 commit comments