| File: IntegrationTests.cs | Web Access |
| Project: src\tests\Aspire.Hosting.JavaScript.Tests\Aspire.Hosting.JavaScript.Tests.csproj (Aspire.Hosting.JavaScript.Tests) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Aspire.Hosting.ApplicationModel; using Microsoft.Extensions.DependencyInjection; namespace Aspire.Hosting.JavaScript.Tests; /// <summary> /// Integration test that demonstrates the new resource-based package installer architecture. /// This shows how installer resources appear as separate resources in the application model. /// </summary> public class IntegrationTests { [Fact] public void ResourceBasedPackageInstallersAppearInApplicationModel() { var builder = DistributedApplication.CreateBuilder(); // Add a vite app with the npm package manager builder.AddViteApp("vite-app", "./frontend") .WithNpm(install: true); using var app = builder.Build(); var appModel = app.Services.GetRequiredService<DistributedApplicationModel>(); // Verify all Node.js app resources are present var nodeResources = appModel.Resources.OfType<JavaScriptAppResource>().ToList(); Assert.Single(nodeResources); // Verify all installer resources are present as separate resources var npmInstallers = appModel.Resources.OfType<JavaScriptInstallerResource>().ToList(); Assert.Single(npmInstallers); // Verify installer resources have expected names (would appear on dashboard) Assert.Equal("vite-app-installer", npmInstallers[0].Name); // Verify parent-child relationships foreach (var installer in npmInstallers.Cast<IResource>()) { Assert.True(installer.TryGetAnnotationsOfType<ResourceRelationshipAnnotation>(out var relationships)); Assert.Single(relationships); Assert.Equal("Parent", relationships.First().Type); } // Verify all Node.js apps wait for their installers foreach (var nodeApp in nodeResources) { Assert.True(nodeApp.TryGetAnnotationsOfType<WaitAnnotation>(out var waitAnnotations)); Assert.Single(waitAnnotations); var waitedResource = waitAnnotations.First().Resource; Assert.True(waitedResource is JavaScriptInstallerResource); } } [Fact] public void InstallerResourcesHaveCorrectExecutableConfiguration() { var builder = DistributedApplication.CreateBuilder(); builder.AddJavaScriptApp("test-app", "./test") .WithNpm(install: true); using var app = builder.Build(); var appModel = app.Services.GetRequiredService<DistributedApplicationModel>(); var installer = Assert.Single(appModel.Resources.OfType<JavaScriptInstallerResource>()); // Verify it's configured as an ExecutableResource Assert.IsAssignableFrom<ExecutableResource>(installer); // Verify working directory matches parent var parentApp = Assert.Single(appModel.Resources.OfType<JavaScriptAppResource>()); Assert.Equal(parentApp.WorkingDirectory, installer.WorkingDirectory); // Verify parent-child relationship exists Assert.True(installer.TryGetAnnotationsOfType<ResourceRelationshipAnnotation>(out var relationships)); var relationship = Assert.Single(relationships); Assert.Same(parentApp, relationship.Resource); Assert.Equal("Parent", relationship.Type); } }