1- # requires -Module ModuleBuilder
21. $PSScriptRoot \..\Convert-FolderSeparator.ps1
2+ $ProgressPreference = " SilentlyContinue"
33
44Describe " When we call Build-Module" - Tag Integration {
5- $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - Passthru
6- $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
5+ BeforeAll {
6+ $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - Passthru
7+ $Metadata = Import-Metadata $Output.Path
8+ $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
9+ }
710
811 It " Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
912 $Module | Should -Not - FileContentMatch ' ^Source$'
1013 }
1114
12- $Metadata = Import-Metadata $Output.Path
13-
1415 It " Should update FunctionsToExport in the manifest" {
1516 $Metadata.FunctionsToExport | Should - Be @ (" Get-Source" , " Set-Source" )
1617 }
@@ -29,15 +30,16 @@ Describe "When we call Build-Module" -Tag Integration {
2930}
3031
3132Describe " Regression test for #55: I can pass SourceDirectories" - Tag Integration, Regression {
32- $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - SourceDirectories " Private" - Passthru
33- $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
33+ BeforeAll {
34+ $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - SourceDirectories " Private" - Passthru
35+ $Metadata = Import-Metadata $Output.Path
36+ $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
37+ }
3438
3539 It " Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
3640 $Module | Should -Not - FileContentMatch ' ^Source$'
3741 }
3842
39- $Metadata = Import-Metadata $Output.Path
40-
4143 It " Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
4244 $Metadata.FunctionsToExport | Should - Be @ ()
4345 }
@@ -54,8 +56,8 @@ Describe "Regression test for #55: I can pass SourceDirectories" -Tag Integratio
5456Describe " Regression test for #55: I can pass SourceDirectories and PublicFilter" - Tag Integration, Regression {
5557 BeforeAll {
5658 $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - SourceDirectories " Private" - PublicFilter " Pub*\*" - Passthru
57- $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
5859 $Metadata = Import-Metadata $Output.Path
60+ $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
5961 }
6062
6163 It " Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
@@ -80,27 +82,30 @@ Describe "Regression test for #55: I can pass SourceDirectories and PublicFilter
8082}
8183
8284Describe " Regression test for #84: Multiple Aliases per command will Export" - Tag Integration, Regression {
83- $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - Passthru
84-
85- $Metadata = Import-Metadata $Output.Path
85+ BeforeAll {
86+ $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - Passthru
87+ $Metadata = Import-Metadata $Output.Path
88+ }
8689
8790 It " Should update AliasesToExport in the manifest" {
8891 $Metadata.AliasesToExport | Should - Be @ (" Get-MyAlias" , " GS" , " GSou" , " SS" , " SSou" )
8992 }
9093}
9194
9295Describe " Supports building without a build.psd1" - Tag Integration {
93- Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
94- # This is the old build, with a build.psd1
95- $Output = Build-Module TestDrive:\Source1\build.psd1 - Passthru
96- $ManifestContent = Get-Content $Output.Path
97- $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
98- Remove-Item (Split-Path $Output.Path ) - Recurse
96+ BeforeAll {
97+ Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
98+ # This is the old build, with a build.psd1
99+ $Output = Build-Module TestDrive:\Source1\build.psd1 - Passthru
100+ $ManifestContent = Get-Content $Output.Path
101+ $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
102+ Remove-Item (Split-Path $Output.Path ) - Recurse
99103
100- # Then remove the build.psd1 and rebuild it
101- Remove-Item TestDrive:\Source1\build.psd1
104+ # Then remove the build.psd1 and rebuild it
105+ Remove-Item TestDrive:\Source1\build.psd1
102106
103- $Build = @ { }
107+ $Build = @ { }
108+ }
104109
105110 It " No longer fails if there's no build.psd1" {
106111 $BuildParameters = @ {
@@ -158,17 +163,19 @@ Describe "Supports building without a build.psd1" -Tag Integration {
158163}
159164
160165Describe " Defaults to VersionedOutputDirectory" - Tag Integration {
161- Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
162- # This is the old build, with a build.psd1
163- $Output = Build-Module TestDrive:\Source1\build.psd1 - Passthru
164- $ManifestContent = Get-Content $Output.Path
165- $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
166- Remove-Item (Split-Path $Output.Path ) - Recurse
166+ BeforeAll {
167+ Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
168+ # This is the old build, with a build.psd1
169+ $Output = Build-Module TestDrive:\Source1\build.psd1 - Passthru
170+ $ManifestContent = Get-Content $Output.Path
171+ $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
172+ Remove-Item (Split-Path $Output.Path ) - Recurse
167173
168- # Then remove the build.psd1 and rebuild it
169- Remove-Item TestDrive:\Source1\build.psd1
174+ # Then remove the build.psd1 and rebuild it
175+ Remove-Item TestDrive:\Source1\build.psd1
170176
171- $Build = @ { }
177+ $Build = @ { }
178+ }
172179
173180 It " Builds into a folder with version by default" {
174181 $BuildParameters = @ {
@@ -207,20 +214,22 @@ Describe "Defaults to VersionedOutputDirectory" -Tag Integration {
207214}
208215
209216Describe " Supports building discovering the module without a build.psd1" - Tag Integration {
210- Copy-Item $PSScriptRoot \Source1 TestDrive:\source - Recurse
217+ BeforeAll {
218+ Copy-Item $PSScriptRoot \Source1 TestDrive:\source - Recurse
211219
212- # This is the old build, with a build.psd1
213- $Output = Build-Module TestDrive:\source\build.psd1 - Passthru
214- $ManifestContent = Get-Content $Output.Path
215- $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
216- Remove-Item (Split-Path $Output.Path ) - Recurse
220+ # This is the old build, with a build.psd1
221+ $Output = Build-Module TestDrive:\source\build.psd1 - Passthru
222+ $ManifestContent = Get-Content $Output.Path
223+ $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
224+ Remove-Item (Split-Path $Output.Path ) - Recurse
217225
218- # Then remove the build.psd1 and rebuild it
219- Remove-Item TestDrive:\source\build.psd1
226+ # Then remove the build.psd1 and rebuild it
227+ Remove-Item TestDrive:\source\build.psd1
220228
221- Push-Location - StackName ' IntegrationTest' - Path TestDrive:\
229+ Push-Location - StackName ' IntegrationTest' - Path TestDrive:\
222230
223- $Build = @ { }
231+ $Build = @ { }
232+ }
224233
225234 It " No longer fails if there's no build.psd1" {
226235 $Build.Output = Build-Module - Passthru
@@ -239,38 +248,41 @@ Describe "Supports building discovering the module without a build.psd1" -Tag In
239248 It " Should update FunctionsToExport in the manifest" {
240249 $Build.Metadata.FunctionsToExport | Should - Be @ (" Get-Source" , " Set-Source" )
241250 }
242-
243- Pop-Location - StackName ' IntegrationTest'
251+ AfterAll {
252+ Pop-Location - StackName ' IntegrationTest'
253+ }
244254}
245255
246256Describe " Regression test for #88 not copying prefix files" - Tag Integration, Regression {
247- $Output = Build-Module $PSScriptRoot \build.psd1 - Passthru
248-
249- $Metadata = Import-Metadata $Output.Path
257+ BeforeAll {
258+ $Output = Build-Module $PSScriptRoot \build.psd1 - Passthru
259+ $Metadata = Import-Metadata $Output.Path
260+ }
250261
251- It " Should update AliasesToExport in the manifest " {
262+ It " Should update the top of the module with that prefix " {
252263 $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
253264 $ModuleInfo = Get-Content $Module
254265 $ModuleInfo [0 ] | Should - be " using module Configuration"
255266 }
256267}
257268
258269Describe " Regression test for #40.2 not copying suffix if prefix" - Tag Integration, Regression {
259- Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
260-
261- New-Item TestDrive:\Source1\_GlobalScope.ps1 - Value ' $Global:Module = "Testing"'
270+ BeforeAll {
271+ Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
262272
263- $metadata = Import-Metadata TestDrive:\Source1\build.psd1
264- $metadata += @ {
265- Prefix = " ./_GlobalScope.ps1"
266- Suffix = " ./_GlobalScope.ps1"
267- }
268- $metadata | Export-Metadata TestDrive:\Source1\build.psd1
273+ New-Item TestDrive:\Source1\_GlobalScope.ps1 - Value ' $Global:Module = "Testing"'
269274
270- $Output = Build-Module TestDrive:\Source1 - Passthru
275+ $metadata = Import-Metadata TestDrive:\Source1\build.psd1
276+ $metadata += @ {
277+ Prefix = " ./_GlobalScope.ps1"
278+ Suffix = " ./_GlobalScope.ps1"
279+ }
280+ $metadata | Export-Metadata TestDrive:\Source1\build.psd1
271281
272- $Metadata = Import-Metadata $Output .Path
282+ $Output = Build-Module TestDrive:\Source1 - Passthru
273283
284+ $Metadata = Import-Metadata $Output.Path
285+ }
274286 It " Should inject the content of the _GlobalScope file at the TOP and BOTTOM" {
275287 $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
276288 $Code = Get-Content $Module
@@ -288,10 +300,12 @@ Describe "Regression test for #40.2 not copying suffix if prefix" -Tag Integrati
288300# There's no such thing as a drive root on unix
289301if ($PSVersionTable.Platform -eq " Win32NT" ) {
290302 Describe " Able to build from the drive root" {
291- $null = New-ModuleManifest " TestDrive:/MyModule.psd1" - ModuleVersion " 1.0.0" - Author " Tester"
292- $null = New-Item " TestDrive:/Public/Test.ps1" - Type File - Value ' MATCHING TEST CONTENT' - Force
303+ BeforeAll {
304+ $null = New-ModuleManifest " TestDrive:/MyModule.psd1" - ModuleVersion " 1.0.0" - Author " Tester"
305+ $null = New-Item " TestDrive:/Public/Test.ps1" - Type File - Value ' MATCHING TEST CONTENT' - Force
293306
294- $Result = Build-Module - SourcePath ' TestDrive:/MyModule.psd1' - Version " 1.0.0" - OutputDirectory ' ./output' - Encoding UTF8 - SourceDirectories @ (' Public' ) - Target Build - Passthru
307+ $Result = Build-Module - SourcePath ' TestDrive:/MyModule.psd1' - Version " 1.0.0" - OutputDirectory ' ./output' - Encoding UTF8 - SourceDirectories @ (' Public' ) - Target Build - Passthru
308+ }
295309
296310 It " Builds the Module in the designated output folder" {
297311 $Result.ModuleBase | Convert-FolderSeparator | Should - Be (Convert-FolderSeparator " TestDrive:/Output/MyModule/1.0.0" )
@@ -301,20 +315,21 @@ if ($PSVersionTable.Platform -eq "Win32NT") {
301315}
302316
303317Describe " Copies additional items specified in CopyPaths" {
318+ BeforeAll {
319+ $null = New-Item " TestDrive:/build.psd1" - Type File - Force - Value " @{
320+ SourcePath = 'TestDrive:/MyModule.psd1'
321+ SourceDirectories = @('Public')
322+ OutputDirectory = './output'
323+ CopyPaths = './lib', './MyModule.format.ps1xml'
324+ }"
325+ $null = New-ModuleManifest " TestDrive:/MyModule.psd1" - ModuleVersion " 1.0.0" - Author " Tester"
326+ $null = New-Item " TestDrive:/Public/Test.ps1" - Type File - Value ' MATCHING TEST CONTENT' - Force
327+ $null = New-Item " TestDrive:/MyModule.format.ps1xml" - Type File - Value ' <Configuration />' - Force
328+ $null = New-Item " TestDrive:/lib/imaginary1.dll" - Type File - Value ' 1' - Force
329+ $null = New-Item " TestDrive:/lib/subdir/imaginary2.dll" - Type File - Value ' 2' - Force
304330
305- $null = New-Item " TestDrive:/build.psd1" - Type File - Force - Value " @{
306- SourcePath = 'TestDrive:/MyModule.psd1'
307- SourceDirectories = @('Public')
308- OutputDirectory = './output'
309- CopyPaths = './lib', './MyModule.format.ps1xml'
310- }"
311- $null = New-ModuleManifest " TestDrive:/MyModule.psd1" - ModuleVersion " 1.0.0" - Author " Tester"
312- $null = New-Item " TestDrive:/Public/Test.ps1" - Type File - Value ' MATCHING TEST CONTENT' - Force
313- $null = New-Item " TestDrive:/MyModule.format.ps1xml" - Type File - Value ' <Configuration />' - Force
314- $null = New-Item " TestDrive:/lib/imaginary1.dll" - Type File - Value ' 1' - Force
315- $null = New-Item " TestDrive:/lib/subdir/imaginary2.dll" - Type File - Value ' 2' - Force
316-
317- $Result = Build-Module - SourcePath ' TestDrive:/build.psd1' - OutputDirectory ' ./output' - Version ' 1.0.0' - Passthru - Target Build
331+ $Result = Build-Module - SourcePath ' TestDrive:/build.psd1' - OutputDirectory ' ./output' - Version ' 1.0.0' - Passthru - Target Build
332+ }
318333
319334 It " Copies single files that are in CopyPaths" {
320335 (Convert-FolderSeparator $Result.ModuleBase ) | Should - Be (Convert-FolderSeparator " $TestDrive /output/MyModule/1.0.0" )
0 commit comments