mochify.js icon indicating copy to clipboard operation
mochify.js copied to clipboard

No source mapping for async functions

Open Bjvanminnen opened this issue 9 years ago • 6 comments

When hitting assertions in asynchronous code, we don't get unhelpful callstacks, instead just getting the line number from bundle.js

var assert = require('chai').assert;

describe('foo', function () {
  it('sync', function (done) {
    assert(true, 'truth');
    assert(false, 'false');
  });

  it('async', function (done) {
    assert(true, 'truth');

    setTimeout(function () {
      assert(false, 'false');
      done();
    }, 1000);
  });
});

Result:

1) foo sync:                                                            
   false                                                                
    at assert (node_modules/chai/lib/chai/assertion.js:111:67)          
    at assert (node_modules/chai/lib/chai/interface/assert.js:37:16)    
    at test/test.js:6:11                                                

2) foo async:                                                           
   Uncaught AssertionError: false (http://localhost:52436/js/bundle:229)

Bjvanminnen avatar Jun 01 '15 22:06 Bjvanminnen

Yes, I'm seeing this occasionally as well. Not sure it has something to do with the async test case.

Can you try and run the tests as a website with --consolify and check whether you see the same thing? Maybe even in different browsers?

mantoni avatar Jun 02 '15 06:06 mantoni

Chrome on OSX

  1) foo sync:
     AssertionError: false
      at Context.<anonymous> (test/test.js:6:5)
      at Test.Runnable.run (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4529:15)
      at Runner.runTest (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4974:10)
      at node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:5057:12
      at next (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4899:14)
      at node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4909:7
      at next (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4844:23)
      at node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4876:5
      at timeslice (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6483:27)

  2) foo async:
     Uncaught Uncaught AssertionError: false (file:///Users/brent/git/fun/mochify_test/output.html:389)
      Error: Uncaught AssertionError: false (node_modules/chai/lib/chai/assertion.js:107)
      at global.onerror (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6458:10)

Firefox

  1) foo sync:
     false


  2) foo async:
     Uncaught AssertionError: false (:0)
      require<[88]</</process.on/global.onerror node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6458:10

Safari

1) foo sync:
     false
      assert node_modules/chai/lib/chai/assertion.js:111:67
      assert node_modules/chai/lib/chai/interface/assert.js:37:16
      test/test.js:6:11
      run node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4529:19
      runTest node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4974:13
      node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:5057:19
      next node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4899:16
      node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4909:11
      next node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4844:25
      node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4876:9
      timeslice node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6483:27

  2) foo async:
     Uncaught AssertionError: false (file:///Users/brent/git/fun/mochify_test/output.html:393)
      onerror node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6458:19

Bjvanminnen avatar Jun 02 '15 06:06 Bjvanminnen

try mocha's --full-trace option. we eliminated much of the stack trace to ignore Mocha internals; maybe it's zapping lines it shouldn't.

boneskull avatar Jul 28 '15 19:07 boneskull

I'm running into this.

boneskull avatar Aug 03 '15 19:08 boneskull

I don't even know if the browser bundle of mocha supports full-trace

boneskull avatar Aug 03 '15 19:08 boneskull

I suppose this happens because errors in async functions are caught with the window "error" event. Mocha then associates the error with the currently running test. Unfortunately, browsers treat these "global" errors very differently and it's not guaranteed that there is a stack trace at all.

To anyone who wants to look into this, I'd suggest to check what the raw format of a global error looks like in different browsers / phantom and then fix that RegExp in source-mapper.

mantoni avatar Nov 12 '15 08:11 mantoni