pester / vscode-adapter

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

Throwing exception when using `pester.pesterModulePath` and when there are no Pester in `$PSModulePath` #189

Closed johlju closed 5 months ago

johlju commented 1 year ago

The extension started to throw an exception when using the setting pester.pesterModulePath and when there are no Pester in $PSModulePath.

Error log:

2023-08-19 14:49:20.860 [info] Test Run Start: 1 test items
2023-08-19 14:49:20.860 [debug] Run invoked on undiscovered testFile Install-SqlDscServer.Tests.ps1, discovery will be run first
2023-08-19 14:49:20.861 [debug] VSCode requested resolve for: /Users/johlju/source/SqlServerDsc/tests/Unit/Public/Install-SqlDscServer.Tests.ps1
2023-08-19 14:49:20.861 [debug] Adding to Discovery Queue:  /Users/johlju/source/SqlServerDsc/tests/Unit/Public/Install-SqlDscServer.Tests.ps1
2023-08-19 14:49:21.190 [info] Test Discovery Start: 1 files
2023-08-19 14:49:21.190 [info] Using Custom Pester Module Path specified in settings: ./output/RequiredModules/Pester
2023-08-19 14:49:21.190 [debug] Resolved Pester CustomModulePath ./output/RequiredModules/Pester to /Users/johlju/source/SqlServerDsc/output/RequiredModules/Pester
2023-08-19 14:49:21.198 [debug] Starting PowerShell Pester testing instance /usr/local/bin/pwsh with working directory /usr/local/bin
2023-08-19 14:49:21.198 [debug] Running Script in PS Worker: & '/Users/johlju/.vscode/extensions/pspester.pester-test-2023.7.8/Scripts/PesterInterface.ps1' -Discovery '/Users/johlju/source/SqlServerDsc/tests/Unit/Public/Install-SqlDscServer.Tests.ps1' -CustomModulePath /Users/johlju/source/SqlServerDsc/output/RequiredModules/Pester
2023-08-19 14:49:22.704 [error] Test Discovery failed: A terminating error was received from PowerShell: Pester 5.2.0 or greater is required to use the Pester Tests extension but was not found on your system. Please install the latest version of Pester from the PowerShell Gallery. at <ScriptBlock>, /Users/johlju/.vscode/extensions/pspester.pester-test-2023.7.8/Scripts/PesterInterface.ps1: line 33
at <ScriptBlock>, <No file>: line 1

This is due to a bug here:

https://github.com/pester/vscode-adapter/blob/0baee997e94b59d08f0e537b9672e5501d91e47d/Scripts/PesterInterface.ps1#L28-L34

It should use the variable $CustomModulePath istead of hardcode it to 'Pester'. Also, there is more logic in Invoke-Main that maybe should be concatenated:

https://github.com/pester/vscode-adapter/blob/0baee997e94b59d08f0e537b9672e5501d91e47d/Scripts/PesterInterface.ps1#L124-L125

nlsdg commented 5 months ago

Shouldn't this issue be closed, since there is a merged fix? Or is this waiting for something else?