Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset logging between requests #1288

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,4 @@ UpgradeLog*.htm

# Microsoft Fakes
FakesAssemblies/
src/.idea
2 changes: 1 addition & 1 deletion src/React.Core/ReactEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public virtual void GetInitJavaScript(TextWriter writer, bool clientOnly = false
// Propagate any server-side console.log calls to corresponding client-side calls.
if (!clientOnly && _components.Count != 0)
{
var consoleCalls = Execute<string>("console.getCalls()");
var consoleCalls = Execute<string>("console.drainCalls()");
writer.Write(consoleCalls);
}

Expand Down
6 changes: 4 additions & 2 deletions src/React.Core/Resources/shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ MockConsole.prototype = {
_formatCall: function(call) {
return 'console.' + call.method + '("[.NET]", ' + call.args.join(', ') + ', ' + JSON.stringify(call.stack) + ');';
},
getCalls: function() {
return this._calls.map(this._formatCall).join('\n');
drainCalls: function() {
var calls = this._calls.map(this._formatCall).join('\n');
this._calls = [];
return calls;
}
};
var console = new MockConsole();
Expand Down
2 changes: 1 addition & 1 deletion tests/React.Tests/Core/ReactEnvironmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void SSRInitSkippedIfNoComponents(bool renderComponent, int ssrTimes)

environment.GetInitJavaScript();

mocks.Engine.Verify(x => x.Evaluate<string>("console.getCalls()"), Times.Exactly(ssrTimes));
mocks.Engine.Verify(x => x.Evaluate<string>("console.drainCalls()"), Times.Exactly(ssrTimes));
}

[Fact]
Expand Down