diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-06-06 17:50:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-06 17:50:56 +0800 |
commit | 9e19e63551907be19c8c6b5b75217d7650504436 (patch) | |
tree | 9c545c0e02d16c73a19c96f44b191af4f1eaff0e /test/mocha | |
parent | bce7ee5f6a28e87e2e68cd2d22b4e4280372d7bb (diff) | |
download | tracifyjs-9e19e63551907be19c8c6b5b75217d7650504436.tar.gz tracifyjs-9e19e63551907be19c8c6b5b75217d7650504436.zip |
general clean-ups (#3175)
Diffstat (limited to 'test/mocha')
-rw-r--r-- | test/mocha/cli.js | 212 | ||||
-rw-r--r-- | test/mocha/getter-setter.js | 11 | ||||
-rw-r--r-- | test/mocha/ie8.js | 21 | ||||
-rw-r--r-- | test/mocha/number-literal.js | 13 | ||||
-rw-r--r-- | test/mocha/screw-ie8.js | 21 | ||||
-rw-r--r-- | test/mocha/sourcemaps.js | 12 |
6 files changed, 113 insertions, 177 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 2e1c3b64..3bc92c30 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -8,58 +8,46 @@ function read(path) { describe("bin/uglifyjs", function() { var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; - it("should produce a functional build when using --self", function (done) { + it("should produce a functional build when using --self", function(done) { this.timeout(30000); - var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - eval(stdout); - - assert.strictEqual(typeof WrappedUglifyJS, 'object'); + assert.strictEqual(typeof WrappedUglifyJS, "object"); var result = WrappedUglifyJS.minify("foo([true,,2+3]);"); assert.strictEqual(result.error, undefined); assert.strictEqual(result.code, "foo([!0,,5]);"); - done(); }); }); - it("Should be able to filter comments correctly with `--comments all`", function (done) { + it("Should be able to filter comments correctly with `--comments all`", function(done) { var command = uglifyjscmd + ' test/input/comments/filter.js --comments all'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "// foo\n/*@preserve*/\n// bar\n\n"); done(); }); }); - it("Should be able to filter comments correctly with `--comment <RegExp>`", function (done) { + it("Should be able to filter comments correctly with `--comment <RegExp>`", function(done) { var command = uglifyjscmd + ' test/input/comments/filter.js --comments /r/'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "/*@preserve*/\n// bar\n\n"); done(); }); }); - it("Should be able to filter comments correctly with just `--comment`", function (done) { + it("Should be able to filter comments correctly with just `--comment`", function(done) { var command = uglifyjscmd + ' test/input/comments/filter.js --comments'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "/*@preserve*/\n\n"); done(); }); }); it("Should give sensible error against invalid input source map", function(done) { var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline"; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.deepEqual(stderr.split(/\n/).slice(0, 2), [ "INFO: Using input source map: blah", @@ -68,38 +56,35 @@ describe("bin/uglifyjs", function() { done(); }); }); - it("Should append source map to output when using --source-map url=inline", function (done) { + it("Should append source map to output when using --source-map url=inline", function(done) { var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map url=inline"; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - - assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n" + - "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==\n"); + assert.strictEqual(stdout, [ + "var bar=function(){function foo(bar){return bar}return foo}();", + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==", + "", + ].join("\n")); done(); }); }); - it("should not append source map to output when not using --source-map url=inline", function (done) { + it("should not append source map to output when not using --source-map url=inline", function(done) { var command = uglifyjscmd + ' test/input/issue-1323/sample.js'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n"); done(); }); }); - it("should not consider source map file content as source map file name (issue #2082)", function (done) { + it("should not consider source map file content as source map file name (issue #2082)", function(done) { var command = [ uglifyjscmd, "test/input/issue-2082/sample.js", "--source-map", "content=test/input/issue-2082/sample.js.map", "--source-map", "url=inline", ].join(" "); - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { if (err) throw err; - var stderrLines = stderr.split("\n"); assert.strictEqual(stderrLines[0], "INFO: Using input source map: test/input/issue-2082/sample.js.map"); assert.notStrictEqual(stderrLines[1], 'INFO: Using input source map: {"version": 3,"sources": ["index.js"],"mappings": ";"}'); @@ -136,82 +121,66 @@ describe("bin/uglifyjs", function() { child.stdin.end(read("test/input/pr-3040/input.js")); }, 1000); }); - it("Should work with --keep-fnames (mangle only)", function (done) { + it("Should work with --keep-fnames (mangle only)", function(done) { var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n"); done(); }); }); - it("Should work with --keep-fnames (mangle & compress)", function (done) { + it("Should work with --keep-fnames (mangle & compress)", function(done) { var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c unused=false'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(5==f(g)());\n"); done(); }); }); - it("Should work with keep_fnames under mangler options", function (done) { + it("Should work with keep_fnames under mangler options", function(done) { var command = uglifyjscmd + ' test/input/issue-1431/sample.js -m keep_fnames=true'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n"); done(); }); }); - it("Should work with --define (simple)", function (done) { + it("Should work with --define (simple)", function(done) { var command = uglifyjscmd + ' test/input/global_defs/simple.js --define D=5 -c'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "console.log(5);\n"); done(); }); }); - it("Should work with --define (nested)", function (done) { + it("Should work with --define (nested)", function(done) { var command = uglifyjscmd + ' test/input/global_defs/nested.js --define C.D=5,C.V=3 -c'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "console.log(3,5);\n"); done(); }); }); - it("Should work with --define (AST_Node)", function (done) { + it("Should work with --define (AST_Node)", function(done) { var command = uglifyjscmd + ' test/input/global_defs/simple.js --define console.log=stdout.println -c'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, "stdout.println(D);\n"); done(); }); }); - it("Should work with `--beautify`", function (done) { + it("Should work with `--beautify`", function(done) { var command = uglifyjscmd + ' test/input/issue-1482/input.js -b'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, read("test/input/issue-1482/default.js")); done(); }); }); - it("Should work with `--beautify braces`", function (done) { + it("Should work with `--beautify braces`", function(done) { var command = uglifyjscmd + ' test/input/issue-1482/input.js -b braces'; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, read("test/input/issue-1482/braces.js")); done(); }); @@ -225,20 +194,16 @@ describe("bin/uglifyjs", function() { "--source-map", "includeSources=true", "--source-map", "url=inline", ].join(" "); - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, read("test/input/issue-520/output.js")); done(); }); }); 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"; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { if (err) throw err; - assert.strictEqual(stdout, [ "var bar=function(){function foo(bar){return bar}return foo}();", "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==", @@ -256,10 +221,8 @@ describe("bin/uglifyjs", function() { "test/input/issue-1323/sample.js", "--source-map", "content=inline,url=inline", ].join(" "); - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { if (err) throw err; - assert.strictEqual(stdout, [ "var Foo=function Foo(){console.log(1+2)};new Foo;var bar=function(){function foo(bar){return bar}return foo}();", "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwidGVzdC9pbnB1dC9pc3N1ZS0xMzIzL3NhbXBsZS5qcyJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFNBQUFBLE1BQWdCQyxRQUFRQyxJQUFJLEVBQUUsSUFBTyxJQUFJRixJQ0FuRCxJQUFJRyxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==", @@ -272,8 +235,7 @@ describe("bin/uglifyjs", function() { }); it("Should fail with acorn and inline source map", function(done) { var command = uglifyjscmd + " test/input/issue-520/input.js --source-map content=inline,url=inline -p acorn"; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stderr, "ERROR: inline source map only works with built-in parser\n"); done(); @@ -281,8 +243,7 @@ describe("bin/uglifyjs", function() { }); it("Should fail with SpiderMonkey and inline source map", function(done) { var command = uglifyjscmd + " test/input/issue-520/input.js --source-map content=inline,url=inline -p spidermonkey"; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stderr, "ERROR: inline source map only works with built-in parser\n"); done(); @@ -290,8 +251,7 @@ describe("bin/uglifyjs", function() { }); it("Should fail with invalid syntax", function(done) { var command = uglifyjscmd + ' test/input/invalid/simple.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); var lines = stderr.split(/\n/); assert.strictEqual(lines[0], "Parse error at test/input/invalid/simple.js:1,12"); @@ -303,8 +263,7 @@ describe("bin/uglifyjs", function() { }); it("Should fail with correct marking of tabs", function(done) { var command = uglifyjscmd + ' test/input/invalid/tab.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); var lines = stderr.split(/\n/); assert.strictEqual(lines[0], "Parse error at test/input/invalid/tab.js:1,12"); @@ -316,8 +275,7 @@ describe("bin/uglifyjs", function() { }); it("Should fail with correct marking at start of line", function(done) { var command = uglifyjscmd + ' test/input/invalid/eof.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); var lines = stderr.split(/\n/); assert.strictEqual(lines[0], "Parse error at test/input/invalid/eof.js:2,0"); @@ -329,8 +287,7 @@ describe("bin/uglifyjs", function() { }); it("Should fail with a missing loop body", function(done) { var command = uglifyjscmd + ' test/input/invalid/loop-no-body.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); var lines = stderr.split(/\n/); assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0"); @@ -342,8 +299,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (5--)", function(done) { var command = uglifyjscmd + ' test/input/invalid/assign_1.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -357,8 +313,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (Math.random() /= 2)", function(done) { var command = uglifyjscmd + ' test/input/invalid/assign_2.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -372,8 +327,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (++this)", function(done) { var command = uglifyjscmd + ' test/input/invalid/assign_3.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -387,8 +341,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (++null)", function(done) { var command = uglifyjscmd + ' test/input/invalid/assign_4.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -402,8 +355,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (a.=)", function(done) { var command = uglifyjscmd + ' test/input/invalid/dot_1.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -417,8 +369,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (%.a)", function(done) { var command = uglifyjscmd + ' test/input/invalid/dot_2.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -432,8 +383,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (a./();)", function(done) { var command = uglifyjscmd + ' test/input/invalid/dot_3.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -447,8 +397,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error ({%: 1})", function(done) { var command = uglifyjscmd + ' test/input/invalid/object.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -462,8 +411,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (delete x)", function(done) { var command = uglifyjscmd + ' test/input/invalid/delete.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -477,8 +425,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (function g(arguments))", function(done) { var command = uglifyjscmd + ' test/input/invalid/function_1.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -492,8 +439,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (function eval())", function(done) { var command = uglifyjscmd + ' test/input/invalid/function_2.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -507,8 +453,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (iife arguments())", function(done) { var command = uglifyjscmd + ' test/input/invalid/function_3.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -522,8 +467,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (catch(eval))", function(done) { var command = uglifyjscmd + ' test/input/invalid/try.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -537,8 +481,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (var eval)", function(done) { var command = uglifyjscmd + ' test/input/invalid/var.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -552,8 +495,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (else)", function(done) { var command = uglifyjscmd + ' test/input/invalid/else.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -567,8 +509,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (return)", function(done) { var command = uglifyjscmd + ' test/input/invalid/return.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -582,8 +523,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (for-in init)", function(done) { var command = uglifyjscmd + ' test/input/invalid/for-in_1.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -597,8 +537,7 @@ describe("bin/uglifyjs", function() { }); it("Should throw syntax error (for-in var)", function(done) { var command = uglifyjscmd + ' test/input/invalid/for-in_2.js'; - - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ @@ -617,10 +556,8 @@ describe("bin/uglifyjs", function() { "--source-map", 'content="' + read_map() + '",url=inline' ].join(" "); - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, [ '"use strict";var foo=function foo(x){return"foo "+x};console.log(foo("bar"));', "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LmpzIl0sIm5hbWVzIjpbImZvbyIsIngiLCJjb25zb2xlIiwibG9nIl0sIm1hcHBpbmdzIjoiYUFBQSxJQUFJQSxJQUFNLFNBQU5BLElBQU1DLEdBQUEsTUFBSyxPQUFTQSxHQUN4QkMsUUFBUUMsSUFBSUgsSUFBSSJ9", @@ -642,10 +579,8 @@ describe("bin/uglifyjs", function() { "-c", "--source-map", "url=inline", ].join(" "); - exec(command, function(err, stdout, stderr) { if (err) throw err; - assert.strictEqual(stdout, [ 'function foo(){return function(){console.log("PASS")}}foo()();', "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMjMxMC9pbnB1dC5qcyJdLCJuYW1lcyI6WyJmb28iLCJjb25zb2xlIiwibG9nIiwiZiJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsTUFDTCxPQUFPLFdBQ0hDLFFBQVFDLElBQUksU0FLUkYsS0FDUkcifQ==", @@ -656,9 +591,8 @@ describe("bin/uglifyjs", function() { }); it("Should dump AST as JSON", function(done) { var command = uglifyjscmd + " test/input/global_defs/simple.js -mco ast"; - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - var ast = JSON.parse(stdout); assert.strictEqual(ast._class, "AST_Toplevel"); assert.ok(Array.isArray(ast.body)); @@ -667,7 +601,7 @@ describe("bin/uglifyjs", function() { }); it("Should print supported options on invalid option syntax", function(done) { var command = uglifyjscmd + " test/input/comments/filter.js -b ascii-only"; - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.ok(/^Supported options:\n[\s\S]*?\nERROR: `ascii-only` is not a supported option/.test(stderr), stderr); @@ -676,27 +610,23 @@ describe("bin/uglifyjs", function() { }); it("Should work with --mangle reserved=[]", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=[callback]"; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, 'function test(callback){"aaaaaaaaaaaaaaaa";callback(err,data);callback(err,data)}\n'); done(); }); }); it("Should work with --mangle reserved=false", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=false"; - - exec(command, function (err, stdout) { + exec(command, function(err, stdout) { if (err) throw err; - assert.strictEqual(stdout, 'function test(a){"aaaaaaaaaaaaaaaa";a(err,data);a(err,data)}\n'); done(); }); }); it("Should fail with --mangle-props reserved=[in]", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js --mangle-props reserved=[in]"; - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.ok(/^Supported options:\n[\s\S]*?\nERROR: `reserved=\[in]` is not a supported option/.test(stderr), stderr); @@ -705,7 +635,7 @@ describe("bin/uglifyjs", function() { }); it("Should fail with --define a-b", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b"; - exec(command, function (err, stdout, stderr) { + exec(command, function(err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr, "Error parsing arguments for 'define': a-b\n"); diff --git a/test/mocha/getter-setter.js b/test/mocha/getter-setter.js index fe0481b3..cd4433e0 100644 --- a/test/mocha/getter-setter.js +++ b/test/mocha/getter-setter.js @@ -61,29 +61,24 @@ describe("Getters and setters", function() { return results; }; - var testCase = function(data) { return function() { UglifyJS.parse(data.code); }; }; - var fail = function(data) { - return function (e) { - return e instanceof UglifyJS.JS_Parse_Error && - e.message === "Unexpected token: operator (" + data.operator + ")"; + return function(e) { + return e instanceof UglifyJS.JS_Parse_Error + && e.message === "Unexpected token: operator (" + data.operator + ")"; }; }; - var errorMessage = function(data) { return "Expected but didn't get a syntax error while parsing following line:\n" + data.code; }; - var tests = generator(); for (var i = 0; i < tests.length; i++) { var test = tests[i]; assert.throws(testCase(test), fail(test), errorMessage(test)); } }); - }); diff --git a/test/mocha/ie8.js b/test/mocha/ie8.js new file mode 100644 index 00000000..8f3a27fa --- /dev/null +++ b/test/mocha/ie8.js @@ -0,0 +1,21 @@ +var assert = require("assert"); +var uglify = require("../../"); + +describe("ie8", function() { + it("Should be able to minify() with undefined as catch parameter in a try...catch statement", function() { + assert.strictEqual( + uglify.minify([ + "function a(b){", + " try {", + " throw 'Stuff';", + " } catch (undefined) {", + " console.log('caught: ' + undefined);", + " }", + " console.log('undefined is ' + undefined);", + " return b === undefined;", + "};", + ].join("\n")).code, + 'function a(o){try{throw"Stuff"}catch(o){console.log("caught: "+o)}return console.log("undefined is "+void 0),void 0===o}' + ); + }); +}); diff --git a/test/mocha/number-literal.js b/test/mocha/number-literal.js index f4e2f5dd..eb2b407d 100644 --- a/test/mocha/number-literal.js +++ b/test/mocha/number-literal.js @@ -1,24 +1,23 @@ var assert = require("assert"); var uglify = require("../node"); -describe("Number literals", function () { +describe("Number literals", function() { it("Should not allow legacy octal literals in strict mode", function() { var inputs = [ '"use strict";00;', '"use strict"; var foo = 00;' ]; - var test = function(input) { return function() { uglify.parse(input); } - } + }; var error = function(e) { - return e instanceof uglify.JS_Parse_Error && - e.message === "Legacy octal literals are not allowed in strict mode"; - } + return e instanceof uglify.JS_Parse_Error + && e.message === "Legacy octal literals are not allowed in strict mode"; + }; for (var i = 0; i < inputs.length; i++) { assert.throws(test(inputs[i]), error, inputs[i]); } }); -});
\ No newline at end of file +}); diff --git a/test/mocha/screw-ie8.js b/test/mocha/screw-ie8.js deleted file mode 100644 index e120a475..00000000 --- a/test/mocha/screw-ie8.js +++ /dev/null @@ -1,21 +0,0 @@ -var assert = require("assert"); -var uglify = require("../../"); - -describe("screw-ie8", function () { - it("Should be able to minify() with undefined as catch parameter in a try...catch statement", function () { - assert.strictEqual( - uglify.minify( - "function a(b){\ - try {\ - throw 'Stuff';\ - } catch (undefined) {\ - console.log('caught: ' + undefined);\ - }\ - console.log('undefined is ' + undefined);\ - return b === undefined;\ - };" - ).code, - 'function a(o){try{throw"Stuff"}catch(o){console.log("caught: "+o)}return console.log("undefined is "+void 0),void 0===o}' - ); - }); -}); diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js index 8d8c18df..8590b308 100644 --- a/test/mocha/sourcemaps.js +++ b/test/mocha/sourcemaps.js @@ -48,6 +48,18 @@ describe("sourcemaps", function() { assert.strictEqual(result.map, '{"version":3,"sources":["0"],"names":["wat"],"mappings":"CAAU,IACNA,IAAI"}'); }); + it("Should give correct sourceRoot", function() { + var code = "console.log(42);"; + var result = Uglify.minify(code, { + sourceMap: { + root: "//foo.bar/", + }, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, code); + assert.strictEqual(result.map, '{"version":3,"sources":["0"],"names":["console","log"],"mappings":"AAAAA,QAAQC,IAAI","sourceRoot":"//foo.bar/"}'); + }); + describe("inSourceMap", function() { it("Should read the given string filename correctly when sourceMapIncludeSources is enabled (#1236)", function() { var result = Uglify.minify(read("./test/input/issue-1236/simple.js"), { |