Skip to content

Commit deab95f

Browse files
authored
SWA test stability (#697)
* Fixes #677 Update project references and improve app setup - Added project reference for `CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.csproj` in `CommunityToolkit.Aspire.StaticWebApps.AppHost.csproj`. - Changed web app setup in `Program.cs` from `.AddNpmApp` to `.AddViteApp` with `.WithNpmPackageInstallation()`. - Modified `Port` property in `SwaResourceOptions.cs` to use a random port between 4280 and 5280. - Updated tests in `SwaHostingComponentTests.cs` to utilize `CancellationToken` for better control over async operations. Related Work Items: #6, #677 * reverting port change and disabling tests * Deprecating the SWA emulator integration Contributes to #698 * Updating readmie * forcing the dev certs install for SWA * Revert "forcing the dev certs install for SWA" This reverts commit 15475a6. * Commenting out the tests completely This precents the test app host from actually starting up
1 parent 716ee8d commit deab95f

File tree

11 files changed

+89
-29
lines changed

11 files changed

+89
-29
lines changed

docs/diagnostics.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ Once a release of .NET Aspire with that API is available, the API in the .NET As
1313
## CTASPIRE002
1414

1515
Support for loading extensions into SQLite requires either a NuGet package or folder path to the library to be provided, and as a result there is some custom logic to load the extension based on the path or NuGet package. This logic will require some experimenting to figure out edge cases, so the feature for extension loading will be kept as experimental until it is proven to be stable.
16+
17+
## CTASPIRE003
18+
19+
The API is marked for deprecation and will be removed in a future release.

examples/swa/CommunityToolkit.Aspire.StaticWebApps.AppHost/CommunityToolkit.Aspire.StaticWebApps.AppHost.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)"/>
2+
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)" />
33

44
<PropertyGroup>
55
<OutputType>Exe</OutputType>
@@ -13,6 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16+
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.csproj" IsAspireProjectResource="false" />
1617
<ProjectReference Include="..\CommunityToolkit.Aspire.StaticWebApps.ApiApp\CommunityToolkit.Aspire.StaticWebApps.ApiApp.csproj" />
1718
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.csproj" IsAspireProjectResource="false" />
1819
</ItemGroup>

examples/swa/CommunityToolkit.Aspire.StaticWebApps.AppHost/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
.WithHttpHealthCheck("/health");
55

66
var web = builder
7-
.AddNpmApp("web", Path.Combine(builder.AppHostDirectory, "..", "CommunityToolkit.Aspire.StaticWebApps.WebApp"), "dev")
8-
.WithHttpEndpoint(env: "PORT")
7+
.AddViteApp("web", Path.Combine(builder.AppHostDirectory, "..", "CommunityToolkit.Aspire.StaticWebApps.WebApp"))
8+
.WithNpmPackageInstallation()
99
.WithHttpHealthCheck("/");
1010

11+
#pragma warning disable CTASPIRE003 // Type or member is obsolete
1112
_ = builder
1213
.AddSwaEmulator("swa")
1314
.WithAppResource(web)
1415
.WithApiResource(api);
16+
#pragma warning restore CTASPIRE003 // Type or member is obsolete
1517

1618
builder.Build().Run();

src/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps library
22

3+
**Deprecation warning**: This library is deprecated and will be removed in a future release, refer to https://github.com/CommunityToolkit/Aspire/issues/698 for more information.
4+
35
Provides extensions methods and resource definitions for the .NET Aspire AppHost to support running Azure Static Web Apps locally using the emulator using the [Azure Static Web App CLI](https://learn.microsoft.com/azure/static-web-apps/local-development).
46

57
## Getting Started

src/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps/SwaApiEndpointAnnotation.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace Aspire.Hosting.ApplicationModel;
44
/// Represents an annotation for an API endpoint in a Static Web App.
55
/// </summary>
66
/// <param name="resource">The resource builder for resources with endpoints.</param>
7+
[Obsolete(
8+
message: "The SWA emulator integration is going to be removed in a future release.",
9+
error: false,
10+
DiagnosticId = "CTASPIRE003",
11+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
712
public class SwaApiEndpointAnnotation(IResourceBuilder<IResourceWithEndpoints> resource) : IResourceAnnotation
813
{
914
/// <summary>

src/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps/SwaAppEndpointAnnotation.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace Aspire.Hosting.ApplicationModel;
77
/// Initializes a new instance of the <see cref="SwaAppEndpointAnnotation"/> class.
88
/// </remarks>
99
/// <param name="resource">The resource builder for the endpoint.</param>
10+
[Obsolete(
11+
message: "The SWA emulator integration is going to be removed in a future release.",
12+
error: false,
13+
DiagnosticId = "CTASPIRE003",
14+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
1015
public class SwaAppEndpointAnnotation(IResourceBuilder<IResourceWithEndpoints> resource) : IResourceAnnotation
1116
{
1217
/// <summary>

src/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps/SwaAppHostingExtension.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ namespace Aspire.Hosting;
55
/// <summary>
66
/// Provides extension methods for adding and configuring Static Web Apps emulator.
77
/// </summary>
8+
[Obsolete(
9+
message: "The SWA emulator integration is going to be removed in a future release.",
10+
error: false,
11+
DiagnosticId = "CTASPIRE003",
12+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
813
public static class SwaAppHostingExtension
914
{
1015
/// <summary>
@@ -14,6 +19,11 @@ public static class SwaAppHostingExtension
1419
/// <param name="name">The name of the resource.</param>
1520
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
1621
/// <remarks>This resource will not be included in the published manifest.</remarks>
22+
[Obsolete(
23+
message: "The SWA emulator integration is going to be removed in a future release.",
24+
error: false,
25+
DiagnosticId = "CTASPIRE003",
26+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
1727
public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedApplicationBuilder builder, [ResourceName] string name) =>
1828
builder.AddSwaEmulator(name, new SwaResourceOptions());
1929

@@ -25,6 +35,11 @@ public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedAppl
2535
/// <param name="options">The <see cref="SwaResourceOptions"/> to configure the SWA CLI.</param>"
2636
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
2737
/// <remarks>This resource will not be included in the published manifest.</remarks>
38+
[Obsolete(
39+
message: "The SWA emulator integration is going to be removed in a future release.",
40+
error: false,
41+
DiagnosticId = "CTASPIRE003",
42+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
2843
public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedApplicationBuilder builder, [ResourceName] string name, SwaResourceOptions options)
2944
{
3045
var resource = new SwaResource(name, Environment.CurrentDirectory);
@@ -62,6 +77,11 @@ public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedAppl
6277
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
6378
/// <param name="appResource">The existing <see cref="IResourceBuilder{IResourceWithEndpoint}"/> to use as the <c>--app-devserver-url</c> argument.</param>
6479
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
80+
[Obsolete(
81+
message: "The SWA emulator integration is going to be removed in a future release.",
82+
error: false,
83+
DiagnosticId = "CTASPIRE003",
84+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
6585
public static IResourceBuilder<SwaResource> WithAppResource(this IResourceBuilder<SwaResource> builder, IResourceBuilder<IResourceWithEndpoints> appResource) =>
6686
builder.WithAnnotation<SwaAppEndpointAnnotation>(new(appResource), ResourceAnnotationMutationBehavior.Replace).WaitFor(appResource);
6787

@@ -71,6 +91,11 @@ public static IResourceBuilder<SwaResource> WithAppResource(this IResourceBuilde
7191
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
7292
/// <param name="apiResource">The existing <see cref="IResourceBuilder{IResourceWithEndpoint}"/> to use as the <c>--api-devserver-url</c> argument.</param>
7393
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
94+
[Obsolete(
95+
message: "The SWA emulator integration is going to be removed in a future release.",
96+
error: false,
97+
DiagnosticId = "CTASPIRE003",
98+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
7499
public static IResourceBuilder<SwaResource> WithApiResource(this IResourceBuilder<SwaResource> builder, IResourceBuilder<IResourceWithEndpoints> apiResource) =>
75100
builder.WithAnnotation<SwaApiEndpointAnnotation>(new(apiResource), ResourceAnnotationMutationBehavior.Replace).WaitFor(apiResource);
76101
}

src/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps/SwaResource.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace Aspire.Hosting.ApplicationModel;
88
/// </remarks>
99
/// <param name="name">The name of the resource.</param>
1010
/// <param name="workingDirectory">The working directory for the resource.</param>
11+
[Obsolete(
12+
message: "The SWA emulator integration is going to be removed in a future release.",
13+
error: false,
14+
DiagnosticId = "CTASPIRE003",
15+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
1116
public class SwaResource(string name, string workingDirectory) : ExecutableResource(name, "swa", workingDirectory)
1217
{
1318
}

src/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps/SwaResourceOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ namespace Aspire.Hosting;
33
/// <summary>
44
/// Represents the configuration options for a Static Web App resource.
55
/// </summary>
6+
[Obsolete(
7+
message: "The SWA emulator integration is going to be removed in a future release.",
8+
error: false,
9+
DiagnosticId = "CTASPIRE003",
10+
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
611
public class SwaResourceOptions
712
{
813
/// <summary>

tests/CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests/ResourceCreationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma warning disable CTASPIRE003
12
using Aspire.Hosting;
23

34
namespace CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests;

0 commit comments

Comments
 (0)