question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

E2E tests ignore javascript errors

See original GitHub issue

If a javascript error occurs during execution of an E2E test, it’s ignored and not surfaced to the console or logs. If it causes an assertion to fail (due to missing content, etc) the test will “fail” but you will have no way to see that the JS error caused it. If the assertions pass, everything looks good which is a really bad outcome.

I think chromedriver probably has a way to get logged errors, but if not the E2E tests should register an unhandled error handler on the window so they can propagate this out somehow (maybe into a hidden dom element that the test runner checks at the end).

An easy way to reproduce this is to shove a setTimeout that throws an error somewhere in the blazor code (this sample code is from a blazor bug I’m troubleshooting), like:

  private insertText(batch: RenderBatch, parent: LogicalElement, childIndex: number, textFrame: RenderTreeFrame) {
    let textContent = batch.frameReader.textContent(textFrame)!;
    if (typeof (textContent) !== "string") {
      textContent = "";
      window.setTimeout(() => {
        throw new Error(`Found non-string in batch text content with parent ${parent}`);
      }, 1);
    }
    const newTextNode = document.createTextNode(textContent);
    insertLogicalChild(newTextNode, parent, childIndex);
  }

This will produce an error in the browser console, but the test will not fail or dump the error to stdout/stderr, even if you sleep before your assertions to give time for the error to fire. If you turn the setTimeout into a regular throw, the test will fail. image

image

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, May 10, 2022

@kg we pipe this to the ITestOutput (or whatever is called) from xUnit. At the very least it shows up in Visual Studio.

1reaction
TanayParikhcommented, Oct 11, 2022

we normally don’t check for errors on the console to drive the outcome of tests

and in the rare cases that we do need the console output, it’s done as per below:

https://github.com/dotnet/aspnetcore/blob/7259991b5d2ecef36979fd55e48884de8d69f114/src/Components/test/E2ETest/ServerExecutionTests/ServerReconnectionTest.cs#L81-L82

Read more comments on GitHub >

github_iconTop Results From Across the Web

Skip JavaScript Errors | Debugging | Recipes
TestCafe tests fail when a page yields a JavaScript error. If you enable the skipJsErrors option, TestCafe deliberately ignores JavaScript errors and lets...
Read more >
How to ignore errors beyond your control with TestCafe
TestCafe tests fail if JS errors occur, which any other time is a sensible feature. We could run the tests with the --skip-js-errors...
Read more >
Raising JavaScript errors in Ruby E2E tests (RSpec ...
Ignoring errors. You can ignore errors by their exact message: BrowserConsole.ignore('Browser is burning').
Read more >
Detect JavaScript errors on client using annotation with ...
Motivation: In our E2E tests we want to track client noises in the form of javascript errors received during the user session.
Read more >
Exception Handling In Cypress: A Comprehensive Guide
This tutorial post dives deep into the concept of exception handling in Cypress for identifying and addressing errors during test execution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found