diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-04-30 06:32:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-30 06:32:24 +0800 |
commit | 2ea96549c55c44935c05fcaf6c68119d0eef4c8e (patch) | |
tree | 89a3ab9e15c3b250858f9d1c590816675cf93c5f /test/mocha | |
parent | fba008e2989de0611d144a1ec91d9eb1c9b2b479 (diff) | |
download | tracifyjs-2ea96549c55c44935c05fcaf6c68119d0eef4c8e.tar.gz tracifyjs-2ea96549c55c44935c05fcaf6c68119d0eef4c8e.zip |
unify logging functionality (#3392)
fixes #3253
fixes #3254
Diffstat (limited to 'test/mocha')
-rw-r--r-- | test/mocha/cli.js | 10 | ||||
-rw-r--r-- | test/mocha/sourcemaps.js | 68 |
2 files changed, 31 insertions, 47 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 811c493f..6d6e1e80 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -47,7 +47,7 @@ describe("bin/uglifyjs", function() { }); }); it("Should give sensible error against invalid input source map", function(done) { - var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline"; + var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline --verbose"; exec(command, function(err, stdout, stderr) { assert.ok(err); assert.deepEqual(stderr.split(/\n/).slice(0, 2), [ @@ -83,6 +83,7 @@ describe("bin/uglifyjs", function() { "test/input/issue-2082/sample.js", "--source-map", "content=test/input/issue-2082/sample.js.map", "--source-map", "url=inline", + "--verbose", ].join(" "); exec(command, function(err, stdout, stderr) { if (err) throw err; @@ -202,7 +203,7 @@ describe("bin/uglifyjs", function() { }); }); it("Should warn for missing inline source map", function(done) { - var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline"; + var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline --warn"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, [ @@ -221,6 +222,7 @@ describe("bin/uglifyjs", function() { "test/input/issue-520/input.js", "test/input/issue-1323/sample.js", "--source-map", "content=inline,url=inline", + "--warn", ].join(" "); exec(command, function(err, stdout, stderr) { if (err) throw err; @@ -466,7 +468,7 @@ describe("bin/uglifyjs", function() { done(); }); }); - it("Should throw syntax error (catch(eval))", function(done) { + it("Should throw syntax error (catch (eval))", function(done) { var command = uglifyjscmd + ' test/input/invalid/try.js'; exec(command, function(err, stdout, stderr) { assert.ok(err); @@ -647,7 +649,7 @@ describe("bin/uglifyjs", function() { exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); - assert.strictEqual(stderr, "Error parsing arguments for 'define': a-b\n"); + assert.strictEqual(stderr, "ERROR: cannot parse arguments for 'define': a-b\n"); done(); }); }); diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js index ccaa68e1..f625b227 100644 --- a/test/mocha/sourcemaps.js +++ b/test/mocha/sourcemaps.js @@ -118,51 +118,33 @@ describe("sourcemaps", function() { assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-520/output.js", "utf8")); }); it("Should warn for missing inline source map", function() { - var warn_function = UglifyJS.AST_Node.warn_function; - var warnings = []; - UglifyJS.AST_Node.warn_function = function(txt) { - warnings.push(txt); - }; - try { - var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), { - mangle: false, - sourceMap: { - content: "inline" - } - }); - assert.strictEqual(result.code, "var bar=function(bar){return bar};"); - assert.strictEqual(warnings.length, 1); - assert.strictEqual(warnings[0], "inline source map not found: 0"); - } finally { - UglifyJS.AST_Node.warn_function = warn_function; - } + var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), { + mangle: false, + sourceMap: { + content: "inline" + }, + warnings: true, + }); + assert.strictEqual(result.code, "var bar=function(bar){return bar};"); + assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 0" ]); }); it("Should handle multiple input and inline source map", function() { - var warn_function = UglifyJS.AST_Node.warn_function; - var warnings = []; - UglifyJS.AST_Node.warn_function = function(txt) { - warnings.push(txt); - }; - try { - var result = UglifyJS.minify([ - read("./test/input/issue-520/input.js"), - read("./test/input/issue-1323/sample.js"), - ], { - sourceMap: { - content: "inline", - url: "inline", - } - }); - if (result.error) throw result.error; - assert.strictEqual(result.code, [ - "var Foo=function(){console.log(3)};new Foo;var bar=function(o){return o};", - "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElBQVMsSUFBSUYsSUNBbkQsSUFBSUcsSUFDQSxTQUFjQSxHQUNWLE9BQU9BIn0=", - ].join("\n")); - assert.strictEqual(warnings.length, 1); - assert.strictEqual(warnings[0], "inline source map not found: 1"); - } finally { - UglifyJS.AST_Node.warn_function = warn_function; - } + var result = UglifyJS.minify([ + read("./test/input/issue-520/input.js"), + read("./test/input/issue-1323/sample.js"), + ], { + sourceMap: { + content: "inline", + url: "inline", + }, + warnings: true, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, [ + "var Foo=function(){console.log(3)};new Foo;var bar=function(o){return o};", + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElBQVMsSUFBSUYsSUNBbkQsSUFBSUcsSUFDQSxTQUFjQSxHQUNWLE9BQU9BIn0=", + ].join("\n")); + assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 1" ]); }); it("Should drop source contents for includeSources=false", function() { var result = UglifyJS.minify(read("./test/input/issue-520/input.js"), { |