Testcafe stacktrace is incomplete and missing reference to calling test
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 helperutil/verifyPageContent.ts- Level 2: Middle helperutil/checkElementText.ts- Level 3: Deepest helper (performs assertion)
Test File (nested-test.spec.ts) contains 4 tests with different nesting levels:
- 3 levels -
validateContent()→verifyPageContent()→checkElementText() - 2 levels -
verifyPageContent()→checkElementText() - 1 level -
checkElementText() - 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
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
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".
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.
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.
Would you accept a PR for this topic?
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.