gaelcolas / Sampler

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

Invoke-Pester.pester.build.ps1 does not support $BuiltModuleSubdirectory #239

Closed stevehose closed 3 years ago

stevehose commented 3 years ago

ISSUE DESCRIPTION: I have used $BuiltModuleSubdirectory as a parameter for a build for my project. The build succeeds and the project code is loaded into \Modules and runs correctly. The required DSC resources that my project relies on are all loaded into output\RequiredModules as expected.

However, running the build task named 'test' fails. The issue comes from Invoke-Pester.pester.build.ps1. The code has this block repeated in it for multiple tasks:

    $getModuleVersionParameters = @{
        OutputDirectory = $OutputDirectory
        ProjectName     = $ProjectName
    }

    $ModuleVersion = Get-BuiltModuleVersion @getModuleVersionParameters

The problem is that $OutputDirectory looks specifically at the output folder. It won't look in $BuiltModuleSubdirectory to find my module's manifest.

The desired behavior is that tests should reference modules in $BuiltModuleSubdirectory if it is used by the project.

Suggested solution to the issue

I have fixed it in my repo by adding a copy of the task to .build\tasks. I replaced the existing block with this one:

    if ($BuiltModuleSubdirectory.Length -gt 0){
        $useModuleDirectory = Join-Path -path $OutputDirectory -ChildPath $BuiltModuleSubdirectory
    } else {
        $useModuleDirectory = $OutputDirectory
    }

    $getModuleVersionParameters = @{
        OutputDirectory = $useModuleDirectory
        ProjectName     = $ProjectName
    }

    $ModuleVersion = Get-BuiltModuleVersion @getModuleVersionParameters

I also added an additional parameter to the file:

    [Parameter()]
    [System.String]
    $BuiltModuleSubdirectory = (property BuiltModuleSubdirectory $BuiltModuleSubdirectory),

My version tests to see if it should be looking in $BuiltModuleSubdirectory before proceeding to Get-BuiltModuleVersion.

The operating system the target node is running

OsName : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition OsArchitecture : 64-bit WindowsVersion : 2009 WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value PSVersion 5.1.19041.610 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.610 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1