Skip to content

Commit a8e91e9

Browse files
authored
Continue printing out redirected process output after we detect browser launch URL. (#44290)
2 parents d053894 + ca04700 commit a8e91e9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,27 @@ public bool TryGetRefreshServer(ProjectGraphNode projectNode, [NotNullWhen(true)
112112
return null;
113113
}
114114

115+
bool matchFound = false;
116+
115117
return handler;
116118

117119
void handler(object sender, DataReceivedEventArgs eventArgs)
118120
{
119121
// We've redirected the output, but want to ensure that it continues to appear in the user's console.
120122
Console.WriteLine(eventArgs.Data);
121123

124+
if (matchFound)
125+
{
126+
return;
127+
}
128+
122129
var match = s_nowListeningRegex.Match(eventArgs.Data ?? "");
123130
if (!match.Success)
124131
{
125132
return;
126133
}
127134

128-
((Process)sender).OutputDataReceived -= handler;
135+
matchFound = true;
129136

130137
var projectAddedToAttemptedSet = ImmutableInterlocked.Update(ref _browserLaunchAttempted, static (set, projectNode) => set.Add(projectNode), projectNode);
131138
if (projectAddedToAttemptedSet)

test/dotnet-watch.Tests/Watch/BrowserLaunchTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ public async Task LaunchesBrowserOnStart()
2222

2323
App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);
2424

25+
// check that all app output is printed out:
26+
await App.AssertOutputLine(line => line.Contains("Content root path:"));
27+
28+
Assert.Contains(App.Process.Output, line => line.Contains("Application started. Press Ctrl+C to shut down."));
29+
Assert.Contains(App.Process.Output, line => line.Contains("Hosting environment: Development"));
30+
2531
// Verify we launched the browser.
26-
await App.AssertOutputLineStartsWith("dotnet watch ⌚ Launching browser: https://localhost:5001/");
32+
Assert.Contains(App.Process.Output, line => line.Contains("dotnet watch ⌚ Launching browser: https://localhost:5001/"));
2733
}
2834

2935
[Fact]

0 commit comments

Comments
 (0)