From c7271e4157a4628fbd10a512be53fb66672159f5 Mon Sep 17 00:00:00 2001 From: pengzhenqing Date: Mon, 10 Oct 2016 14:53:31 +0800 Subject: [PATCH] add tests about sourceMapInline --- test/input/issue-1323/sample.js | 7 +++++++ test/mocha/cli.js | 25 +++++++++++++++++++++++++ test/mocha/minify.js | 27 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 test/input/issue-1323/sample.js diff --git a/test/input/issue-1323/sample.js b/test/input/issue-1323/sample.js new file mode 100644 index 00000000..ff56acc3 --- /dev/null +++ b/test/input/issue-1323/sample.js @@ -0,0 +1,7 @@ +var bar = (function () { + function foo (bar) { + return bar; + } + + return foo; +})(); \ No newline at end of file diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 495b0076..1d08972a 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -49,4 +49,29 @@ describe("bin/uglifyjs", function () { done(); }); }); + it("Should append source map to output when using --source-map-inline", function (done) { + var command = uglifyjscmd + ' test/input/issue-1323/sample.js --source-map-inline'; + + exec(command, function (err, stdout) { + if (err) throw err; + + assert.doesNotThrow(function (){ + var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/; + var base64 = stdout.match(validate_source_map)[1]; + + var buf = new Buffer(base64, 'base64'); + var map = JSON.parse(buf.toString()); + done(); + }); + }); + }); + it("should not append source map to output when not using --source-map-inline", function (done) { + var command = uglifyjscmd + ' test/input/issue-1323/sample.js'; + + exec(command, function (err, stdout) { + var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/; + assert.strictEqual(false, validate_source_map.test(stdout)); + done(); + }); + }); }); diff --git a/test/mocha/minify.js b/test/mocha/minify.js index 2adbadcb..56c4c02a 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -75,4 +75,31 @@ describe("minify", function() { 'let foo = x => "foo " + x;\nconsole.log(foo("bar"));'); }); }); + + describe("sourceMapInline", function() { + it("should append source map to output js when sourceMapInline is enabled", function() { + var result = Uglify.minify('var a = function(foo) { return foo; };', { + fromString: true, + sourceMapInline: true + }); + var code = result.code; + + assert.doesNotThrow(function() { + var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/; + var base64 = code.match(validate_source_map)[1]; + + var buf = new Buffer(base64, 'base64'); + var map = JSON.parse(buf.toString()); + }) + }); + it("should not append source map to output js when sourceMapInline is not enabled", function() { + var result = Uglify.minify('var a = function(foo) { return foo; };', { + fromString: true + }); + + var code = result.code; + var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/; + assert.strictEqual(false, validate_source_map.test(code)); + }); + }); });