Mocha: babel-register: stack trace with correct line numbers

Created on 15 Sep 2016  路  4Comments  路  Source: mochajs/mocha

hello!

We have test sute writen on ES2015 and run mocha as writted on official site with parameter --compilers js:babel-register. Everything goes well except error stack trace. We get incorrect line numbers into console when Mocha fail test.

Example:

TypeError: Cannot read property 'listenerCount' of undefined
at Context. (test/view/SlovoAsListItemView.Test.js:184:32)

SlovoAsListItemView.Test.js has 79 lines at all. Not 184! As far as I can see babel transpile our code into ES 5 and it grows up to 184+ lines. And then Mocha get this temp file and execute it as a source.

How can we get correct line numbers into console?

package.json with babel section

{
...
    "babel": {
        "plugins": [
            "fast-async",
            "transform-class-properties",
            "transform-es2015-parameters",
            "transform-es2015-destructuring"
        ],
        "sourceMaps": "inline"
    }
}

Most helpful comment

--require source-map-support probably. Try "sourceMaps": "both" as well.

Hint: use --require babel-register instead of --compilers js:babel-register.

All 4 comments

--require source-map-support probably. Try "sourceMaps": "both" as well.

Hint: use --require babel-register instead of --compilers js:babel-register.

@boneskull
--require source-map-support works like a charm.

@boneskull

Hint: use --require babel-register instead of --compilers js:babel-register

what is the difference?

--compilers is intended for use with files that don't have a .js extension. Originally, CoffeeScript. But this might be a holdover from old require() implementations--the registration module in coffee-script might work with --require nowadays. Not sure. If that is the case, --compilers could be deprecated for certain versions of Node and/or coffee-script.

Was this page helpful?
0 / 5 - 0 ratings