13

So nyc is mangling my files as follows:

  at _onCreate (src/post/admin.js:1:10453)
  at doQuery (src/db.js:59:216)
  at process._tickCallback (internal/process/next_tick.js:68:7)

I am unsure of how to use a source map to unmangle this. The docs state:

Accurate stack traces using source-maps.

When produce-source-map is set to true, then the instrumented source files will include inline source maps for the instrumenter transform. When combined with source-map-support, stack traces for instrumented code will reflect their original lines.

So I tried the following npm run command:

"NODE_ENV=test nyc mocha --require ./tests/setup.js --require source-map-support/register --produce-source-map true --bail ./tests/unit/$FILE"

combined with the nyc setting:

"nyc": {
    "include": [
        "src"
    ],
    "exclude": [
        "./tmp/**/*",
        "./tests"
    ],
    "instrument": true,
    "report-dir": "./tests/coverage",
    "temp-dir": "./tests/temp",
    "source-map": true,
    "produce-source-map": true
}

but the line is still mangled.

A. L
  • 11,695
  • 23
  • 85
  • 163

1 Answers1

13

the basic pre-condition for it to work would be (as described here):

npm install --save-dev source-map-support

make sure nyc is ^10.3.2 (10.3.0 was broken).

"devDependencies": {
    ...
    "mocha": "^3.3.0",
    "nyc": "^10.3.2",
    "source-map-support": "^0.4.15",
}

the nyc config should be "sourceMap": true, "produce-source-map": true.

and the documentation explains how to use them:

CLI Usage

node -r source-map-support/register compiled.js

Programmatic Usage

Put the following line at the top of the compiled file.

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

one can also define mapping file-names by adding comments:

//# sourceMappingURL=filename.js.map
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Well I'm trying to use in their example of `$ mocha --require source-map-support/register tests/`, except that's pretty pointless since I can get the right line error without it in the first place. I'm just trying to work out how to incorporate it with nyc. – A. L Oct 26 '18 at 05:17
  • @A.Lau when `produce-source-map` is set to `true`, then the instrumented source files will include inline source maps... where the word "inline" tells where to find them. `sourceMappingURL` can be used not to inline. the issue tracker has quite some entries: https://github.com/istanbuljs/nyc/issues?utf8=%E2%9C%93&q=is%3Aopen+source-map – Martin Zeitler Oct 26 '18 at 18:25
  • found another `nyc` config, which uses `sourceMap` instead of `source-map`. – Martin Zeitler Oct 26 '18 at 18:37