diff options
author | bcoe <bencoe@google.com> | 2019-09-29 14:15:39 -0700 |
---|---|---|
committer | Benjamin Coe <bencoe@google.com> | 2019-10-05 17:08:00 -0700 |
commit | e1e2f669f65fd53323b8a58d80ed3cee039706b7 (patch) | |
tree | 582baba1511e57a9915b379d0f263cb29fb6c38f /test | |
parent | 739f113ba63367a93e1567032d85573a079b97b5 (diff) | |
download | android-node-v8-e1e2f669f65fd53323b8a58d80ed3cee039706b7.tar.gz android-node-v8-e1e2f669f65fd53323b8a58d80ed3cee039706b7.tar.bz2 android-node-v8-e1e2f669f65fd53323b8a58d80ed3cee039706b7.zip |
process: add source-map support to stack traces
PR-URL: https://github.com/nodejs/node/pull/29564
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
24 files changed, 292 insertions, 13 deletions
diff --git a/test/fixtures/source-map/babel-esm-original.mjs b/test/fixtures/source-map/babel-esm-original.mjs new file mode 100644 index 0000000000..70ae479452 --- /dev/null +++ b/test/fixtures/source-map/babel-esm-original.mjs @@ -0,0 +1,9 @@ +import {foo} from './esm-dep.mjs'; + +const obj = { + a: { + b: 22 + } +}; + +if (obj?.a?.b === 22) throw Error('an exception'); diff --git a/test/fixtures/source-map/babel-esm.mjs b/test/fixtures/source-map/babel-esm.mjs new file mode 100644 index 0000000000..9ad84663a3 --- /dev/null +++ b/test/fixtures/source-map/babel-esm.mjs @@ -0,0 +1,10 @@ +var _obj$a; + +import { foo } from './esm-dep.mjs'; +const obj = { + a: { + b: 22 + } +}; +if ((obj === null || obj === void 0 ? void 0 : (_obj$a = obj.a) === null || _obj$a === void 0 ? void 0 : _obj$a.b) === 22) throw Error('an exception'); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImJhYmVsLWVzbS1vcmlnaW5hbC5tanMiXSwibmFtZXMiOlsiZm9vIiwib2JqIiwiYSIsImIiLCJFcnJvciJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxTQUFRQSxHQUFSLFFBQWtCLGVBQWxCO0FBRUEsTUFBTUMsR0FBRyxHQUFHO0FBQ1ZDLEVBQUFBLENBQUMsRUFBRTtBQUNEQyxJQUFBQSxDQUFDLEVBQUU7QUFERjtBQURPLENBQVo7QUFNQSxJQUFJLENBQUFGLEdBQUcsU0FBSCxJQUFBQSxHQUFHLFdBQUgsc0JBQUFBLEdBQUcsQ0FBRUMsQ0FBTCxrREFBUUMsQ0FBUixNQUFjLEVBQWxCLEVBQXNCLE1BQU1DLEtBQUssQ0FBQyxjQUFELENBQVgiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQge2Zvb30gZnJvbSAnLi9lc20tZGVwLm1qcyc7XG5cbmNvbnN0IG9iaiA9IHtcbiAgYToge1xuICAgIGI6IDIyXG4gIH1cbn07XG5cbmlmIChvYmo/LmE/LmIgPT09IDIyKSB0aHJvdyBFcnJvcignYW4gZXhjZXB0aW9uJyk7XG5cbiJdfQ== diff --git a/test/fixtures/source-map/babel-throw-original.js b/test/fixtures/source-map/babel-throw-original.js new file mode 100644 index 0000000000..779bd16fd4 --- /dev/null +++ b/test/fixtures/source-map/babel-throw-original.js @@ -0,0 +1,19 @@ +/*--- +esid: prod-OptionalExpression +features: [optional-chaining] +---*/ + +const obj = { + a: { + b: 22 + } +}; + +function fn () { + return {}; +} + +setTimeout((err) => { + // OptionalExpression (MemberExpression OptionalChain) OptionalChain + if (obj?.a?.b === 22) throw Error('an exception'); +}, 5); diff --git a/test/fixtures/source-map/babel-throw.js b/test/fixtures/source-map/babel-throw.js new file mode 100644 index 0000000000..3cef68136c --- /dev/null +++ b/test/fixtures/source-map/babel-throw.js @@ -0,0 +1,21 @@ +/*--- +esid: prod-OptionalExpression +features: [optional-chaining] +---*/ +const obj = { + a: { + b: 22 + } +}; + +function fn() { + return {}; +} + +setTimeout(err => { + var _obj$a; + + // OptionalExpression (MemberExpression OptionalChain) OptionalChain + if ((obj === null || obj === void 0 ? void 0 : (_obj$a = obj.a) === null || _obj$a === void 0 ? void 0 : _obj$a.b) === 22) throw Error('an exception'); +}, 5); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImJhYmVsLXRocm93LW9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbIm9iaiIsImEiLCJiIiwiZm4iLCJzZXRUaW1lb3V0IiwiZXJyIiwiRXJyb3IiXSwibWFwcGluZ3MiOiJBQUFBOzs7O0FBS0EsTUFBTUEsR0FBRyxHQUFHO0FBQ1ZDLEVBQUFBLENBQUMsRUFBRTtBQUNEQyxJQUFBQSxDQUFDLEVBQUU7QUFERjtBQURPLENBQVo7O0FBTUEsU0FBU0MsRUFBVCxHQUFlO0FBQ2IsU0FBTyxFQUFQO0FBQ0Q7O0FBRURDLFVBQVUsQ0FBRUMsR0FBRCxJQUFTO0FBQUE7O0FBQ2xCO0FBQ0EsTUFBSSxDQUFBTCxHQUFHLFNBQUgsSUFBQUEsR0FBRyxXQUFILHNCQUFBQSxHQUFHLENBQUVDLENBQUwsa0RBQVFDLENBQVIsTUFBYyxFQUFsQixFQUFzQixNQUFNSSxLQUFLLENBQUMsY0FBRCxDQUFYO0FBQ3ZCLENBSFMsRUFHUCxDQUhPLENBQVYiLCJzb3VyY2VzQ29udGVudCI6WyIvKi0tLVxuZXNpZDogcHJvZC1PcHRpb25hbEV4cHJlc3Npb25cbmZlYXR1cmVzOiBbb3B0aW9uYWwtY2hhaW5pbmddXG4tLS0qL1xuXG5jb25zdCBvYmogPSB7XG4gIGE6IHtcbiAgICBiOiAyMlxuICB9XG59O1xuXG5mdW5jdGlvbiBmbiAoKSB7XG4gIHJldHVybiB7fTtcbn1cblxuc2V0VGltZW91dCgoZXJyKSA9PiB7XG4gIC8vIE9wdGlvbmFsRXhwcmVzc2lvbiAoTWVtYmVyRXhwcmVzc2lvbiBPcHRpb25hbENoYWluKSBPcHRpb25hbENoYWluXG4gIGlmIChvYmo/LmE/LmIgPT09IDIyKSB0aHJvdyBFcnJvcignYW4gZXhjZXB0aW9uJyk7XG59LCA1KTtcblxuIl19 diff --git a/test/fixtures/source-map/basic.js b/test/fixtures/source-map/basic.js index a483ffb105..5d1420360f 100644 --- a/test/fixtures/source-map/basic.js +++ b/test/fixtures/source-map/basic.js @@ -4,4 +4,4 @@ if (true) { } else { const c = 102; } -//# sourceMappingURL=https://http.cat/418 +//# sourceMappingURL=https://ci.nodejs.org/418 diff --git a/test/fixtures/source-map/esm-basic.mjs b/test/fixtures/source-map/esm-basic.mjs index 55747d3870..03222b244b 100644 --- a/test/fixtures/source-map/esm-basic.mjs +++ b/test/fixtures/source-map/esm-basic.mjs @@ -1,4 +1,4 @@ import {foo} from './esm-dep.mjs'; import {strictEqual} from 'assert'; strictEqual(foo(), 'foo'); -//# sourceMappingURL=https://http.cat/405 +//# sourceMappingURL=https://ci.nodejs.org/405 diff --git a/test/fixtures/source-map/esm-dep.mjs b/test/fixtures/source-map/esm-dep.mjs index 00805894af..5e86405751 100644 --- a/test/fixtures/source-map/esm-dep.mjs +++ b/test/fixtures/source-map/esm-dep.mjs @@ -1,4 +1,4 @@ export function foo () { return 'foo'; }; -//# sourceMappingURL=https://http.cat/422 +//# sourceMappingURL=https://ci.nodejs.org/422 diff --git a/test/fixtures/source-map/exit-1.js b/test/fixtures/source-map/exit-1.js index 9734649a77..d8b5626445 100644 --- a/test/fixtures/source-map/exit-1.js +++ b/test/fixtures/source-map/exit-1.js @@ -5,4 +5,4 @@ if (true) { const c = 102; } process.exit(1); -//# sourceMappingURL=https://http.cat/404 +//# sourceMappingURL=https://ci.nodejs.org/404 diff --git a/test/fixtures/source-map/istanbul-throw-original.js b/test/fixtures/source-map/istanbul-throw-original.js new file mode 100644 index 0000000000..099faa175d --- /dev/null +++ b/test/fixtures/source-map/istanbul-throw-original.js @@ -0,0 +1,10 @@ +/* + * comments dropped by uglify. + */ +function Hello() { + throw Error('goodbye'); +} + +setImmediate(function() { + Hello(); +}); diff --git a/test/fixtures/source-map/istanbul-throw.js b/test/fixtures/source-map/istanbul-throw.js new file mode 100644 index 0000000000..4f719a1c7a --- /dev/null +++ b/test/fixtures/source-map/istanbul-throw.js @@ -0,0 +1,4 @@ +var cov_ono70fls3=function(){var path="/Users/bencoe/oss/source-map-testing/istanbul-throw-original.js";var hash="4302fcea4eb0ea4d9af6e63a478f214aa61f9dd8";var global=new Function("return this")();var gcv="__coverage__";var coverageData={path:"/Users/bencoe/oss/source-map-testing/istanbul-throw-original.js",statementMap:{"0":{start:{line:5,column:2},end:{line:5,column:25}},"1":{start:{line:8,column:0},end:{line:10,column:3}},"2":{start:{line:9,column:2},end:{line:9,column:10}}},fnMap:{"0":{name:"Hello",decl:{start:{line:4,column:9},end:{line:4,column:14}},loc:{start:{line:4,column:17},end:{line:6,column:1}},line:4},"1":{name:"(anonymous_1)",decl:{start:{line:8,column:13},end:{line:8,column:14}},loc:{start:{line:8,column:24},end:{line:10,column:1}},line:8}},branchMap:{},s:{"0":0,"1":0,"2":0},f:{"0":0,"1":0},b:{},_coverageSchema:"43e27e138ebf9cfc5966b082cf9a028302ed4184",hash:"4302fcea4eb0ea4d9af6e63a478f214aa61f9dd8"};var coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}return coverage[path]=coverageData;}();/* + * comments dropped by uglify. + */function Hello(){cov_ono70fls3.f[0]++;cov_ono70fls3.s[0]++;throw Error('goodbye');}cov_ono70fls3.s[1]++;setImmediate(function(){cov_ono70fls3.f[1]++;cov_ono70fls3.s[2]++;Hello();}); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9iZW5jb2Uvb3NzL3NvdXJjZS1tYXAtdGVzdGluZy9pc3RhbmJ1bC10aHJvdy1vcmlnaW5hbC5qcyJdLCJuYW1lcyI6WyJIZWxsbyIsIkVycm9yIiwic2V0SW1tZWRpYXRlIl0sIm1hcHBpbmdzIjoiMmpDQUFBOztHQUdBLFFBQVNBLENBQUFBLEtBQVQsRUFBaUIsMkNBQ2YsS0FBTUMsQ0FBQUEsS0FBSyxDQUFDLFNBQUQsQ0FBWCxDQUNELEMscUJBRURDLFlBQVksQ0FBQyxVQUFXLDJDQUN0QkYsS0FBSyxHQUNOLENBRlcsQ0FBWiIsInNvdXJjZXNDb250ZW50IjpbIi8qXG4gKiBjb21tZW50cyBkcm9wcGVkIGJ5IHVnbGlmeS5cbiAqL1xuZnVuY3Rpb24gSGVsbG8oKSB7XG4gIHRocm93IEVycm9yKCdnb29kYnllJyk7XG59XG5cbnNldEltbWVkaWF0ZShmdW5jdGlvbigpIHtcbiAgSGVsbG8oKTtcbn0pO1xuXG4iXX0= diff --git a/test/fixtures/source-map/sigint.js b/test/fixtures/source-map/sigint.js index 11df66645f..f9ffaa8666 100644 --- a/test/fixtures/source-map/sigint.js +++ b/test/fixtures/source-map/sigint.js @@ -5,4 +5,4 @@ if (true) { const c = 102; } process.kill(process.pid, "SIGINT"); -//# sourceMappingURL=https://http.cat/402 +//# sourceMappingURL=https://ci.nodejs.org/402 diff --git a/test/fixtures/source-map/typescript-throw.js b/test/fixtures/source-map/typescript-throw.js new file mode 100644 index 0000000000..0c4e57756f --- /dev/null +++ b/test/fixtures/source-map/typescript-throw.js @@ -0,0 +1,27 @@ +var ATrue; +(function (ATrue) { + ATrue[ATrue["IsTrue"] = 1] = "IsTrue"; + ATrue[ATrue["IsFalse"] = 0] = "IsFalse"; +})(ATrue || (ATrue = {})); +if (false) { + console.info('unreachable'); +} +else if (true) { + console.info('reachable'); +} +else { + console.info('unreachable'); +} +function branch(a) { + if (a === ATrue.IsFalse) { + console.info('a = false'); + } + else if (a === ATrue.IsTrue) { + throw Error('an exception'); + } + else { + console.info('a = ???'); + } +} +branch(ATrue.IsTrue); +//# sourceMappingURL=typescript-throw.js.map diff --git a/test/fixtures/source-map/typescript-throw.js.map b/test/fixtures/source-map/typescript-throw.js.map new file mode 100644 index 0000000000..f1f55af1a9 --- /dev/null +++ b/test/fixtures/source-map/typescript-throw.js.map @@ -0,0 +1 @@ +{"version":3,"file":"typescript-throw.js","sourceRoot":"","sources":["typescript-throw.ts"],"names":[],"mappings":"AAAA,IAAK,KAGJ;AAHD,WAAK,KAAK;IACR,qCAAU,CAAA;IACV,uCAAW,CAAA;AACb,CAAC,EAHI,KAAK,KAAL,KAAK,QAGT;AAED,IAAI,KAAK,EAAE;IACT,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;CAC5B;KAAM,IAAI,IAAI,EAAE;IACf,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;CAC1B;KAAM;IACL,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;CAC5B;AAED,SAAS,MAAM,CAAE,CAAQ;IACvB,IAAI,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE;QACvB,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;KAC1B;SAAM,IAAI,CAAC,KAAK,KAAK,CAAC,MAAM,EAAE;QAC7B,MAAM,KAAK,CAAC,cAAc,CAAC,CAAC;KAC7B;SAAM;QACL,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;KACxB;AACH,CAAC;AAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA"} diff --git a/test/fixtures/source-map/typescript-throw.ts b/test/fixtures/source-map/typescript-throw.ts new file mode 100644 index 0000000000..befb58fe0a --- /dev/null +++ b/test/fixtures/source-map/typescript-throw.ts @@ -0,0 +1,24 @@ +enum ATrue { + IsTrue = 1, + IsFalse = 0 +} + +if (false) { + console.info('unreachable') +} else if (true) { + console.info('reachable') +} else { + console.info('unreachable') +} + +function branch (a: ATrue) { + if (a === ATrue.IsFalse) { + console.info('a = false') + } else if (a === ATrue.IsTrue) { + throw Error('an exception'); + } else { + console.info('a = ???') + } +} + +branch(ATrue.IsTrue) diff --git a/test/fixtures/source-map/uglify-throw-original.js b/test/fixtures/source-map/uglify-throw-original.js new file mode 100644 index 0000000000..099faa175d --- /dev/null +++ b/test/fixtures/source-map/uglify-throw-original.js @@ -0,0 +1,10 @@ +/* + * comments dropped by uglify. + */ +function Hello() { + throw Error('goodbye'); +} + +setImmediate(function() { + Hello(); +}); diff --git a/test/fixtures/source-map/uglify-throw.js b/test/fixtures/source-map/uglify-throw.js new file mode 100644 index 0000000000..ea6201e59d --- /dev/null +++ b/test/fixtures/source-map/uglify-throw.js @@ -0,0 +1,2 @@ +setImmediate(function(){!function(){throw Error("goodbye")}()}); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInVnbGlmeS10aHJvdy1vcmlnaW5hbC5qcyJdLCJuYW1lcyI6WyJzZXRJbW1lZGlhdGUiLCJFcnJvciIsIkhlbGxvIl0sIm1hcHBpbmdzIjoiQUFPQUEsYUFBYSxZQUpiLFdBQ0UsTUFBTUMsTUFBTSxXQUlaQyIsInNvdXJjZXNDb250ZW50IjpbIi8qXG4gKiBjb21tZW50cyBkcm9wcGVkIGJ5IHVnbGlmeS5cbiAqL1xuZnVuY3Rpb24gSGVsbG8oKSB7XG4gIHRocm93IEVycm9yKCdnb29kYnllJyk7XG59XG5cbnNldEltbWVkaWF0ZShmdW5jdGlvbigpIHtcbiAgSGVsbG8oKTtcbn0pO1xuXG4iXX0= diff --git a/test/message/source_map_throw_catch.js b/test/message/source_map_throw_catch.js new file mode 100644 index 0000000000..f3a887474b --- /dev/null +++ b/test/message/source_map_throw_catch.js @@ -0,0 +1,11 @@ +// Flags: --enable-source-maps + +'use strict'; +require('../common'); +try { + require('../fixtures/source-map/typescript-throw'); +} catch (err) { + setTimeout(() => { + console.info(err); + }, 10); +} diff --git a/test/message/source_map_throw_catch.out b/test/message/source_map_throw_catch.out new file mode 100644 index 0000000000..63e3eca3ef --- /dev/null +++ b/test/message/source_map_throw_catch.out @@ -0,0 +1,14 @@ +reachable +Error: an exception + at branch (*typescript-throw.js:20:15) + -> *typescript-throw.ts:18:11 + at Object.<anonymous> (*typescript-throw.js:26:1) + -> *typescript-throw.ts:24:1 + at Module._compile (internal/modules/cjs/loader.js:*) + at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) + at Module.load (internal/modules/cjs/loader.js:*) + at Function.Module._load (internal/modules/cjs/loader.js:*) + at Module.require (internal/modules/cjs/loader.js:*) + at require (internal/modules/cjs/helpers.js:*) + at Object.<anonymous> (*source_map_throw_catch.js:6:3) + at Module._compile (internal/modules/cjs/loader.js:*) diff --git a/test/message/source_map_throw_first_tick.js b/test/message/source_map_throw_first_tick.js new file mode 100644 index 0000000000..b691b51f35 --- /dev/null +++ b/test/message/source_map_throw_first_tick.js @@ -0,0 +1,5 @@ +// Flags: --enable-source-maps + +'use strict'; +require('../common'); +require('../fixtures/source-map/typescript-throw'); diff --git a/test/message/source_map_throw_first_tick.out b/test/message/source_map_throw_first_tick.out new file mode 100644 index 0000000000..7f11d9fbd9 --- /dev/null +++ b/test/message/source_map_throw_first_tick.out @@ -0,0 +1,14 @@ +reachable +Error: an exception + at branch (*typescript-throw.js:20:15) + -> *typescript-throw.ts:18:11 + at Object.<anonymous> (*typescript-throw.js:26:1) + -> *typescript-throw.ts:24:1 + at Module._compile (internal/modules/cjs/loader.js:*) + at Object.Module._extensions..js (internal/modules/cjs/loader.js:*) + at Module.load (internal/modules/cjs/loader.js:*) + at Function.Module._load (internal/modules/cjs/loader.js:*) + at Module.require (internal/modules/cjs/loader.js:*) + at require (internal/modules/cjs/helpers.js:*) + at Object.<anonymous> (*source_map_throw_first_tick.js:5:1) + at Module._compile (internal/modules/cjs/loader.js:*) diff --git a/test/message/source_map_throw_set_immediate.js b/test/message/source_map_throw_set_immediate.js new file mode 100644 index 0000000000..17da1bd7ac --- /dev/null +++ b/test/message/source_map_throw_set_immediate.js @@ -0,0 +1,5 @@ +// Flags: --enable-source-maps + +'use strict'; +require('../common'); +require('../fixtures/source-map/uglify-throw'); diff --git a/test/message/source_map_throw_set_immediate.out b/test/message/source_map_throw_set_immediate.out new file mode 100644 index 0000000000..6b169d7e02 --- /dev/null +++ b/test/message/source_map_throw_set_immediate.out @@ -0,0 +1,10 @@ +*uglify-throw.js:1 +setImmediate(function(){!function(){throw Error("goodbye")}()}); + ^ + +Error: goodbye + at *uglify-throw.js:1:43 + -> *uglify-throw-original.js:5:9 + at Immediate.<anonymous> (*uglify-throw.js:1:60) + -> *uglify-throw-original.js:9:3 + at processImmediate (internal/timers.js:*) diff --git a/test/parallel/test-bootstrap-modules.js b/test/parallel/test-bootstrap-modules.js index 36c323b977..ae69f5aef0 100644 --- a/test/parallel/test-bootstrap-modules.js +++ b/test/parallel/test-bootstrap-modules.js @@ -55,7 +55,7 @@ const expectedModules = new Set([ 'NativeModule internal/process/task_queues', 'NativeModule internal/process/warning', 'NativeModule internal/querystring', - 'NativeModule internal/source_map', + 'NativeModule internal/source_map/source_map_cache', 'NativeModule internal/timers', 'NativeModule internal/url', 'NativeModule internal/util', diff --git a/test/parallel/test-source-map.js b/test/parallel/test-source-map.js index de728c05bf..41a315e3f8 100644 --- a/test/parallel/test-source-map.js +++ b/test/parallel/test-source-map.js @@ -30,7 +30,7 @@ function nextdir() { assert.strictEqual(output.status, 0); assert.strictEqual(output.stderr.toString(), ''); const sourceMap = getSourceMapFromCache('basic.js', coverageDirectory); - assert.strictEqual(sourceMap.url, 'https://http.cat/418'); + assert.strictEqual(sourceMap.url, 'https://ci.nodejs.org/418'); } // Outputs source maps when process.kill(process.pid, "SIGINT"); exits process. @@ -47,7 +47,7 @@ function nextdir() { } assert.strictEqual(output.stderr.toString(), ''); const sourceMap = getSourceMapFromCache('sigint.js', coverageDirectory); - assert.strictEqual(sourceMap.url, 'https://http.cat/402'); + assert.strictEqual(sourceMap.url, 'https://ci.nodejs.org/402'); } // Outputs source maps when source-file calls process.exit(1). @@ -58,7 +58,7 @@ function nextdir() { ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); assert.strictEqual(output.stderr.toString(), ''); const sourceMap = getSourceMapFromCache('exit-1.js', coverageDirectory); - assert.strictEqual(sourceMap.url, 'https://http.cat/404'); + assert.strictEqual(sourceMap.url, 'https://ci.nodejs.org/404'); } // Outputs source-maps for esm module. @@ -71,7 +71,7 @@ function nextdir() { ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); assert.strictEqual(output.stderr.toString(), ''); const sourceMap = getSourceMapFromCache('esm-basic.mjs', coverageDirectory); - assert.strictEqual(sourceMap.url, 'https://http.cat/405'); + assert.strictEqual(sourceMap.url, 'https://ci.nodejs.org/405'); } // Loads source-maps with relative path from .map file on disk. @@ -116,12 +116,95 @@ function nextdir() { ); } +// Does not apply source-map to stack trace if --experimental-modules +// is not set. +{ + const output = spawnSync(process.execPath, [ + require.resolve('../fixtures/source-map/uglify-throw.js') + ]); + assert.strictEqual( + output.stderr.toString().match(/->.*uglify-throw-original\.js:5:9/), + null + ); + assert.strictEqual( + output.stderr.toString().match(/->.*uglify-throw-original\.js:9:3/), + null + ); +} + +// Applies source-maps generated by uglifyjs to stack trace. +{ + const output = spawnSync(process.execPath, [ + '--enable-source-maps', + require.resolve('../fixtures/source-map/uglify-throw.js') + ]); + assert.ok( + output.stderr.toString().match(/->.*uglify-throw-original\.js:5:9/) + ); + assert.ok( + output.stderr.toString().match(/->.*uglify-throw-original\.js:9:3/) + ); +} + +// Applies source-maps generated by tsc to stack trace. +{ + const output = spawnSync(process.execPath, [ + '--enable-source-maps', + require.resolve('../fixtures/source-map/typescript-throw.js') + ]); + assert.ok(output.stderr.toString().match(/->.*typescript-throw\.ts:18:11/)); + assert.ok(output.stderr.toString().match(/->.*typescript-throw\.ts:24:1/)); +} + +// Applies source-maps generated by babel to stack trace. +{ + const output = spawnSync(process.execPath, [ + '--enable-source-maps', + require.resolve('../fixtures/source-map/babel-throw.js') + ]); + assert.ok( + output.stderr.toString().match(/->.*babel-throw-original\.js:18:31/) + ); +} + +// Applies source-maps generated by nyc to stack trace. +{ + const output = spawnSync(process.execPath, [ + '--enable-source-maps', + require.resolve('../fixtures/source-map/istanbul-throw.js') + ]); + assert.ok( + output.stderr.toString().match(/->.*istanbul-throw-original\.js:5:9/) + ); + assert.ok( + output.stderr.toString().match(/->.*istanbul-throw-original\.js:9:3/) + ); +} + +// Applies source-maps in esm modules to stack trace. +{ + const output = spawnSync(process.execPath, [ + '--enable-source-maps', + '--experimental-modules', + require.resolve('../fixtures/source-map/babel-esm.mjs') + ]); + assert.ok( + output.stderr.toString().match(/->.*babel-esm-original\.mjs:9:29/) + ); +} + function getSourceMapFromCache(fixtureFile, coverageDirectory) { const jsonFiles = fs.readdirSync(coverageDirectory); for (const jsonFile of jsonFiles) { - const maybeSourceMapCache = require( - path.join(coverageDirectory, jsonFile) - )['source-map-cache'] || {}; + let maybeSourceMapCache; + try { + maybeSourceMapCache = require( + path.join(coverageDirectory, jsonFile) + )['source-map-cache'] || {}; + } catch (err) { + console.warn(err); + maybeSourceMapCache = {}; + } const keys = Object.keys(maybeSourceMapCache); for (const key of keys) { if (key.includes(fixtureFile)) { |