jestjs/jest

The original function name gets lost in the Jest error stack

Open

#10,633 建立於 2020年10月13日

在 GitHub 查看
 (18 留言) (0 反應) (0 負責人)TypeScript (6,653 fork)batch import
:bug: BugConfirmedHelp WantedPinned

倉庫指標

Star
 (45,361 star)
PR 合併指標
 (平均合併 11天 22小時) (30 天內合併 11 個 PR)

描述

test('hello world', () => {
 function BadCode() {
    throw new Error('noo')
  }

  function run(fn) {
    fn()
  }

  run(BadCode)
});

I expect to see BadCode in the stack because it's a named function. But it shows up as fn instead:

      at fn (sum.test.js:3:11)
      at run (sum.test.js:7:5)
      at Object.<anonymous> (sum.test.js:10:3)

Same with error.stack property.

Isn't this just a Node issue?

Nope, try it in Node REPL and see BadCode:

Uncaught Error: noo
    at BadCode (repl:2:11)
    at run (repl:2:5)

Also works correctly in Chrome.

I've done both locally so I used the same Node version (12.18.3). So it's Jest-specific.

I can also reproduce this on Repl.it: https://repl.it/repls/SecondaryItchyGui

I've tried vm.runInContext locally but that did not trigger the issue. I also verified I'm not transpiling anything. So I have no idea what is the cause of this. The underlying bug is probably in Node or V8 but we need to figure out what is special about Jest that is triggering it.

Why fix this?

This affects the new React component stack printing strategy so it would be unfortunate for this to stay unfixed very long.

貢獻者指南