-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Dev exception notifications #14636
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
Merged
Merged
Dev exception notifications #14636
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2a774c5
Blazor dev exception notification
ryanbrandenburg e22b5e4
Clean up and presentation
ryanbrandenburg 8b78ccb
Blazor Client-side
ryanbrandenburg fae461a
PR feedback
ryanbrandenburg 7792bb9
Adding tests
ryanbrandenburg 20311a2
Cleanup
ryanbrandenburg 9e3eb33
PR feedback and some test fixes
ryanbrandenburg 3af9a2f
PR feedback
ryanbrandenburg 37363e5
Rebuild js files
ryanbrandenburg 2d63526
PR feedback
ryanbrandenburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
let hasFailed = false; | ||
|
||
export async function showErrorNotification() { | ||
let errorUi = document.querySelector('#error-ui') as HTMLElement; | ||
if (errorUi) { | ||
errorUi.style.display = 'block'; | ||
} | ||
|
||
if (!hasFailed) { | ||
hasFailed = true; | ||
const errorUiReloads = document.querySelectorAll<HTMLElement>('#error-ui .reload'); | ||
errorUiReloads.forEach(reload => { | ||
reload.onclick = function (e) { | ||
location.reload(); | ||
e.preventDefault(); | ||
}; | ||
}); | ||
|
||
let errorUiDismiss = document.querySelectorAll<HTMLElement>('#error-ui .dismiss'); | ||
errorUiDismiss.forEach(dismiss => { | ||
dismiss.onclick = function (e) { | ||
const errorUi = document.querySelector<HTMLElement>('#error-ui'); | ||
if (errorUi) { | ||
errorUi.style.display = 'none'; | ||
} | ||
e.preventDefault(); | ||
}; | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Components/test/E2ETest/Tests/ErrorNotificationClientSideTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using BasicTestApp; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
using Microsoft.AspNetCore.E2ETesting; | ||
using OpenQA.Selenium; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Tests | ||
{ | ||
[Collection("ErrorNotification")] // When the clientside and serverside tests run together it seems to cause failures, possibly due to connection lose on exception. | ||
public class ErrorNotificationClientSideTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>> | ||
ryanbrandenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public ErrorNotificationClientSideTest( | ||
BrowserFixture browserFixture, | ||
ToggleExecutionModeServerFixture<Program> serverFixture, | ||
ITestOutputHelper output) | ||
: base(browserFixture, serverFixture, output) | ||
{ | ||
} | ||
|
||
protected override void InitializeAsyncCore() | ||
{ | ||
// On WebAssembly, page reloads are expensive so skip if possible | ||
Navigate(ServerPathBase, noReload: _serverFixture.ExecutionMode == ExecutionMode.Client); | ||
Browser.MountTestComponent<ErrorComponent>(); | ||
Browser.Exists(By.Id("error-ui")); | ||
Browser.Exists(By.TagName("button")); | ||
} | ||
|
||
[Fact] | ||
public void ShowsErrorNotification_OnError_Dismiss() | ||
{ | ||
var errorUi = Browser.FindElement(By.Id("error-ui")); | ||
Assert.Equal("none", errorUi.GetCssValue("display")); | ||
|
||
var causeErrorButton = Browser.FindElement(By.TagName("button")); | ||
causeErrorButton.Click(); | ||
|
||
Browser.Exists(By.CssSelector("#error-ui[style='display: block;']"), TimeSpan.FromSeconds(10)); | ||
|
||
var reload = Browser.FindElement(By.ClassName("reload")); | ||
reload.Click(); | ||
|
||
Browser.DoesNotExist(By.TagName("button")); | ||
} | ||
|
||
[Fact] | ||
public void ShowsErrorNotification_OnError_Reload() | ||
{ | ||
var causeErrorButton = Browser.Exists(By.TagName("button")); | ||
var errorUi = Browser.FindElement(By.Id("error-ui")); | ||
Assert.Equal("none", errorUi.GetCssValue("display")); | ||
|
||
causeErrorButton.Click(); | ||
Browser.Exists(By.CssSelector("#error-ui[style='display: block;']")); | ||
|
||
var dismiss = Browser.FindElement(By.ClassName("dismiss")); | ||
dismiss.Click(); | ||
Browser.Exists(By.CssSelector("#error-ui[style='display: none;']")); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Components/test/E2ETest/Tests/ErrorNotificationServerSideTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using BasicTestApp; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
using Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests; | ||
using Microsoft.AspNetCore.E2ETesting; | ||
using OpenQA.Selenium; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Tests | ||
{ | ||
[Collection("ErrorNotification")] // When the clientside and serverside tests run together it seems to cause failures, possibly due to connection lose on exception. | ||
public class ErrorNotificationServerSideTest : ErrorNotificationClientSideTest | ||
{ | ||
public ErrorNotificationServerSideTest( | ||
BrowserFixture browserFixture, | ||
ToggleExecutionModeServerFixture<Program> serverFixture, | ||
ITestOutputHelper output) | ||
: base(browserFixture, serverFixture.WithServerExecution(), output) | ||
{ | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Components/test/testassets/BasicTestApp/ErrorComponent.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div> | ||
<h2>Error throwing button</h2> | ||
<p> | ||
<button @onclick="@(IncrementCount)">Click me</button> | ||
</p> | ||
</div> | ||
|
||
@code { | ||
int currentCount = 0; | ||
|
||
void IncrementCount() | ||
{ | ||
currentCount++; | ||
throw new NotImplementedException("Doing crazy things!"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.