Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V5rc6] Invoke-Pester -CI Various Issues #1527

Closed
JustinGrote opened this issue May 8, 2020 · 4 comments
Closed

[V5rc6] Invoke-Pester -CI Various Issues #1527

JustinGrote opened this issue May 8, 2020 · 4 comments
Milestone

Comments

@JustinGrote
Copy link
Contributor

JustinGrote commented May 8, 2020

1. General summary of the issue

PassThru doesn't save to variable

Invoke-Pester -PassThru works as expected and can be assigned to a variable
Invoke-Pester -PassThru -CI causes the object to not go to output and cannot be assigned.
image

LastExitCode doesn't work

image

@nohwnd nohwnd added this to the 5.0 milestone May 8, 2020
@JustinGrote
Copy link
Contributor Author

I narrowed this down to specifically Configuration.Run.Exit. Setting this to $true causes both issues without -CI specified.

@nohwnd
Copy link
Member

nohwnd commented May 10, 2020

On a closer look this works as designed. The process will exit with the correct code, and the object is output to the pipeline prior to that.

The thing is that in VSCode which is where you are probably trying it, it won't exit the process when calling exit, because of the special things they do to prevent that. So you will not close the process, but you also won't reach the $x = assignment. And because you are not running in strict mode your $x will resolve to null, instead of to InvalidOperation: The variable '$x' cannot be retrieved because it has not been set. error.

If you run it in a separate process it will run correctly:

$r = pwsh -c "import-module /projects/pester/bin/pester.psd1; invoke-pester C:\temp\Get-Emoji.Tests.ps1 -ci -passthru"; $lastexitcode; $r

1

Starting discovery in 1 files.
Discovery finished in 173ms.
[-] Get-Emoji.Gets avocado 48ms (45ms|3ms)
 Expected strings to be the same, but they were different.
 String lengths are both 2.
 Strings differ at index 0.
 Expected: '🥑'
 But was:  '🌵'
 at Get-Emoji -Emoji avocado | Should -Be '🥑', C:\temp\Get-Emoji.Tests.ps1:11
 at <ScriptBlock>, C:\temp\Get-Emoji.Tests.ps1:11
Tests completed in 890ms
Tests Passed: 1, Failed: 1, Skipped: 0 NotRun: 0

Containers            : {[-] C:\temp\Get-Emoji.Tests.ps1}
Result                : Failed

@nohwnd nohwnd closed this as completed May 10, 2020
@JustinGrote
Copy link
Contributor Author

@nohwnd confirmed, I also forgot "exit" will kill the entire process which makes sense the behavior I was hitting. Maybe -CI needs an option to throw a terminating error rather than "Exit" for when running pester in a CI build script such as Invoke-Build or PSake.

For now I just do a custom configuration and compare against the failedTests in the result, but for the -CI to have it's intended result, I think this is a worthwhile 5.1 item.

@nohwnd
Copy link
Member

nohwnd commented May 11, 2020

I agree throwing on failed run is needed, I am working around this in multiple pipelines as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants