gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
171 stars 42 forks source link

How do I use the extension Pester Tests in VS Code with modules built with Sampler? #486

Open DennisL68 opened 3 months ago

DennisL68 commented 3 months ago

Pester Tests keeps asking for the module when running one of the sample unit tests using VS Code...

An error occured running Pester: The specified module 'XXXX' was not loaded because no valid module file was found in any module directory.

johlju commented 3 months ago

I tried this in the SqlServerDsc repo:

https://github.com/dsccommunity/SqlServerDsc/blob/3c3092976409645d74f58707331f66ffe1967127/.vscode/settings.json#L102-L111

Although it requires to run noop in the PowerShell Extension terminal for it to find the correct version of Pester before opening a test file (unless Pester is also installed as a user or machine module).

Also I had to add code to the tests to run noop task so everything is set up, but that is just required for testing classes as it need a new process each time.

https://github.com/dsccommunity/SqlServerDsc/blob/3c3092976409645d74f58707331f66ffe1967127/tests/Unit/Public/Add-SqlDscNode.Tests.ps1#L5-L25