Skip to content

Add option to tweak console output for better VSCode extension functionality - #479

Merged
dlwyatt merged 3 commits into
pester:masterfrom
dlwyatt:VSCode
Feb 29, 2016
Merged

dlwyatt merged 3 commits into
pester:masterfrom
dlwyatt:VSCode

Conversation

@dlwyatt

@dlwyatt dlwyatt commented Feb 21, 2016

Copy link
Copy Markdown
Member

@rkeithhill , start with this and let me know what you think. This was just about the quickest and laziest way I could implement this, just to get the ball rolling. If the new option is specified, the first line of the stack trace gets output in between the failed test header line and the error message. We can tweak this as needed. Here's how the usage works (same as you'd expect with New-PSSessionOption / etc):

$option = New-PesterOption -IncludeVSCodeMarker
Invoke-Pester -PesterOption $option

@rkeithhill

Copy link
Copy Markdown

Cool. I believe this will work just fine.

BTW as I've gotten more experience with the errors and warnings list in VSCode, I've found that it's not just a list but VSCode also decorates the failing test source with red squiggles and displays the problemMatcher message field text in a hover tip. At first I was using the It description of the test as the message but that is a bit redundant when you pop the hover tip in the test source e.g.:

vscodepestermessagetitle

That got me thinking that maybe I always grab the message from the third line. VSCode only allows you to pick the message text from a single line but I think the third line might work OK. Check it out:

vscodepestermessage

What do you think? Also, thanks!!

@dlwyatt

dlwyatt commented Feb 22, 2016

Copy link
Copy Markdown
Member Author

Only problem with that is that the most common test by far is Should Be, and the error message for that is always spread across at least two lines. (More if the values are strings.)

Describing Testing
 [-] Compares booleans 50ms
   at <ScriptBlock>, C:\Users\dlwya_000\OneDrive\Source\Temp\test.Tests.ps1: line 15
   Expected: {False}
   But was:  {True}
   15:         $true | Should Be $false
   at <ScriptBlock>, C:\Users\dlwya_000\OneDrive\Source\Temp\test.Tests.ps1: line 15
 [-] Compares strings 67ms
   at <ScriptBlock>, C:\Users\dlwya_000\OneDrive\Source\Temp\test.Tests.ps1: line 19
   String lengths are both 10. Strings differ at index 7.
   Expected: {String two}
   But was:  {String one}
   ------------------^
   19:         'String one' | Should Be 'String two'
   at <ScriptBlock>, C:\Users\dlwya_000\OneDrive\Source\Temp\test.Tests.ps1: line 19

@rkeithhill

Copy link
Copy Markdown

Yeah, that is less than ideal. OK, I'll stick with the It description for now. I think that is more handy - at least in the errors and warnings list.
vscodepestermessagedash

What do you think about including [-] in the message text? I've submitted an issue to the VSCode project that it is hard to tell what the origin of an error or warning is.

In the PowerShell extension case, it could be either Pester or PSScriptAnalyzer. I figured putting in the [-] at the beginning of the message would help to indicate it is a pester test failure. Thoughts?

BTW I want to note the version of Pester required in the VSCode tasks.json example file. Would this be 3.3.15 or 3.4.0?

@daviwil

daviwil commented Feb 29, 2016

Copy link
Copy Markdown

Awesome, thanks so much for working this out! I think people will be pretty happy to have good Pester integration in VS Code :)

@dlwyatt

dlwyatt commented Feb 29, 2016

Copy link
Copy Markdown
Member Author

This will be 3.4.0. Just need to tie up the loose ends, add some documentation and I'll get it released tonight.

Following the pattern of New-PSSessionOption / etc, people can just pass a hashtable to the -PesterOption parameter, if desired.
dlwyatt added a commit that referenced this pull request Feb 29, 2016
@dlwyatt
dlwyatt merged commit a1e7ce2 into pester:master Feb 29, 2016
@dlwyatt
dlwyatt deleted the VSCode branch February 29, 2016 22:11
@dlwyatt dlwyatt changed the title Initial fix for #470 Add option to tweak console output for better VSCode extension functionality Feb 29, 2016
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

Successfully merging this pull request may close these issues.

3 participants