From a3b2eb75bd57e78305c418242c538c41acf010e7 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 8 May 2017 07:05:19 +0800 Subject: return `Error` from `minify()` (#1880) Have `minify()` return `Error` in `result.error` rather than throwing it. --- test/mocha/minify.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/mocha/minify.js b/test/mocha/minify.js index d69ef59c..7812fe6b 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -114,17 +114,18 @@ describe("minify", function() { } }); it("Should fail with multiple input and inline source map", function() { - assert.throws(function() { - Uglify.minify([ - read("./test/input/issue-520/input.js"), - read("./test/input/issue-520/output.js") - ], { - sourceMap: { - content: "inline", - url: "inline" - } - }); + var result = Uglify.minify([ + read("./test/input/issue-520/input.js"), + read("./test/input/issue-520/output.js") + ], { + sourceMap: { + content: "inline", + url: "inline" + } }); + var err = result.error; + assert.ok(err instanceof Error); + assert.strictEqual(err.stack.split(/\n/)[0], "Error: inline source map only works with singular input"); }); }); @@ -170,17 +171,14 @@ describe("minify", function() { }); describe("JS_Parse_Error", function() { - it("should throw syntax error", function() { - assert.throws(function() { - Uglify.minify("function f(a{}"); - }, function(err) { - assert.ok(err instanceof Error); - assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token punc «{», expected punc «,»"); - assert.strictEqual(err.filename, "0"); - assert.strictEqual(err.line, 1); - assert.strictEqual(err.col, 12); - return true; - }); + it("should return syntax error", function() { + var result = Uglify.minify("function f(a{}"); + var err = result.error; + assert.ok(err instanceof Error); + assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token punc «{», expected punc «,»"); + assert.strictEqual(err.filename, "0"); + assert.strictEqual(err.line, 1); + assert.strictEqual(err.col, 12); }); }); }); -- cgit v1.2.3