|
| 1 | +BeforeAll { |
| 2 | + $projectRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) |
| 3 | + . (Join-Path $projectRoot 'src/private/build/CopyProjectResource.ps1') |
| 4 | + |
| 5 | + function Get-NovaBuildProjectInfo {param([pscustomobject]$ProjectInfo)} |
| 6 | + function Get-ProjectResourceFolderPath {param([string]$ProjectRoot)} |
| 7 | + function Get-ProjectResourceItemList {param([string]$ResourceFolder)} |
| 8 | + function Copy-ProjectResourceContentToModuleRoot {param([System.IO.FileSystemInfo[]]$ItemList, [string]$OutputModuleDir)} |
| 9 | + function Copy-ProjectResourceFolderToOutputModuleDir {param([string]$ResourceFolder, [string]$OutputModuleDir)} |
| 10 | +} |
| 11 | + |
| 12 | +Describe 'Copy-ProjectResource' { |
| 13 | + BeforeEach { |
| 14 | + $script:root = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString('N')) |
| 15 | + $script:resourceFolder = Join-Path $script:root 'resources' |
| 16 | + $null = New-Item -ItemType Directory -Path $script:resourceFolder -Force |
| 17 | + Set-Content -LiteralPath (Join-Path $script:resourceFolder 'item.txt') -Value 'x' |
| 18 | + $script:projectData = [pscustomobject]@{ |
| 19 | + ProjectRoot = $script:root |
| 20 | + OutputModuleDir = (Join-Path $script:root 'dist') |
| 21 | + CopyResourcesToModuleRoot = $false |
| 22 | + } |
| 23 | + Mock Get-NovaBuildProjectInfo {return $script:projectData} |
| 24 | + Mock Get-ProjectResourceFolderPath {return $script:resourceFolder} |
| 25 | + Mock Get-ProjectResourceItemList {return @(Get-ChildItem -LiteralPath $script:resourceFolder)} |
| 26 | + Mock Copy-ProjectResourceContentToModuleRoot {} |
| 27 | + Mock Copy-ProjectResourceFolderToOutputModuleDir {} |
| 28 | + } |
| 29 | + |
| 30 | + AfterEach { |
| 31 | + Remove-Item -LiteralPath $script:root -Recurse -Force -ErrorAction SilentlyContinue |
| 32 | + } |
| 33 | + |
| 34 | + It 'returns silently when the resource folder does not exist' { |
| 35 | + Mock Get-ProjectResourceFolderPath {return (Join-Path $script:root 'missing')} |
| 36 | + |
| 37 | + Copy-ProjectResource |
| 38 | + |
| 39 | + Assert-MockCalled Copy-ProjectResourceContentToModuleRoot -Times 0 |
| 40 | + Assert-MockCalled Copy-ProjectResourceFolderToOutputModuleDir -Times 0 |
| 41 | + } |
| 42 | + |
| 43 | + It 'returns silently when the resource folder is empty' { |
| 44 | + Mock Get-ProjectResourceItemList {return @()} |
| 45 | + |
| 46 | + Copy-ProjectResource |
| 47 | + |
| 48 | + Assert-MockCalled Copy-ProjectResourceContentToModuleRoot -Times 0 |
| 49 | + Assert-MockCalled Copy-ProjectResourceFolderToOutputModuleDir -Times 0 |
| 50 | + } |
| 51 | + |
| 52 | + It 'flattens resources when CopyResourcesToModuleRoot is true' { |
| 53 | + $script:projectData.CopyResourcesToModuleRoot = $true |
| 54 | + |
| 55 | + Copy-ProjectResource |
| 56 | + |
| 57 | + Assert-MockCalled Copy-ProjectResourceContentToModuleRoot -Times 1 |
| 58 | + Assert-MockCalled Copy-ProjectResourceFolderToOutputModuleDir -Times 0 |
| 59 | + } |
| 60 | + |
| 61 | + It 'copies the resource folder when CopyResourcesToModuleRoot is false' { |
| 62 | + Copy-ProjectResource |
| 63 | + |
| 64 | + Assert-MockCalled Copy-ProjectResourceFolderToOutputModuleDir -Times 1 |
| 65 | + Assert-MockCalled Copy-ProjectResourceContentToModuleRoot -Times 0 |
| 66 | + } |
| 67 | +} |
0 commit comments