From e363f8e17f6c68bebf6923cb1a0ad7b5510e9394 Mon Sep 17 00:00:00 2001 From: Nolik Date: Wed, 6 Nov 2019 18:43:53 +0300 Subject: [PATCH] process: add coverage tests for sourceMapFromDataUrl method PR-URL: https://github.com/nodejs/node/pull/30319 Reviewed-By: Anna Henningsen Reviewed-By: Ben Coe Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat Reviewed-By: Masashi Hirano --- .../source-map/inline-base64-json-error.js | 2 ++ .../source-map/inline-base64-type-error.js | 2 ++ test/parallel/test-source-map.js | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 test/fixtures/source-map/inline-base64-json-error.js create mode 100644 test/fixtures/source-map/inline-base64-type-error.js diff --git a/test/fixtures/source-map/inline-base64-json-error.js b/test/fixtures/source-map/inline-base64-json-error.js new file mode 100644 index 00000000000000..ba87a7208b0fd2 --- /dev/null +++ b/test/fixtures/source-map/inline-base64-json-error.js @@ -0,0 +1,2 @@ +var cov_263bu3eqm8=function(){var path= "./branches.js";var hash="424788076537d051b5bf0e2564aef393124eabc7";var global=new Function("return this")();var gcv="__coverage__";var coverageData={path: "./branches.js",statementMap:{"0":{start:{line:1,column:0},end:{line:7,column:1}},"1":{start:{line:2,column:2},end:{line:2,column:29}},"2":{start:{line:3,column:7},end:{line:7,column:1}},"3":{start:{line:4,column:2},end:{line:4,column:27}},"4":{start:{line:6,column:2},end:{line:6,column:29}},"5":{start:{line:10,column:2},end:{line:16,column:3}},"6":{start:{line:11,column:4},end:{line:11,column:28}},"7":{start:{line:12,column:9},end:{line:16,column:3}},"8":{start:{line:13,column:4},end:{line:13,column:31}},"9":{start:{line:15,column:4},end:{line:15,column:29}},"10":{start:{line:19,column:0},end:{line:19,column:12}},"11":{start:{line:20,column:0},end:{line:20,column:13}}},fnMap:{"0":{name:"branch",decl:{start:{line:9,column:9},end:{line:9,column:15}},loc:{start:{line:9,column:20},end:{line:17,column:1}},line:9}},branchMap:{"0":{loc:{start:{line:1,column:0},end:{line:7,column:1}},type:"if",locations:[{start:{line:1,column:0},end:{line:7,column:1}},{start:{line:1,column:0},end:{line:7,column:1}}],line:1},"1":{loc:{start:{line:3,column:7},end:{line:7,column:1}},type:"if",locations:[{start:{line:3,column:7},end:{line:7,column:1}},{start:{line:3,column:7},end:{line:7,column:1}}],line:3},"2":{loc:{start:{line:10,column:2},end:{line:16,column:3}},type:"if",locations:[{start:{line:10,column:2},end:{line:16,column:3}},{start:{line:10,column:2},end:{line:16,column:3}}],line:10},"3":{loc:{start:{line:12,column:9},end:{line:16,column:3}},type:"if",locations:[{start:{line:12,column:9},end:{line:16,column:3}},{start:{line:12,column:9},end:{line:16,column:3}}],line:12}},s:{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0},f:{"0":0},b:{"0":[0,0],"1":[0,0],"2":[0,0],"3":[0,0]},_coverageSchema:"43e27e138ebf9cfc5966b082cf9a028302ed4184",hash:"424788076537d051b5bf0e2564aef393124eabc7"};var coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}return coverage[path]=coverageData;}();cov_263bu3eqm8.s[0]++;if(false){cov_263bu3eqm8.b[0][0]++;cov_263bu3eqm8.s[1]++;console.info('unreachable');}else{cov_263bu3eqm8.b[0][1]++;cov_263bu3eqm8.s[2]++;if(true){cov_263bu3eqm8.b[1][0]++;cov_263bu3eqm8.s[3]++;console.info('reachable');}else{cov_263bu3eqm8.b[1][1]++;cov_263bu3eqm8.s[4]++;console.info('unreachable');}}function branch(a){cov_263bu3eqm8.f[0]++;cov_263bu3eqm8.s[5]++;if(a){cov_263bu3eqm8.b[2][0]++;cov_263bu3eqm8.s[6]++;console.info('a = true');}else{cov_263bu3eqm8.b[2][1]++;cov_263bu3eqm8.s[7]++;if(undefined){cov_263bu3eqm8.b[3][0]++;cov_263bu3eqm8.s[8]++;console.info('unreachable');}else{cov_263bu3eqm8.b[3][1]++;cov_263bu3eqm8.s[9]++;console.info('a = false');}}}cov_263bu3eqm8.s[10]++;branch(true);cov_263bu3eqm8.s[11]++;branch(false); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uOjMsInNvdXJjZXMiOlsiLi9icmFuY2hlcy5qcyJdLCJuYW1lcyI6WyJjb25zb2xlIiwiaW5mbyIsImJyYW5jaCIsImEiLCJ1bmRlZmluZWQiXSwibWFwcGluZ3MiOiJzdUVBQUEsR0FBSSxLQUFKLENBQVcsZ0RBQ1RBLE9BQU8sQ0FBQ0MsSUFBUixDQUFhLGFBQWIsRUFDRCxDQUZELElBRU8sbURBQUksSUFBSixDQUFVLGdEQUNmRCxPQUFPLENBQUNDLElBQVIsQ0FBYSxXQUFiLEVBQ0QsQ0FGTSxJQUVBLGdEQUNMRCxPQUFPLENBQUNDLElBQVIsQ0FBYSxhQUFiLEVBQ0QsRUFFRCxRQUFTQyxDQUFBQSxNQUFULENBQWlCQyxDQUFqQixDQUFvQiw2Q0FDbEIsR0FBSUEsQ0FBSixDQUFPLGdEQUNMSCxPQUFPLENBQUNDLElBQVIsQ0FBYSxVQUFiLEVBQ0QsQ0FGRCxJQUVPLG1EQUFJRyxTQUFKLENBQWUsZ0RBQ3BCSixPQUFPLENBQUNDLElBQVIsQ0FBYSxhQUFiLEVBQ0QsQ0FGTSxJQUVBLGdEQUNMRCxPQUFPLENBQUNDLElBQVIsQ0FBYSxXQUFiLEVBQ0QsRUFDRixDLHVCQUVEQyxNQUFNLENBQUMsSUFBRCxDQUFOLEMsdUJBQ0FBLE1BQU0sQ0FBQyxLQUFELENBQU4iLCJzb3VyY2VzQ29udGVudCI6WyJpZiAoZmFsc2UpIHtcbiAgY29uc29sZS5pbmZvKCd1bnJlYWNoYWJsZScpXG59IGVsc2UgaWYgKHRydWUpIHtcbiAgY29uc29sZS5pbmZvKCdyZWFjaGFibGUnKVxufSBlbHNlIHtcbiAgY29uc29sZS5pbmZvKCd1bnJlYWNoYWJsZScpXG59XG5cbmZ1bmN0aW9uIGJyYW5jaCAoYSkge1xuICBpZiAoYSkge1xuICAgIGNvbnNvbGUuaW5mbygnYSA9IHRydWUnKVxuICB9IGVsc2UgaWYgKHVuZGVmaW5lZCkge1xuICAgIGNvbnNvbGUuaW5mbygndW5yZWFjaGFibGUnKVxuICB9IGVsc2Uge1xuICAgIGNvbnNvbGUuaW5mbygnYSA9IGZhbHNlJylcbiAgfVxufVxuXG5icmFuY2godHJ1ZSlcbmJyYW5jaChmYWxzZSlcbiJdfQ== \ No newline at end of file diff --git a/test/fixtures/source-map/inline-base64-type-error.js b/test/fixtures/source-map/inline-base64-type-error.js new file mode 100644 index 00000000000000..2bc77ca54e0e40 --- /dev/null +++ b/test/fixtures/source-map/inline-base64-type-error.js @@ -0,0 +1,2 @@ +var cov_263bu3eqm8=function(){var path= "./branches.js";var hash="424788076537d051b5bf0e2564aef393124eabc7";var global=new Function("return this")();var gcv="__coverage__";var coverageData={path: "./branches.js",statementMap:{"0":{start:{line:1,column:0},end:{line:7,column:1}},"1":{start:{line:2,column:2},end:{line:2,column:29}},"2":{start:{line:3,column:7},end:{line:7,column:1}},"3":{start:{line:4,column:2},end:{line:4,column:27}},"4":{start:{line:6,column:2},end:{line:6,column:29}},"5":{start:{line:10,column:2},end:{line:16,column:3}},"6":{start:{line:11,column:4},end:{line:11,column:28}},"7":{start:{line:12,column:9},end:{line:16,column:3}},"8":{start:{line:13,column:4},end:{line:13,column:31}},"9":{start:{line:15,column:4},end:{line:15,column:29}},"10":{start:{line:19,column:0},end:{line:19,column:12}},"11":{start:{line:20,column:0},end:{line:20,column:13}}},fnMap:{"0":{name:"branch",decl:{start:{line:9,column:9},end:{line:9,column:15}},loc:{start:{line:9,column:20},end:{line:17,column:1}},line:9}},branchMap:{"0":{loc:{start:{line:1,column:0},end:{line:7,column:1}},type:"if",locations:[{start:{line:1,column:0},end:{line:7,column:1}},{start:{line:1,column:0},end:{line:7,column:1}}],line:1},"1":{loc:{start:{line:3,column:7},end:{line:7,column:1}},type:"if",locations:[{start:{line:3,column:7},end:{line:7,column:1}},{start:{line:3,column:7},end:{line:7,column:1}}],line:3},"2":{loc:{start:{line:10,column:2},end:{line:16,column:3}},type:"if",locations:[{start:{line:10,column:2},end:{line:16,column:3}},{start:{line:10,column:2},end:{line:16,column:3}}],line:10},"3":{loc:{start:{line:12,column:9},end:{line:16,column:3}},type:"if",locations:[{start:{line:12,column:9},end:{line:16,column:3}},{start:{line:12,column:9},end:{line:16,column:3}}],line:12}},s:{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0},f:{"0":0},b:{"0":[0,0],"1":[0,0],"2":[0,0],"3":[0,0]},_coverageSchema:"43e27e138ebf9cfc5966b082cf9a028302ed4184",hash:"424788076537d051b5bf0e2564aef393124eabc7"};var coverage=global[gcv]||(global[gcv]={});if(coverage[path]&&coverage[path].hash===hash){return coverage[path];}return coverage[path]=coverageData;}();cov_263bu3eqm8.s[0]++;if(false){cov_263bu3eqm8.b[0][0]++;cov_263bu3eqm8.s[1]++;console.info('unreachable');}else{cov_263bu3eqm8.b[0][1]++;cov_263bu3eqm8.s[2]++;if(true){cov_263bu3eqm8.b[1][0]++;cov_263bu3eqm8.s[3]++;console.info('reachable');}else{cov_263bu3eqm8.b[1][1]++;cov_263bu3eqm8.s[4]++;console.info('unreachable');}}function branch(a){cov_263bu3eqm8.f[0]++;cov_263bu3eqm8.s[5]++;if(a){cov_263bu3eqm8.b[2][0]++;cov_263bu3eqm8.s[6]++;console.info('a = true');}else{cov_263bu3eqm8.b[2][1]++;cov_263bu3eqm8.s[7]++;if(undefined){cov_263bu3eqm8.b[3][0]++;cov_263bu3eqm8.s[8]++;console.info('unreachable');}else{cov_263bu3eqm8.b[3][1]++;cov_263bu3eqm8.s[9]++;console.info('a = false');}}}cov_263bu3eqm8.s[10]++;branch(true);cov_263bu3eqm8.s[11]++;branch(false); +//# sourceMappingURL=data:application/text;charset=utf-8;base64,eyJ2ZX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lLmluZm8oJ3VucmVhY2hhYmxlJylcbiAgfSBlbHNlIHtcbiAgICBjb25zb2xlLmluZm8oJ2EgPSBmYWxzZScpXG4gIH1cbn1cblxuYnJhbmNoKHRydWUpXG5icmFuY2goZmFsc2UpXG4iXX0= diff --git a/test/parallel/test-source-map.js b/test/parallel/test-source-map.js index 2ded13a631dd8c..13fa391aafefcc 100644 --- a/test/parallel/test-source-map.js +++ b/test/parallel/test-source-map.js @@ -116,6 +116,38 @@ function nextdir() { ); } +// base64 encoding error does not crash application. +{ + const coverageDirectory = nextdir(); + const output = spawnSync(process.execPath, [ + require.resolve('../fixtures/source-map/inline-base64-type-error.js') + ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); + assert.strictEqual(output.status, 0); + assert.strictEqual(output.stderr.toString(), ''); + const sourceMap = getSourceMapFromCache( + 'inline-base64-type-error.js', + coverageDirectory + ); + + assert.strictEqual(sourceMap.data, null); +} + +// JSON error does not crash application. +{ + const coverageDirectory = nextdir(); + const output = spawnSync(process.execPath, [ + require.resolve('../fixtures/source-map/inline-base64-json-error.js') + ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); + assert.strictEqual(output.status, 0); + assert.strictEqual(output.stderr.toString(), ''); + const sourceMap = getSourceMapFromCache( + 'inline-base64-json-error.js', + coverageDirectory + ); + + assert.strictEqual(sourceMap.data, null); +} + // Does not apply source-map to stack trace if --experimental-modules // is not set. {