Skip to content

Commit

Permalink
Fix the issue when running the unit tests (#18300)
Browse files Browse the repository at this point in the history
* Fix the issue in unit tests.

- In the module we create a minimum runspace for PowerShell, and use it to parse the command line.
  The mini runspace contains the built-in core modules for PowerShell. We don't need them when we
  package and publish our module because the runtime will have them. That'll reduce the module size.
  So in the module project we exclude `contentfiles` when we referece Microsoft.PowerShell.SDK.
- The issue in the unit tests is that it doesn't find the built-in core module when we create the runspace.
  So we have a reference to Microsoft.PowerShell.SDK in the test project to include `contentfiles` to provide
  the built-in core modules. The unit tests can run successfully.

* Test
  • Loading branch information
kceiw authored and wyunchi-ms committed Jun 22, 2022
1 parent f7f1ae1 commit af693c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<ProjectReference Include="..\Az.Tools.Predictor\Az.Tools.Predictor.csproj" />
<!-- The test project doesn't reference to it directly. Az.Tools.Predictor has a reference to Microsoft.PowerShell.SDK.
- But it's excluding content files to reduce the size of the module. The content files are not needed since they're in the runtime (PowerShell)
- The content files are needed to set up the runspace to parse the command line. So we need to include them when we run the unit tests.
-->
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ For more information on Az Predictor, please visit the following: https://aka.ms
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.18.0" />
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.45-preview" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.0">
<ExcludeAssets>contentFiles</ExcludeAssets>
</PackageReference>
<PackageReference Include="System.Management.Automation" Version="7.2.0">
<ExcludeAssets>contentFiles</ExcludeAssets>
Expand Down

0 comments on commit af693c5

Please sign in to comment.