Skip to content

Commit bc1f420

Browse files
committed
Continue printing out redirected process output after we detect browser launch URL.
1 parent 4fb94f2 commit bc1f420

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ 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+
2528
// Verify we launched the browser.
26-
await App.AssertOutputLineStartsWith("dotnet watch ⌚ Launching browser: https://localhost:5001/");
29+
Assert.Contains(App.Process.Output, line => line.Contains("Launching browser: https://localhost:5001/"));
2730
}
2831

2932
[Fact]

0 commit comments

Comments
 (0)