Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize-TestEnvironment function does not support use of ScriptsToProcess parameter in PSD1 #97

Closed
ykuijs opened this issue Jan 13, 2021 · 0 comments · Fixed by #98
Closed

Comments

@ykuijs
Copy link
Member

ykuijs commented Jan 13, 2021

The function Initialize-TestEnvironment tries to import the specified module. However, if that module is using the ScriptsToProcess parameter in the PSD1 file, the function throws an error. I have tracked this down to the following line:

$ModuleUnderTest = Import-Module $Module -PassThru -ErrorAction Stop

In that case the Import-Module cmdlet returns two modules, resulting in $ModuleUnderTest to become an array instead of a string. All subsequent don't expect this scenario and fail.

The solution is to add Where-Object to the line:

$ModuleUnderTest = (Import-Module $Module -PassThru -ErrorAction Stop) | Where-Object -FilterScript { $_.Name -eq $Module }

Will submit a PR to correct this issue.

ykuijs added a commit to ykuijs/DscResource.Test that referenced this issue Jan 13, 2021
johlju pushed a commit that referenced this issue Jan 13, 2021
- Fix issue where the use of ScriptsToProcess causes the Initialize-TestEnvironment
  function to fail (issue #97).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant