pester / vscode-adapter

Run PowerShell Pester Tests with Visual Studio Code
MIT License
58 stars 14 forks source link

`Set-StrictMode -Latest` produces an error in the framework #145

Closed iRon7 closed 1 year ago

iRon7 commented 1 year ago

In most of my pester tests, I am testing with Set-StrictMode -Latest , like:

Describe 'MyTest' {

    BeforeAll {
        Set-StrictMode -Version Latest
    }
    ....

But this causes an (strictmode) error in the framework

Framework failed:
Result :Error :
Merge-TestData: C:\Users\Gebruiker\.vscode\extensions\pspester.pester-test-2023.4.0\Scripts\PesterInterface.ps1:141
Line |
 141 |          $Data = Merge-TestData $Test
     |                  ~~~~~~~~~~~~~~~~~~~~
     | The property 'Data' cannot be found on this object. Verify that the property exists.

at Merge-TestData, C:\Users\Gebruiker\.vscode\extensions\pspester.pester-test-2023.4.0\Scripts\PesterInterface.ps1: line 79
at New-TestItemId<Process>, C:\Users\Gebruiker\.vscode\extensions\pspester.pester-test-2023.4.0\Scripts\PesterInterface.ps1: line 141
at New-TestObject, C:\Users\Gebruiker\.vscode\extensions\pspester.pester-test-2023.4.0\Scripts\PesterInterface.ps1: line 246
at <ScriptBlock>, C:\Users\Gebruiker\.vscode\extensions\pspester.pester-test-2023.4.0\Scripts\PesterInterface.ps1: line 414
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 2037
at Invoke-ScriptBlock, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 2113
at Invoke-Block, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 956
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 881
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 1988
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 1949
at Invoke-ScriptBlock, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 2113
at Invoke-Block, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 928
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 881
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 1988
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 1949
at Invoke-ScriptBlock, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 2113
at Invoke-Block, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 928
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 1662
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.ps1: line 3
at <ScriptBlock>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 3154
at Invoke-InNewScriptScope, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 3161
at Run-Test, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 1665
at Invoke-Test, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 2465
at Invoke-Pester<End>, C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 5225
at Invoke-Main, C:\Users\Gebruiker\.vscode\extensions\pspester.pester-test-2023.4.0\Scripts\PesterInterface.ps1: line 495
at <ScriptBlock>, C:\Users\Gebruiker\.vscode\extensions\pspester.pester-test-2023.4.0\Scripts\PesterInterface.ps1: line 502
at <ScriptBlock>, <No file>: line 1
JustinGrote commented 1 year ago

Thanks for your submission! Dupe of https://github.com/pester/vscode-adapter/issues/85, the pesterinterface was not written with strictmode in mind as strictmode doesn't really provide much benefit other than a lot more annoying runtime errors. Its on the development list but low in priority, I'll certainly take PRs to refactor the PesterInterface.ps1 to work in strictm ode.