mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.64k stars 3.02k forks source link

🐛 Bug: Errors messages and stack traces from JSDOM loaded scripts are not useful #1757

Closed mjhm closed 10 months ago

mjhm commented 9 years ago

I put up a test case repo at https://github.com/mjhm/mocha_jsdom_test

As mentioned in the README the repo shows a change in handling jsdom stack traces.

The problem is that for mocha@2.2.X the handling of stack traces has changed so that stack traces of JSDOM loaded scripts are no longer useful.

In particular the report of last test using mocha@2.1.0 is

6) Basic Test with beforeEach jsdom setup throws a jsdom browser error from preloaded file.:
     Error: globalThrower
      at window.browserThrower (file:///Users/johnmclaughlin/git/mocha_jsdom_test/browserThrower.js:5:9)

But the result for mocha@2.2.5 is not useful for tracking down the source of the error:

6) Basic Test with beforeEach jsdom setup throws a jsdom browser error from preloaded file.:
   Error: the error {} was thrown, throw an Error :)
    at Context.jsdomDoneCallback (all_tests.js:12:3)

There are differences in the other tests as well.


  Basic Test
    1) throws an error in the actual test
    2) throws an error from a node require
    3) throws an async error from a node require
jsdomDoneCallback: [ { type: 'error',
    message: 'Running file:///Users/johnmclaughlin/git/mocha_jsdom_test2/directThrow.js failed.',
    data: 
     { error: [Error: direct throw from file],
       filename: 'file:///Users/johnmclaughlin/git/mocha_jsdom_test2/directThrow.js' } } ]
    4) throws an error in a jsdom script
    5) throws an error in a jsdom done callback
    with beforeEach jsdom setup
      6) throws a jsdom browser error from preloaded file.

  0 passing (52ms)
  6 failing

  1) Basic Test throws an error in the actual test:
     Error: throws something
      at Context.<anonymous> (all_tests.js:27:11)

  2) Basic Test throws an error from a node require:
     Error: thrower
      at module.exports (thrower.js:3:9)
      at Context.<anonymous> (all_tests.js:31:5)

  3) Basic Test throws an async error from a node require:
     Uncaught Error: thrower
      at module.exports (thrower.js:3:9)
      at null._onTimeout (all_tests.js:36:7)

  4) Basic Test throws an error in a jsdom script:
     the object {
  "data": {
    "error": "Error: direct throw from file"
    "filename": "file:///Users/johnmclaughlin/git/mocha_jsdom_test2/directThrow.js"
  }
  "message": "Running file:///Users/johnmclaughlin/git/mocha_jsdom_test2/directThrow.js failed."
  "type": "error"
  "uncaught": true
} was thrown, throw an Error :)
  Error: the object {
    "data": {
      "error": "Error: direct throw from file"
      "filename": "file://directThrow.js"
    }
    "message": "Running file://directThrow.js failed."
    "type": "error"
    "uncaught": true
  } was thrown, throw an Error :)

  5) Basic Test throws an error in a jsdom done callback:
     Uncaught Error: thrower
      at Object.module.exports [as done] (thrower.js:3:9)

  6) Basic Test with beforeEach jsdom setup throws a jsdom browser error from preloaded file.:
     Error: the error {} was thrown, throw an Error :)
      at Context.jsdomDoneCallback (all_tests.js:12:3)

Complete test report for mocha@2.1.0


  Basic Test
    1) throws an error in the actual test
    2) throws an error from a node require
    3) throws an async error from a node require
jsdomDoneCallback: [ { type: 'error',
    message: 'Running file:///Users/johnmclaughlin/git/mocha_jsdom_test2/directThrow.js failed.',
    data: 
     { error: [Error: direct throw from file],
       filename: 'file:///Users/johnmclaughlin/git/mocha_jsdom_test2/directThrow.js' } } ]
    4) throws an error in a jsdom script
    5) throws an error in a jsdom done callback
    with beforeEach jsdom setup
      6) throws a jsdom browser error from preloaded file.

  0 passing (48ms)
  6 failing

  1) Basic Test throws an error in the actual test:
     Error: throws something
      at Context.<anonymous> (/Users/johnmclaughlin/git/mocha_jsdom_test2/all_tests.js:27:11)
      at callFn (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runnable.js:251:21)
      at Test.Runnable.run (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runnable.js:244:7)
      at Runner.runTest (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:374:10)
      at /Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:452:12
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:299:14)
      at /Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:309:7
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:248:23)
      at Immediate._onImmediate (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:358:17)

  2) Basic Test throws an error from a node require:
     Error: thrower
      at module.exports (/Users/johnmclaughlin/git/mocha_jsdom_test2/thrower.js:3:9)
      at Context.<anonymous> (/Users/johnmclaughlin/git/mocha_jsdom_test2/all_tests.js:31:5)
      at callFn (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runnable.js:251:21)
      at Test.Runnable.run (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runnable.js:244:7)
      at Runner.runTest (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:374:10)
      at /Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:452:12
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:299:14)
      at /Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:309:7
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:248:23)
      at Immediate._onImmediate (/Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:358:17)

  3) Basic Test throws an async error from a node require:
     Uncaught Error: thrower
      at module.exports (/Users/johnmclaughlin/git/mocha_jsdom_test2/thrower.js:3:9)
      at null._onTimeout (/Users/johnmclaughlin/git/mocha_jsdom_test2/all_tests.js:36:7)
      at Timer.listOnTimeout (timers.js:110:15)

  4) Basic Test throws an error in a jsdom script:
     Uncaught Running file:///Users/johnmclaughlin/git/mocha_jsdom_test2/directThrow.js failed.

  5) Basic Test throws an error in a jsdom done callback:
     Uncaught Error: thrower
      at Object.module.exports [as done] (/Users/johnmclaughlin/git/mocha_jsdom_test2/thrower.js:3:9)
      at /Users/johnmclaughlin/git/mocha_jsdom_test2/node_modules/jsdom/lib/jsdom.js:249:18
      at process._tickCallback (node.js:355:11)

  6) Basic Test with beforeEach jsdom setup throws a jsdom browser error from preloaded file.:
     Error: globalThrower
      at window.browserThrower (file:///Users/johnmclaughlin/git/mocha_jsdom_test2/browserThrower.js:5:9)
danielstjules commented 9 years ago

Seems related to https://github.com/mochajs/mocha/issues/1766 Can you checkout https://github.com/mochajs/mocha/pull/1767 and confirm whether or not it helps?

mjhm commented 9 years ago

@danielstjules In my test case it looks like https://github.com/mochajs/mocha/pull/1767 prints out pretty much the same as the --full-trace option with mocha@2.2.5. Unfortunately this still misses the stack trace lines for the JSDOM loaded files.

Output for https://github.com/mochajs/mocha/pull/1767


  1) Basic Test throws an error in the actual test:
     Error: throws something
      at Context.<anonymous> (/Users/johnmclaughlin/git/mocha_jsdom_test/all_tests.js:27:11)
      at callFn (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:266:21)
      at Test.Runnable.run (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:259:7)
      at Runner.runTest (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:390:10)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:473:12
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:315:14)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:325:7
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:260:23)
      at Immediate._onImmediate (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:292:5)
      at processImmediate [as _immediateCallback] (timers.js:358:17)

  2) Basic Test throws an error from a node require:
     Error: thrower
      at module.exports (/Users/johnmclaughlin/git/mocha_jsdom_test/thrower.js:3:9)
      at Context.<anonymous> (/Users/johnmclaughlin/git/mocha_jsdom_test/all_tests.js:31:5)
      at callFn (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:266:21)
      at Test.Runnable.run (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:259:7)
      at Runner.runTest (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:390:10)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:473:12
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:315:14)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:325:7
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:260:23)
      at Immediate._onImmediate (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:292:5)
      at processImmediate [as _immediateCallback] (timers.js:358:17)

  3) Basic Test throws an async error from a node require:
     Uncaught Error: thrower
      at module.exports (/Users/johnmclaughlin/git/mocha_jsdom_test/thrower.js:3:9)
      at null._onTimeout (/Users/johnmclaughlin/git/mocha_jsdom_test/all_tests.js:36:7)
      at Timer.listOnTimeout (timers.js:110:15)

  4) Basic Test throws an error in a jsdom script:
     Error: the object {
  "data": {
    "error": "Error: direct throw from file"
    "filename": "file:///Users/johnmclaughlin/git/mocha_jsdom_test/directThrow.js"
  }
  "message": "Running file:///Users/johnmclaughlin/git/mocha_jsdom_test/directThrow.js failed."
  "type": "error"
  "uncaught": true
} was thrown, throw an Error :)
      at Runner.fail (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:206:11)
      at Runner.uncaught (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:583:8)
      at process.uncaught (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:612:10)
      at process.emit (events.js:107:17)
      at process._fatalException (node.js:236:26)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/jsdom/lib/jsdom.js:249:18
      at process._tickCallback (node.js:355:11)

  5) Basic Test throws an error in a jsdom done callback:
     Uncaught Error: thrower
      at Object.module.exports [as done] (/Users/johnmclaughlin/git/mocha_jsdom_test/thrower.js:3:9)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/jsdom/lib/jsdom.js:249:18
      at process._tickCallback (node.js:355:11)

  6) Basic Test with beforeEach jsdom setup throws a jsdom browser error from preloaded file.:
     Error: the error {} was thrown, throw an Error :)
      at Runner.fail (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:206:11)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:480:18
      at done (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:222:5)
      at Test.Runnable.run (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:245:7)
      at Runner.runTest (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:390:10)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:473:12
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:315:14)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:325:7
      at next (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:260:23)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runner.js:287:7
      at done (/Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:222:5)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/mocha/lib/runnable.js:242:9
      at Context.jsdomDoneCallback (/Users/johnmclaughlin/git/mocha_jsdom_test/all_tests.js:12:3)
      at /Users/johnmclaughlin/git/mocha_jsdom_test/node_modules/jsdom/lib/jsdom.js:249:18
      at process._tickCallback (node.js:355:11)
boneskull commented 9 years ago

@danielstjules I'm gonna put this on your plate :smile:

danielstjules commented 9 years ago

@boneskull haha cool, will take a look this weekend

czardoz commented 8 years ago

Any updates on this? :smile:

stale[bot] commented 7 years ago

I am a bot that watches issues for inactivity. This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue. Thanks for contributing to Mocha!

JoshuaKGoldberg commented 10 months ago

This should have been fixed in #1767. Also the issue is very old and hasn't been interacted with since 2017. Marking as closed. ✔️

But if I'm wrong and it's still an active issue, please do file a new issue using one of our new issue templates. They'll ask for the info we'd need to re-triage this. Cheers all!