diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mocha/cli.js | 57 | ||||
-rw-r--r-- | test/mocha/sourcemaps.js | 40 |
2 files changed, 95 insertions, 2 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 8642a6b4..5f29bbdc 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -2,6 +2,7 @@ var assert = require("assert"); var exec = require("child_process").exec; var fs = require("fs"); var run_code = require("../sandbox").run_code; +var to_ascii = require("../node").to_ascii; function read(path) { return fs.readFileSync(path, "utf8"); @@ -48,6 +49,62 @@ describe("bin/uglifyjs", function() { done(); }); }); + it("Should work with --source-map names=true", function(done) { + exec([ + uglifyjscmd, + "--beautify", + "--source-map", [ + "names=true", + "url=inline", + ].join(","), + ].join(" "), function(err, stdout) { + if (err) throw err; + var expected = [ + "var obj = {", + " p: a,", + " q: b", + "};", + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,", + ].join("\n") + assert.strictEqual(stdout.slice(0, expected.length), expected); + var map = JSON.parse(to_ascii(stdout.slice(expected.length).trim())); + assert.deepEqual(map.names, [ "obj", "p", "a", "q", "b" ]); + done(); + }).stdin.end([ + "var obj = {", + " p: a,", + " q: b", + "};", + ].join("\n")); + }); + it("Should work with --source-map names=false", function(done) { + exec([ + uglifyjscmd, + "--beautify", + "--source-map", [ + "names=false", + "url=inline", + ].join(","), + ].join(" "), function(err, stdout) { + if (err) throw err; + var expected = [ + "var obj = {", + " p: a,", + " q: b", + "};", + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,", + ].join("\n") + assert.strictEqual(stdout.slice(0, expected.length), expected); + var map = JSON.parse(to_ascii(stdout.slice(expected.length).trim())); + assert.deepEqual(map.names, []); + done(); + }).stdin.end([ + "var obj = {", + " p: a,", + " q: b", + "};", + ].join("\n")); + }); it("Should give sensible error against invalid input source map", function(done) { var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline --verbose"; exec(command, function(err, stdout, stderr) { diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js index 23698c57..91b38cd2 100644 --- a/test/mocha/sourcemaps.js +++ b/test/mocha/sourcemaps.js @@ -7,11 +7,13 @@ function read(path) { } function source_map(code) { - return JSON.parse(UglifyJS.minify(code, { + var result = UglifyJS.minify(code, { compress: false, mangle: false, sourceMap: true, - }).map); + }); + if (result.error) throw result.error; + return JSON.parse(result.map); } function get_map() { @@ -65,6 +67,40 @@ describe("sourcemaps", function() { ].join("\n")); assert.deepEqual(map.names, [ "enabled", "x" ]); }); + it("Should work with sourceMap.names=true", function() { + var result = UglifyJS.minify([ + "var obj = {", + " p: a,", + " q: b", + "};", + ].join("\n"), { + compress: false, + mangle: false, + sourceMap: { + names: true, + }, + }); + if (result.error) throw result.error; + var map = JSON.parse(result.map); + assert.deepEqual(map.names, [ "obj", "p", "a", "q", "b" ]); + }); + it("Should work with sourceMap.names=false", function() { + var result = UglifyJS.minify([ + "var obj = {", + " p: a,", + " q: b", + "};", + ].join("\n"), { + compress: false, + mangle: false, + sourceMap: { + names: false, + }, + }); + if (result.error) throw result.error; + var map = JSON.parse(result.map); + assert.deepEqual(map.names, []); + }); it("Should mark array/object literals", function() { var result = UglifyJS.minify([ "var obj = {};", |