testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Unhelpful stack traces for async functions with multiple async calls

Open benlind opened this issue 3 years ago • 12 comments

What is your Test Scenario?

I have a test block that calls an async helper function. That helper function makes more than one async assertion. If any of those sub-assertions fail except for the first assertion, the error stack trace unhelpfully only lists the helper function and doesn't mention the line in the original test block where the helper function was called.

Since we use helper functions in multiple tests, this leaves us with no easy way to determine which helper invocation led to a logged error.

Here is a simple reproduction:

fixture`Example`

test
  .page('https://google.com')('loads Google', async t => {
    await myHelper(t)
  })

async function myHelper (t) {
  await t.expect(null).eql(null)     // assertion 1
  await t.expect(null).notEql(null)  // assertion 2
}

What is the Current behavior?

When myHelper fails at assertion 2, the stack trace looks like this:

   5 |    await myHelper(t)
   6 |  })
   7 |
   8 |async function myHelper (t) {
   9 |  await t.expect(null).eql(null)     // assertion 1
> 10 |  await t.expect(null).notEql(null)  // assertion 2
  11 |}

at <anonymous> (foo.spec.js:10:24)
at asyncGeneratorStep (foo.spec.js:1:114)
at _next (foo.spec.js:1:452)

This lists the correct line in the helper function where the assertion failed, but it then just lists the first line in the file instead of indicating where in the original test block the helper was called.

However, if I flip assertion 1 and 2, then the stack trace is more helpful:

   4 |  .page('https://google.com')('loads Google', async t => {
   5 |    await myHelper(t)
   6 |  })
   7 |
   8 |async function myHelper (t) {
>  9 |  await t.expect(null).notEql(null)  // assertion 2
  10 |  await t.expect(null).eql(null)     // assertion 1
  11 |}
  12 |

 at <anonymous> (foo.spec.js:9:24)
 at asyncGeneratorStep (foo.spec.js:1:114)
 at _next (foo.spec.js:1:452)
 at <anonymous> (foo.spec.js:1:617)
 at <anonymous> (foo.spec.js:1:358)
 at _myHelper (foo.spec.js:46:153)
 at myHelper (foo.spec.js:8:33)
 at <anonymous> (foo.spec.js:5:11)
 at asyncGeneratorStep (foo.spec.js:1:114)
 at _next (foo.spec.js:1:452)

The at <anonymous> (foo.spec.js:5:11) line correctly points to the line in the test block where myHelper is called.

What is the Expected behavior?

TestCafe should output the full, helpful stack trace from the second example output above even when it is not the first assertion that fails in the helper.

  • testcafe version: 1.12.0
  • node.js version: 14.15.5
  • command-line arguments: testcafe chrome -L
  • browser name and version: Chrome 89.0.4389.90
  • platform and version: macOS 10.14.6

benlind avatar Mar 19 '21 22:03 benlind

Such a stack trace is caused by Babel preprocessing. We'll look into it.

SergeyShurygin avatar Mar 22 '21 08:03 SergeyShurygin

I have this same issue. Trying to divide common test code into utility classes results in a stack trace that doesn't tell you anything about where the error started, only where it happened in the utility class.

Asuza avatar Sep 02 '21 16:09 Asuza

Is it possible to raise the priority on this? At the very least, if it's possible to identify this problem and print a link back to this issue, that would've saved me hours of research. I thought it was a node flag I needed to set.

DanKaplanSES avatar Sep 07 '22 01:09 DanKaplanSES

I think I found a workaround to this issue.

  1. Install https://www.npmjs.com/package/trace
  2. Run testcafe like this in your package.json scripts: npx --node-options='--stack_trace_limit=100 -r trace' testcafe ...

Note: I got errors on different lines when I included clarify, so I recommend not using it.


Update: Actually this is a workaround that sometimes works, but I recommend only using it temporarily. While this did give me a stack trace I could use to troubleshoot, it caused other tests to fail until I removed npx --node-options='--stack_trace_limit=100 -r trace' In other words, this tool can introduce breaking changes, so this is a poor workaround.

DanKaplanSES avatar Sep 07 '22 01:09 DanKaplanSES

Hi @DanKaplanSES,

Thank you for the workaround.

Aleksey28 avatar Sep 08 '22 07:09 Aleksey28

@Aleksey28 No problem. Are there any updates about this issue? It can make life very difficult when you attempt to reuse test code.

DanKaplanSES avatar Dec 08 '22 21:12 DanKaplanSES

We don't have any updates yet. We'll update this thread once we have any results.

Aleksey28 avatar Dec 12 '22 07:12 Aleksey28

Bumping. Is this still an issue?

DanKaplanSES avatar May 02 '23 19:05 DanKaplanSES

No updates yet. Once we get any results, we will post them in this thread.

github-actions[bot] avatar May 04 '23 13:05 github-actions[bot]

Hello @DanKaplanSES ,

We understand the difficulties users may have with an async stack, but this is a low priority issue at the moment. We may reprioritize it in the future or if the number of requests for this feature grows

aleks-pro avatar May 05 '23 06:05 aleks-pro

We also urgently need this fixed.

Dvoreth avatar Oct 18 '23 13:10 Dvoreth

@Dvoreth This issue has low priority so we do not have plans to start working on this in near future.

AlexKamaev avatar Oct 19 '23 07:10 AlexKamaev

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

github-actions[bot] avatar Apr 17 '24 01:04 github-actions[bot]

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

github-actions[bot] avatar Apr 28 '24 01:04 github-actions[bot]

This still affects me and I would like it to be reopened.

DanKaplanSES avatar May 05 '24 04:05 DanKaplanSES

Hello,

Unfortunately, it is currently difficult to determine the cause of this issue.

In addition, it has a low priority, so we do not have plans to start working on this issue in the near future.

We can reopen it if things change and the issue becomes a higher priority.

Bayheck avatar May 08 '24 08:05 Bayheck