22. $PSScriptRoot \..\Convert-FolderSeparator.ps1
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+ $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
8+ $Metadata = Import-Metadata $Output.Path
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
1315
1416 It " Should update FunctionsToExport in the manifest" {
1517 $Metadata.FunctionsToExport | Should - Be @ (" Get-Source" , " Set-Source" )
@@ -29,14 +31,16 @@ Describe "When we call Build-Module" -Tag Integration {
2931}
3032
3133Describe " 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" )
34+ BeforeAll {
35+ $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - SourceDirectories " Private" - Passthru
36+ $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
37+ $Metadata = Import-Metadata $Output.Path
38+ }
3439
3540 It " Should not put the module's DefaultCommandPrefix into the psm1 as code. Duh!" {
3641 $Module | Should -Not - FileContentMatch ' ^Source$'
3742 }
3843
39- $Metadata = Import-Metadata $Output.Path
4044
4145 It " Should not have any FunctionsToExport if SourceDirectories don't match the PublicFilter" {
4246 $Metadata.FunctionsToExport | Should - Be @ ()
@@ -80,27 +84,30 @@ Describe "Regression test for #55: I can pass SourceDirectories and PublicFilter
8084}
8185
8286Describe " 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
87+ BeforeAll {
88+ $Output = Build-Module $PSScriptRoot \Source1\build.psd1 - Passthru
89+ $Metadata = Import-Metadata $Output.Path
90+ }
8691
8792 It " Should update AliasesToExport in the manifest" {
8893 $Metadata.AliasesToExport | Should - Be @ (" Get-MyAlias" , " GS" , " GSou" , " SS" , " SSou" )
8994 }
9095}
9196
9297Describe " 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
98+ BeforeAll {
99+ Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
100+ # This is the old build, with a build.psd1
101+ $Output = Build-Module TestDrive:\Source1\build.psd1 - Passthru
102+ $ManifestContent = Get-Content $Output.Path
103+ $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
104+ Remove-Item (Split-Path $Output.Path ) - Recurse
99105
100- # Then remove the build.psd1 and rebuild it
101- Remove-Item TestDrive:\Source1\build.psd1
106+ # Then remove the build.psd1 and rebuild it
107+ Remove-Item TestDrive:\Source1\build.psd1
102108
103- $Build = @ { }
109+ $Build = @ { }
110+ }
104111
105112 It " No longer fails if there's no build.psd1" {
106113 $BuildParameters = @ {
@@ -158,17 +165,19 @@ Describe "Supports building without a build.psd1" -Tag Integration {
158165}
159166
160167Describe " 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
168+ BeforeAll {
169+ Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
170+ # This is the old build, with a build.psd1
171+ $Output = Build-Module TestDrive:\Source1\build.psd1 - Passthru
172+ $ManifestContent = Get-Content $Output.Path
173+ $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
174+ Remove-Item (Split-Path $Output.Path ) - Recurse
167175
168- # Then remove the build.psd1 and rebuild it
169- Remove-Item TestDrive:\Source1\build.psd1
176+ # Then remove the build.psd1 and rebuild it
177+ Remove-Item TestDrive:\Source1\build.psd1
170178
171- $Build = @ { }
179+ $Build = @ { }
180+ }
172181
173182 It " Builds into a folder with version by default" {
174183 $BuildParameters = @ {
@@ -207,20 +216,22 @@ Describe "Defaults to VersionedOutputDirectory" -Tag Integration {
207216}
208217
209218Describe " Supports building discovering the module without a build.psd1" - Tag Integration {
210- Copy-Item $PSScriptRoot \Source1 TestDrive:\source - Recurse
219+ BeforeAll {
220+ Copy-Item $PSScriptRoot \Source1 TestDrive:\source - Recurse
211221
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
222+ # This is the old build, with a build.psd1
223+ $Output = Build-Module TestDrive:\source\build.psd1 - Passthru
224+ $ManifestContent = Get-Content $Output.Path
225+ $ModuleContent = Get-Content ([IO.Path ]::ChangeExtension($Output.Path , " .psm1" ))
226+ Remove-Item (Split-Path $Output.Path ) - Recurse
217227
218- # Then remove the build.psd1 and rebuild it
219- Remove-Item TestDrive:\source\build.psd1
228+ # Then remove the build.psd1 and rebuild it
229+ Remove-Item TestDrive:\source\build.psd1
220230
221- Push-Location - StackName ' IntegrationTest' - Path TestDrive:\
231+ Push-Location - StackName ' IntegrationTest' - Path TestDrive:\
222232
223- $Build = @ { }
233+ $Build = @ { }
234+ }
224235
225236 It " No longer fails if there's no build.psd1" {
226237 $Build.Output = Build-Module - Passthru
@@ -240,13 +251,16 @@ Describe "Supports building discovering the module without a build.psd1" -Tag In
240251 $Build.Metadata.FunctionsToExport | Should - Be @ (" Get-Source" , " Set-Source" )
241252 }
242253
243- Pop-Location - StackName ' IntegrationTest'
254+ AfterAll {
255+ Pop-Location - StackName ' IntegrationTest'
256+ }
244257}
245258
246259Describe " 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
260+ BeforeAll {
261+ $Output = Build-Module $PSScriptRoot \build.psd1 - Passthru
262+ $Metadata = Import-Metadata $Output.Path
263+ }
250264
251265 It " Should update AliasesToExport in the manifest" {
252266 $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
@@ -256,20 +270,22 @@ Describe "Regression test for #88 not copying prefix files" -Tag Integration, Re
256270}
257271
258272Describe " Regression test for #40.2 not copying suffix if prefix" - Tag Integration, Regression {
259- Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
273+ BeforeAll {
274+ Copy-Item $PSScriptRoot \Source1 TestDrive:\Source1 - Recurse
260275
261- New-Item TestDrive:\Source1\_GlobalScope.ps1 - Value ' $Global:Module = "Testing"'
276+ New-Item TestDrive:\Source1\_GlobalScope.ps1 - Value ' $Global:Module = "Testing"'
262277
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
278+ $metadata = Import-Metadata TestDrive:\Source1\build.psd1
279+ $metadata += @ {
280+ Prefix = " ./_GlobalScope.ps1"
281+ Suffix = " ./_GlobalScope.ps1"
282+ }
283+ $metadata | Export-Metadata TestDrive:\Source1\build.psd1
269284
270- $Output = Build-Module TestDrive:\Source1 - Passthru
285+ $Output = Build-Module TestDrive:\Source1 - Passthru
271286
272- $Metadata = Import-Metadata $Output.Path
287+ $Metadata = Import-Metadata $Output.Path
288+ }
273289
274290 It " Should inject the content of the _GlobalScope file at the TOP and BOTTOM" {
275291 $Module = [IO.Path ]::ChangeExtension($Output.Path , " psm1" )
@@ -288,10 +304,12 @@ Describe "Regression test for #40.2 not copying suffix if prefix" -Tag Integrati
288304# There's no such thing as a drive root on unix
289305if ($PSVersionTable.Platform -eq " Win32NT" ) {
290306 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
307+ BeforeAll {
308+ $null = New-ModuleManifest " TestDrive:/MyModule.psd1" - ModuleVersion " 1.0.0" - Author " Tester"
309+ $null = New-Item " TestDrive:/Public/Test.ps1" - Type File - Value ' MATCHING TEST CONTENT' - Force
293310
294- $Result = Build-Module - SourcePath ' TestDrive:/MyModule.psd1' - Version " 1.0.0" - OutputDirectory ' ./output' - Encoding UTF8 - SourceDirectories @ (' Public' ) - Target Build - Passthru
311+ $Result = Build-Module - SourcePath ' TestDrive:/MyModule.psd1' - Version " 1.0.0" - OutputDirectory ' ./output' - Encoding UTF8 - SourceDirectories @ (' Public' ) - Target Build - Passthru
312+ }
295313
296314 It " Builds the Module in the designated output folder" {
297315 $Result.ModuleBase | Convert-FolderSeparator | Should - Be (Convert-FolderSeparator " TestDrive:/Output/MyModule/1.0.0" )
@@ -301,20 +319,21 @@ if ($PSVersionTable.Platform -eq "Win32NT") {
301319}
302320
303321Describe " Copies additional items specified in CopyPaths" {
322+ BeforeAll {
323+ $null = New-Item " TestDrive:/build.psd1" - Type File - Force - Value " @{
324+ SourcePath = 'TestDrive:/MyModule.psd1'
325+ SourceDirectories = @('Public')
326+ OutputDirectory = './output'
327+ CopyPaths = './lib', './MyModule.format.ps1xml'
328+ }"
329+ $null = New-ModuleManifest " TestDrive:/MyModule.psd1" - ModuleVersion " 1.0.0" - Author " Tester"
330+ $null = New-Item " TestDrive:/Public/Test.ps1" - Type File - Value ' MATCHING TEST CONTENT' - Force
331+ $null = New-Item " TestDrive:/MyModule.format.ps1xml" - Type File - Value ' <Configuration />' - Force
332+ $null = New-Item " TestDrive:/lib/imaginary1.dll" - Type File - Value ' 1' - Force
333+ $null = New-Item " TestDrive:/lib/subdir/imaginary2.dll" - Type File - Value ' 2' - Force
304334
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
335+ $Result = Build-Module - SourcePath ' TestDrive:/build.psd1' - OutputDirectory ' ./output' - Version ' 1.0.0' - Passthru - Target Build
336+ }
318337
319338 It " Copies single files that are in CopyPaths" {
320339 (Convert-FolderSeparator $Result.ModuleBase ) | Should - Be (Convert-FolderSeparator " $TestDrive /output/MyModule/1.0.0" )
0 commit comments