Pester
Pester copied to clipboard
Unable to run Profiler on Pester tests with CodeCoverage
Checklist
- [X] Issue has a meaningful title
- [X] I have searched the existing issues. See all issues
- [X] I have tested using the latest version of Pester. See Installation and update guide.
What is the issue?
Running Pester's own tests inside Profiler fails.
Failing tests:
- /tst/Pester.Mock.RSpec.ts.ps1
[-] Use class with custom attribute.should be able to mock Test-Foo 27ms (21ms|6ms)
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
RuntimeException: The following exception occurred while constructing the attribute "ValidateClass": "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')"
PSInvalidCastException: Cannot convert value "Test-Foo" to type "System.Management.Automation.CommandMetadata". Error: "The following exception occurred while constructing the attribute "ValidateClass": "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')""
RuntimeException: Cannot convert value "Test-Foo" to type "System.Management.Automation.CommandMetadata". Error: "The following exception occurred while constructing the attribute "ValidateClass": "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')""
at <ScriptBlock>, /workspaces/Pester/src/functions/Mock.ps1:589
at Resolve-Command, /workspaces/Pester/src/functions/Mock.ps1:652
....
[-] Use class with custom attribute.should be able to run Test-Foo 14ms (8ms|6ms)
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
RuntimeException: The following exception occurred while constructing the attribute "ValidateClass": "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')"
at <ScriptBlock>, /workspaces/Pester/tst/Pester.Mock.ClassMetadata.ps1:28
at <ScriptBlock>, /workspaces/Pester/src/Pester.Runtime.ps1:1468
..
[n] - generating parametrized tests from foreach without external id -> Expected $true but got 'False'.
at Verify-True, /workspaces/Pester/tst/axiom/Verify-True.ps1:12
at <ScriptBlock>, /workspaces/Pester/tst/Pester.Mock.RSpec.ts.ps1:824
- /tst/Pester.RSpec.Coverage.ts.ps1
MethodInvocationException: /workspaces/Pester/src/functions/Coverage.ps1:1120:13
Line |
1120 | $profilerType::Register($tracer)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "Register" with "1" argument(s): "The provided tracer does not have Trace method with this signature: Trace(IScriptExtent extent, ScriptBlock scriptBlock, int level)"
...
[n] - Coverage is the same when breakpoints are used as when they are not used -> Expected not $null but got $null.
at Verify-NotNull, /workspaces/Pester/tst/axiom/Verify-NotNull.ps1:8
at <ScriptBlock>, /workspaces/Pester/tst/Pester.RSpec.Coverage.ts.ps1:76
- ./tst/functions/Coverage.Tests.ps1 - Almost everything fail.
InvalidOperationException: The provided tracer does not have Trace method with this signature: Trace(IScriptExtent extent, ScriptBlock scriptBlock, int level)
MethodInvocationException: Exception calling "Register" with "1" argument(s): "The provided tracer does not have Trace method with this signature: Trace(IScriptExtent extent, ScriptBlock scriptBlock, int level)"
Expected Behavior
All tests pass so I'm able to fully profile Pester's tests.
Steps To Reproduce
No response
Describe your environment
Pester version : 5.3.3 /workspaces/Pester/bin/Pester.psm1
PowerShell version : 7.2.1
OS version : Unix 5.10.102.1
Profiler version: 3.1.1
Possible Solution?
Not sure what's happening with the failed test in Pester.Mock.RSpec.ts.ps1.
For the Coverage-tests: Add missing overloads for Trace() in CodeCoverageTracer.cs that's compatible with Profiler 3 ExternalTraceAdapter and Profiler 4 ExternalTraceAdapter
https://github.com/nohwnd/Profiler/blob/34f09a97b7859618dd97feb7b691204df05ff9bf/csharp/Profiler/ExternalTracerAdapter.cs#L13-L23
Is this correct in Profiler 4? It looks for Trace(IScriptExtent, ScriptBlock, int, string) but it invokes Trace(IScriptExtent, ScriptBlock, int) in _traceMethod.
Update: Registered as issue in Profiler-repo