Skip to content

Commit 032a01e

Browse files
test: assert external deps are omitted from nuspec
1 parent ea90802 commit 032a01e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

test/PublishPSResourceTests/PublishPSResource.Tests.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,33 @@ function Test-PublishedFunction {
344344

345345
$expectedPath = Join-Path -Path $script:repositoryPath2 -ChildPath "$script:PublishModuleName.$version.nupkg"
346346
(Get-ChildItem $script:repositoryPath2).FullName | Should -Be $expectedPath
347+
348+
Add-Type -AssemblyName System.IO.Compression.FileSystem
349+
$package = [System.IO.Compression.ZipFile]::OpenRead($expectedPath)
350+
try {
351+
$nuspecEntry = $package.Entries | Where-Object FullName -like '*.nuspec' | Select-Object -First 1
352+
$nuspecEntry | Should -Not -BeNullOrEmpty
353+
354+
$reader = [System.IO.StreamReader]::new($nuspecEntry.Open())
355+
try {
356+
$nuspecXml = [xml]$reader.ReadToEnd()
357+
}
358+
finally {
359+
$reader.Dispose()
360+
}
361+
}
362+
finally {
363+
$package.Dispose()
364+
}
365+
366+
$namespaceManager = [System.Xml.XmlNamespaceManager]::new($nuspecXml.NameTable)
367+
$namespaceManager.AddNamespace('ns', 'http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd')
368+
$dependencyIds = @(
369+
$nuspecXml.SelectNodes('//ns:package/ns:metadata/ns:dependencies/ns:dependency', $namespaceManager) |
370+
ForEach-Object { $_.Attributes['id'].Value }
371+
)
372+
373+
$dependencyIds | Should -Not -Contain $externalModuleName
347374
}
348375

349376
It "Publish a module with -SkipDependenciesCheck" {

0 commit comments

Comments
 (0)