gaelcolas / Sampler

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

Simplify running code coverage for a single test file #387

Open johlju opened 2 years ago

johlju commented 2 years ago

Problem description

Currently when running ./build.ps1 -Task test -PesterPath ‘testfile’ it runs code coverage on all files in the built module result in a lot out missed lines (especially for big modules).

To be able to run code coverage for a single file using Invoke-Pester you have to pass a New-PesterConfiguration filled with the code script path and coverage path and settings. This can be complicated for new contributors.

Verbose logs

m/a

How to reproduce

n/a

Expected behavior

n/a

Current behavior

n/a

Suggested solution

We should simplify that by adding a CodeCovergePath to build.ps1 so it possible to write:

.\build.ps1 -Task test -PesterPath ‘testfile’ -CodeCoveragePath ‘code_script_file’

It will then also use settings from the build configuration.

Operating system the target node is running

n/a

PowerShell version and build the target node is running

n/a

Module version used

n/a
johlju commented 2 years ago

For this to work we need to get coverage for a specific source file in the built module (e.g. MOF-based DSC resource) using CodeCoveragePath, or a particular function inside the built module script file (.psm1) for modules using pattern Public/Private/Classes, using the same build.ps1 parameter CodeCoveragePath but pass an [System.Collections.IDictionary] like Pester expects. For the latter we need a way to single out the lines of an individual function or functions.

But it is not possible to pass an [System.Collections.IDictionary] to Pester due to issue https://github.com/pester/Pester/issues/2190.