Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Aug 6, 2024
1 parent 40c02d5 commit 70294a3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/Aspire.Hosting.NodeJs.Tests/NodeAppFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Testing;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
Expand All @@ -17,6 +16,7 @@ namespace Aspire.Hosting.NodeJs.Tests;
/// </summary>
public class NodeAppFixture(IMessageSink diagnosticMessageSink) : IAsyncLifetime
{
private TestDistributedApplicationBuilder? _builder;
private DistributedApplication? _app;
private string? _nodeAppPath;

Expand All @@ -27,29 +27,31 @@ public class NodeAppFixture(IMessageSink diagnosticMessageSink) : IAsyncLifetime

public async Task InitializeAsync()
{
var builder = TestDistributedApplicationBuilder.Create();
builder.Services.AddXunitLogging(new TestOutputWrapper(diagnosticMessageSink));
_builder = TestDistributedApplicationBuilder.Create()
.WithTestAndResourceLogging(new TestOutputWrapper(diagnosticMessageSink));

_nodeAppPath = CreateNodeApp();
var scriptPath = Path.Combine(_nodeAppPath, "app.js");

NodeAppBuilder = builder.AddNodeApp("nodeapp", scriptPath)
NodeAppBuilder = _builder.AddNodeApp("nodeapp", scriptPath)
.WithHttpEndpoint(port: 5031, env: "PORT");

NpmAppBuilder = builder.AddNpmApp("npmapp", _nodeAppPath)
NpmAppBuilder = _builder.AddNpmApp("npmapp", _nodeAppPath)
.WithHttpEndpoint(port: 5032, env: "PORT");

_app = builder.Build();
_app = _builder.Build();

using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));

await _app.StartAsync(cts.Token);

await WaitReadyStateAsync(cts.Token);
await WaitReadyStateAsync(cts.Token);
}

public async Task DisposeAsync()
{
_builder?.Dispose();

if (_app is not null)
{
await _app.StopAsync();
Expand All @@ -58,7 +60,14 @@ public async Task DisposeAsync()

if (_nodeAppPath is not null)
{
Directory.Delete(_nodeAppPath, recursive: true);
try
{
Directory.Delete(_nodeAppPath, recursive: true);
}
catch
{
// Don't fail test if we can't clean the temporary folder
}
}
}

Expand Down

0 comments on commit 70294a3

Please sign in to comment.