| File: TypeScriptStarterTemplateTests.cs | Web Access |
| Project: src\tests\Aspire.Cli.EndToEnd.Tests\Aspire.Cli.EndToEnd.Tests.csproj (Aspire.Cli.EndToEnd.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.Cli.EndToEnd.Tests.Helpers; using Hex1b.Automation; using Xunit; namespace Aspire.Cli.EndToEnd.Tests; /// <summary> /// End-to-end tests for the TypeScript Express/React starter template (aspire-ts-starter). /// Validates that aspire new creates a working Express API + React frontend project /// and that aspire run starts it successfully. /// </summary> public sealed class TypeScriptStarterTemplateTests(ITestOutputHelper output) { [CaptureWorkspaceOnFailure] [Fact] public async Task CreateAndRunTypeScriptStarterProject() { var repoRoot = CliE2ETestHelpers.GetRepoRoot(); var strategy = CliInstallStrategy.Detect(output.WriteLine); var workspace = TemporaryWorkspace.Create(output); using var terminal = CliE2ETestHelpers.CreateDockerTestTerminal(repoRoot, strategy, output, mountDockerSocket: true, workspace: workspace); var counter = new SequenceCounter(); var auto = new Hex1bTerminalAutomator(terminal, defaultTimeout: TimeSpan.FromSeconds(500)); await using var terminalRun = CliE2ETestHelpers.StartRun(terminal, workspace, auto, counter, output, TestContext.Current.CancellationToken); await auto.PrepareDockerEnvironmentAsync(counter, workspace); await auto.InstallAspireCliAsync(strategy, counter); // Step 1: Create project using aspire new, selecting the Express/React template await auto.AspireNewAsync("TsStarterApp", counter, template: AspireTemplate.ExpressReact); // Step 1.5: Verify starter creation also restored the generated TypeScript SDK. var projectRoot = Path.Combine(workspace.WorkspaceRoot.FullName, "TsStarterApp"); GitIgnoreAssertions.AssertContainsEntry(projectRoot, ".aspire/"); var modulesDir = Path.Combine(projectRoot, ".aspire/modules"); if (!Directory.Exists(modulesDir)) { throw new InvalidOperationException($".aspire/modules directory was not created at {modulesDir}"); } var aspireModulePath = Path.Combine(modulesDir, "aspire.mts"); if (!File.Exists(aspireModulePath)) { throw new InvalidOperationException($"Expected generated file not found: {aspireModulePath}"); } // Step 2: Navigate into the project and start it await auto.TypeAsync("cd TsStarterApp"); await auto.EnterAsync(); await auto.WaitForSuccessPromptAsync(counter); await auto.RunCommandAsync("npm run build", counter, TimeSpan.FromMinutes(2)); await auto.AspireStartAsync(counter); await auto.AspireStopAsync(counter); } }