Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript Source Maps Support #550

Closed
rjanicek opened this issue Aug 23, 2012 · 20 comments
Closed

JavaScript Source Maps Support #550

rjanicek opened this issue Aug 23, 2012 · 20 comments

Comments

@rjanicek
Copy link

Maybe it's possible to use source maps for better "view source" and doc reporter when testing with minified JS or languages that compile to JS.

http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

Thank you.

@lavrton
Copy link

lavrton commented Apr 21, 2013

+1

@tj
Copy link
Contributor

tj commented Apr 22, 2013

this shouldn't really have anything to do with Mocha, you can compile source maps for own code if you like

@tj tj closed this as completed Apr 22, 2013
@ashnur
Copy link

ashnur commented May 1, 2013

I might be wrong about this, but what I see is that even though I compile source maps for my code (and I checked that these source maps really work), if an Exception is thrown, mocha reports only the bundle.js file which has the minified/concatenated code.

@lavrton
Copy link

lavrton commented May 1, 2013

Ashnur, you are rigth. Also problem with line numbers.

@tj
Copy link
Contributor

tj commented May 1, 2013

that's not the concern of mocha though, you can compile source maps (or use sourceurl) if you're aggregating

@ashnur
Copy link

ashnur commented May 1, 2013

@visionmedia I am sorry, but I don't understand your response. I mean I understand the meaning of it, but it seems to me, that you just repeated your last response and have not reponded to me. That or I must be completely missing the point somewhere, and I am unaware of not just what it is, but where I am missing it.

I am using mocha in the browser on a code which has to be browserified in order to work there. I use the browserify feature of compiling source maps for the code, and they work properly, as long as I am not trying to use the code with mocha. When I use it with mocha, the source maps go away, I only get the original file and line nr. references, not the source maps, which - I repeat the third time - are there.

So please, if you do not mind taking the time, explain to me what else should I do so that I can use the compiled source maps with mocha?

@tj
Copy link
Contributor

tj commented May 1, 2013

hmm I'm not sure why they would go away when using Mocha, maybe the browsers just don't respect source maps for err.stack, I dont think there's anything we can do about that

@juliangruber
Copy link

that's my impression too...

@jacobbubu
Copy link

May I use mocha in this way mocha --compilers coffee:"coffee-script --map" to support source map?

@tj
Copy link
Contributor

tj commented May 22, 2013

@jacobbubu nope, if you use coffeescript you're screwed just about everywhere on the server-side for error mapping

@actionshrimp
Copy link

If anyone's still interested in source mapped stack traces, @evanw has recently added browser compatability (using browserify) to node-source-map-support here: evanw/node-source-map-support@70c343e

Note that it relies on Error.prepareStackTrace which I believe is only paid attention to by Chrome, so source mapped stack traces only work there, but it's working a treat for me :)

@shanebdavis
Copy link

+1

Reading the comments above, I think there is some misunderstanding. My understanding of the original posters request is that Mocha's HTML output after running the tests contains stack traces which do not use source-maps.

I use Coffeescript + source-maps which work pretty well with Chrome's developer tools, but they are ignored by Mocha.

For anyone using Coffeescript or other javascript preprocessors, a stack trace of the generated javascript is not very helpful. My productivity would increase quite a bit if all stack traces Mocha outputs used source-maps, when available.

@tj
Copy link
Contributor

tj commented Aug 13, 2013

I'm definitely against doing anything custom to pull in source maps, I don't see why the browser can't do this for you when the developer tools are open etc, pretty silly to force every client lib to handle this.

@asheb
Copy link

asheb commented Jul 20, 2014

Dirty hack to make it work with PhantomJS. May come in handy.

@krunkosaurus
Copy link

+1. I realize from what @visionmedia replied that this necessarily isn't a direct Mocha issue but any more visibility into getting this working would be good. I test prod code with Mocha which means I test compressed code. If I can't see real line numbers in the errors it makes Mocha half as useful as it should be.

@dreampulse
Copy link

I solved this problem with node-source-map-support

require('source-map-support').install();

describe('APIs', () => {

    it('should do something', (done) => {

       throw new Error();
       ///....

    });

  });
});

Now the stacktrace is pointing to the "correct" source file.

I hope this will help you :-)

@boneskull
Copy link
Contributor

@dreampulse This is great information. Care to post it in the wiki?

@liukun
Copy link

liukun commented Mar 4, 2015

Agree with @dreampulse
Better set the following option in coffeescript when install

    require('source-map-support').install
      handleUncaughtExceptions: false

Otherwise, function handleUncaughtExceptions in module source-map-support will call process.exit(1) and terminate mocha process without ending properly.

@corelgott
Copy link

@dreampulse +1

@rosskevin
Copy link

FYI - source-map-support also supports chrome - lifesaver for debugging.

https://github.com/evanw/node-source-map-support#browser-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests