Skip to content

Commit 389f3bb

Browse files
committed
Launching browser message
1 parent 0aea834 commit 389f3bb

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

src/BuiltInTools/dotnet-watch/Browser/BrowserLauncher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private void LaunchBrowser(string launchUrl, BrowserRefreshServer? server)
7070
fileName = browserPath;
7171
}
7272

73-
logger.LogDebug("Launching browser: {FileName} {Args}", fileName, args);
73+
logger.Log(MessageDescriptor.LaunchingBrowser, fileName, args);
7474

7575
if (environmentOptions.TestFlags != TestFlags.None)
7676
{
Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Microsoft.DotNet.Watch.UnitTests
4+
namespace Microsoft.DotNet.Watch.UnitTests;
5+
6+
public class BrowserLaunchTests(ITestOutputHelper logger) : DotNetWatchTestBase(logger)
57
{
6-
public class BrowserLaunchTests : DotNetWatchTestBase
8+
[Fact]
9+
public async Task LaunchesBrowserOnStart()
710
{
8-
private const string AppName = "WatchBrowserLaunchApp";
9-
10-
public BrowserLaunchTests(ITestOutputHelper logger)
11-
: base(logger)
12-
{
13-
}
14-
15-
[Fact]
16-
public async Task LaunchesBrowserOnStart()
17-
{
18-
var testAsset = TestAssets.CopyTestAsset(AppName)
19-
.WithSource();
11+
var testAsset = TestAssets.CopyTestAsset("WatchBrowserLaunchApp")
12+
.WithSource();
2013

21-
App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);
14+
App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);
2215

23-
// check that all app output is printed out:
24-
await App.WaitForOutputLineContaining("Content root path:");
16+
// check that all app output is printed out:
17+
await App.WaitForOutputLineContaining("Content root path:");
2518

26-
Assert.Contains(App.Process.Output, line => line.Contains("Application started. Press Ctrl+C to shut down."));
27-
Assert.Contains(App.Process.Output, line => line.Contains("Hosting environment: Development"));
19+
Assert.Contains(App.Process.Output, line => line.Contains("Application started. Press Ctrl+C to shut down."));
20+
Assert.Contains(App.Process.Output, line => line.Contains("Hosting environment: Development"));
2821

29-
// Verify we launched the browser.
30-
Assert.Contains(App.Process.Output, line => line.Contains("dotnet watch ⌚ Launching browser: https://localhost:5001"));
31-
}
22+
// Verify we launched the browser.
23+
App.AssertOutputContains(MessageDescriptor.LaunchingBrowser.GetMessage("https://localhost:5001", ""));
24+
}
3225

33-
[Fact]
34-
public async Task UsesBrowserSpecifiedInEnvironment()
35-
{
36-
var testAsset = TestAssets.CopyTestAsset(AppName)
37-
.WithSource();
26+
[Fact]
27+
public async Task UsesBrowserSpecifiedInEnvironment()
28+
{
29+
var testAsset = TestAssets.CopyTestAsset("WatchBrowserLaunchApp")
30+
.WithSource();
3831

39-
App.EnvironmentVariables.Add("DOTNET_WATCH_BROWSER_PATH", "mycustombrowser.bat");
32+
App.EnvironmentVariables.Add("DOTNET_WATCH_BROWSER_PATH", "mycustombrowser.bat");
4033

41-
App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);
42-
await App.WaitForOutputLineContaining(MessageDescriptor.ConfiguredToUseBrowserRefresh);
43-
await App.WaitForOutputLineContaining(MessageDescriptor.ConfiguredToLaunchBrowser);
34+
App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);
35+
await App.WaitForOutputLineContaining(MessageDescriptor.ConfiguredToUseBrowserRefresh);
36+
await App.WaitForOutputLineContaining(MessageDescriptor.ConfiguredToLaunchBrowser);
4437

45-
// Verify we launched the browser.
46-
await App.AssertOutputLineStartsWith("dotnet watch ⌚ Launching browser: mycustombrowser.bat https://localhost:5001");
47-
}
38+
// Verify we launched the browser.
39+
await App.WaitForOutputLineContaining(MessageDescriptor.LaunchingBrowser.GetMessage("mycustombrowser.bat", "https://localhost:5001"));
4840
}
4941
}

test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ public async Task BlazorWasm(bool projectSpecifiesCapabilities)
777777
App.AssertOutputContains(MessageDescriptor.ConfiguredToLaunchBrowser);
778778

779779
// Browser is launched based on blazor-devserver output "Now listening on: ...".
780-
await App.WaitUntilOutputContains($"dotnet watch ⌚ Launching browser: http://localhost:{port}");
780+
await App.WaitUntilOutputContains(MessageDescriptor.LaunchingBrowser.GetMessage($"http://localhost:{port}", ""));
781781

782782
// Middleware should have been loaded to blazor-devserver before the browser is launched:
783783
App.AssertOutputContains("dbug: Microsoft.AspNetCore.Watch.BrowserRefresh.BlazorWasmHotReloadMiddleware[0]");
@@ -847,7 +847,7 @@ public async Task BlazorWasm_Restart()
847847
App.AssertOutputContains(MessageDescriptor.PressCtrlRToRestart);
848848

849849
// Browser is launched based on blazor-devserver output "Now listening on: ...".
850-
await App.WaitUntilOutputContains($"dotnet watch ⌚ Launching browser: http://localhost:{port}");
850+
await App.WaitUntilOutputContains(MessageDescriptor.LaunchingBrowser.GetMessage($"http://localhost:{port}", ""));
851851

852852
App.SendControlR();
853853

@@ -891,7 +891,7 @@ public async Task Razor_Component_ScopedCssAndStaticAssets()
891891

892892
App.AssertOutputContains(MessageDescriptor.ConfiguredToUseBrowserRefresh);
893893
App.AssertOutputContains(MessageDescriptor.ConfiguredToLaunchBrowser);
894-
App.AssertOutputContains($"dotnet watch ⌚ Launching browser: http://localhost:{port}");
894+
App.AssertOutputContains(MessageDescriptor.LaunchingBrowser.GetMessage($"http://localhost:{port}", ""));
895895
App.Process.ClearOutput();
896896

897897
var scopedCssPath = Path.Combine(testAsset.Path, "RazorClassLibrary", "Components", "Example.razor.css");

0 commit comments

Comments
 (0)