testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Testcafe stacktrace is incomplete and missing reference to calling test

Open AriAy-Ded opened this issue 2 months ago • 5 comments

What is your Scenario?

When using nested helper functions (3+ levels deep), TestCafe omits some function calls from the error stacktrace, making debugging difficult.

What is the Current behavior?

Test Structure

Helper Functions (in separate files under util/):

  • util/validateContent.ts - Level 1: Top-level helper
  • util/verifyPageContent.ts - Level 2: Middle helper
  • util/checkElementText.ts - Level 3: Deepest helper (performs assertion)

Test File (nested-test.spec.ts) contains 4 tests with different nesting levels:

  1. 3 levels - validateContent()verifyPageContent()checkElementText()
  2. 2 levels - verifyPageContent()checkElementText()
  3. 1 level - checkElementText()
  4. Direct assertion - No helper functions (baseline)

All tests are designed to fail to demonstrate stacktrace behavior.

The Bug

3 Levels of Nesting

Stacktrace ends at:

at checkElementText (util/checkElementText.ts:16:12)
at verifyPageContent (util/verifyPageContent.ts:16:12)
at validateContent (util/validateContent.ts:8:71)

❌ NO REFERENCE to nested-test.spec.ts - The stacktrace stops at the deepest helper file and never shows where in the test file the call originated!

What is the Expected behavior?

at (nested-test.spec.ts:17:28) ← Test file IS shown!

What is your TestCafe test code?

https://github.com/aayvazyan-tgm/testcafe-stacktrace-bug

Your complete test report

https://github.com/aayvazyan-tgm/testcafe-stacktrace-bug/blob/main/execution-log.md

Steps to Reproduce

npx testcafe "chrome:headless --disable-features=LocalNetworkAccess --no-sandbox" nested-test.spec.ts

TestCafe version

3.7.2

Node.js version

v22.20.0

Command-line arguments

npx testcafe "chrome:headless --disable-features=LocalNetworkAccess --no-sandbox" nested-test.spec.ts

AriAy-Ded avatar Oct 13 '25 12:10 AriAy-Ded

Hello @AriAy-Ded ,

Thank you for the detailed example. I was able to reproduce the problematic behavior.

The root cause of it is that we use Babel to support modern JavaScript features on older Node.js versions. Babel transpiles the code in a way that prevents Node.js from preserving stack traces for asynchronous calls.

We are considering discontinuing support for several outdated Node.js versions that are no longer maintained, and removing Babel in the future. Since this behavior is currently the default in TestCafe, I will change the issue type from "bug" to "enhancement".

aleks-pro avatar Oct 17 '25 15:10 aleks-pro

This is also something that I regularly noticed, I thought it was default behaviour. I am using node v23.6.1 with JS tests, calling various functions that are nested in helpers/page models. Often, there only is a stack trace linking to the model/helper file, without showing the test file that does the initial call.

di5ko avatar Oct 21 '25 06:10 di5ko

Hi @aleks-pro please reconsider the priority of this. Omitting stacktraces makes it impossible to navigate errors in a complex project with unstable tests that are only showing up on the CI. Investigating these issues often requires turning on internal testcafe logging, and educated guessing. This is an extreme pain point.

If no fix is provided, please consider creating a workaround or giving us the tools to create a workaround.

AriAy-Ded avatar Oct 22 '25 14:10 AriAy-Ded

Would you accept a PR for this topic?

AriAy-Ded avatar Oct 22 '25 14:10 AriAy-Ded

Would you accept a PR for this topic?

We will review a PR and merge it if everything is fine. Please note that this change affects the core part of TestCafe and may impact almost all existing usage scenarios. Therefore, it requires additional resources not only to implement it but also to thoroughly test and verify that it doesn’t introduce any regressions or breaking changes.

aleks-pro avatar Oct 24 '25 08:10 aleks-pro