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
Fix line-based filter for tests with multiline testcases #1664
Conversation
Would this be considered a breaking fix considering someone might have scripts using line filter based on the current behaviour? |
@fflaten I don't think that it is breaking change, I doubt anyone was using it apart from VSCode and our own tests. |
Instead of specifying StartLine as a parameter to
Implemented it here to test. Thoughts? |
Get-PSCallstack is very slow, please don't use it. |
Converted it to a Draft PR, I always forget to remove the WIP: prefix. Please let me know when it's ready for review & merge. |
Cool. What about the last part in my previous comment. Do we need to revert 134f088 to stay backward compatible with third-party implementations of Block/Test or is it probably not needed? That's the only thing outstanding AFAIK. Not sure why the PR fails some checks. Feels like the PS4 host is failing random PTests. |
You don't have to revert it, I don't think there are any such implementations. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Just two suggestions, to make the parameter mandatory, to prevent us from errors, and to let possible external implementations (but there are probably none), that that this is needed. |
I actually avoided that due to all the tests using New-Block/Test directly 🙂 |
Duh! |
Tried it with this code on VSCode and it works perfect: Describe "d1" `
{
Context "c1" `
{
It "User with guard" `
{
1 | Should -Be 2
}
}
} One more tiny suggestion added in comments. |
1. General summary of the pull request
"Run Test" in VS Code doesn't work for running a single test which contains multiple lines to define testcases. The issue is caused by differences in how VS Code would identify the line number for a test compared to Pester's logic. Pester uses the start of scriptblock as the line number, while VS Code uses the line of
It
. VS Code's approach is preferred going forward as it's more consistent with other scenarios like describe, context and tests without testcases as well as being easier for an end user.This PR changes the linefilter-check to use a new "StartLine" property in Pester-objects of type Block (Describe/Context) and Test (It) which stores the location of the function name. This should solve the issue mentioned above.
Fix #1659
Original issue: PowerShell/vscode-powershell#2880