diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-06-22 01:04:15 +0800 |
---|---|---|
committer | alexlamsl <alexlamsl@gmail.com> | 2018-06-24 04:00:36 +0800 |
commit | 28330913d871dd4bdb4e59464c7230f9ae4174fa (patch) | |
tree | 32fba882ce0d546d14f461677c56e771e10f02e1 /test/mocha/minify.js | |
parent | 766a4147d4891a093b550e958268c48104330b52 (diff) | |
download | tracifyjs-28330913d871dd4bdb4e59464c7230f9ae4174fa.tar.gz tracifyjs-28330913d871dd4bdb4e59464c7230f9ae4174fa.zip |
improve `mocha` tests (#3195)
Diffstat (limited to 'test/mocha/minify.js')
-rw-r--r-- | test/mocha/minify.js | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/test/mocha/minify.js b/test/mocha/minify.js index f394cc62..1871ed71 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -1,7 +1,7 @@ -var Uglify = require('../../'); var assert = require("assert"); var readFileSync = require("fs").readFileSync; var run_code = require("../sandbox").run_code; +var UglifyJS = require("../../"); function read(path) { return readFileSync(path, "utf8"); @@ -10,14 +10,14 @@ function read(path) { describe("minify", function() { it("Should test basic sanity of minify with default options", function() { var js = 'function foo(bar) { if (bar) return 3; else return 7; var u = not_called(); }'; - var result = Uglify.minify(js); + var result = UglifyJS.minify(js); assert.strictEqual(result.code, 'function foo(n){return n?3:7}'); }); it("Should skip inherited keys from `files`", function() { var files = Object.create({ skip: this }); files[0] = "alert(1 + 1)"; - var result = Uglify.minify(files); + var result = UglifyJS.minify(files); assert.strictEqual(result.code, "alert(2);"); }); @@ -32,7 +32,7 @@ describe("minify", function() { "qux.js", ].forEach(function(file) { var code = read("test/input/issue-1242/" + file); - var result = Uglify.minify(code, { + var result = UglifyJS.minify(code, { mangle: { cache: cache, toplevel: true @@ -65,7 +65,7 @@ describe("minify", function() { "qux.js", ].forEach(function(file) { var code = read("test/input/issue-1242/" + file); - var result = Uglify.minify(code, { + var result = UglifyJS.minify(code, { mangle: { toplevel: true }, @@ -96,7 +96,7 @@ describe("minify", function() { '"xxyyy";var j={t:2,u:3},k=4;', 'console.log(i.s,j.t,j.u,k);', ].forEach(function(code) { - var result = Uglify.minify(code, { + var result = UglifyJS.minify(code, { compress: false, mangle: { properties: true, @@ -117,15 +117,15 @@ describe("minify", function() { }); it("Should not parse invalid use of reserved words", function() { - assert.strictEqual(Uglify.minify("function enum(){}").error, undefined); - assert.strictEqual(Uglify.minify("function static(){}").error, undefined); - assert.strictEqual(Uglify.minify("function this(){}").error.message, "Unexpected token: name (this)"); + assert.strictEqual(UglifyJS.minify("function enum(){}").error, undefined); + assert.strictEqual(UglifyJS.minify("function static(){}").error, undefined); + assert.strictEqual(UglifyJS.minify("function this(){}").error.message, "Unexpected token: name (this)"); }); describe("keep_quoted_props", function() { it("Should preserve quotes in object literals", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; - var result = Uglify.minify(js, { + var result = UglifyJS.minify(js, { output: { keep_quoted_props: true }}); @@ -134,7 +134,7 @@ describe("minify", function() { it("Should preserve quote styles when quote_style is 3", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; - var result = Uglify.minify(js, { + var result = UglifyJS.minify(js, { output: { keep_quoted_props: true, quote_style: 3 @@ -144,7 +144,7 @@ describe("minify", function() { it("Should not preserve quotes in object literals when disabled", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; - var result = Uglify.minify(js, { + var result = UglifyJS.minify(js, { output: { keep_quoted_props: false, quote_style: 3 @@ -156,7 +156,7 @@ describe("minify", function() { describe("mangleProperties", function() { it("Shouldn't mangle quoted properties", function() { var js = 'a["foo"] = "bar"; a.color = "red"; x = {"bar": 10};'; - var result = Uglify.minify(js, { + var result = UglifyJS.minify(js, { compress: { properties: false }, @@ -174,7 +174,7 @@ describe("minify", function() { 'a["foo"]="bar",a.a="red",x={"bar":10};'); }); it("Should not mangle quoted property within dead code", function() { - var result = Uglify.minify('({ "keep": 1 }); g.keep = g.change;', { + var result = UglifyJS.minify('({ "keep": 1 }); g.keep = g.change;', { mangle: { properties: { keep_quoted: true @@ -188,7 +188,7 @@ describe("minify", function() { describe("#__PURE__", function() { it("should drop #__PURE__ hint after use", function() { - var result = Uglify.minify('//@__PURE__ comment1 #__PURE__ comment2\n foo(), bar();', { + var result = UglifyJS.minify('//@__PURE__ comment1 #__PURE__ comment2\n foo(), bar();', { output: { comments: "all", beautify: false, @@ -198,7 +198,7 @@ describe("minify", function() { assert.strictEqual(code, "// comment1 comment2\nbar();"); }); it("should drop #__PURE__ hint if function is retained", function() { - var result = Uglify.minify("var a = /*#__PURE__*/(function(){ foo(); })();", { + var result = UglifyJS.minify("var a = /*#__PURE__*/(function(){ foo(); })();", { output: { comments: "all", beautify: false, @@ -211,7 +211,7 @@ describe("minify", function() { describe("JS_Parse_Error", function() { it("should return syntax error", function() { - var result = Uglify.minify("function f(a{}"); + var result = UglifyJS.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 «,»"); @@ -220,7 +220,7 @@ describe("minify", function() { assert.strictEqual(err.col, 12); }); it("should reject duplicated label name", function() { - var result = Uglify.minify("L:{L:{}}"); + var result = UglifyJS.minify("L:{L:{}}"); var err = result.error; assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Label L defined twice"); @@ -232,7 +232,7 @@ describe("minify", function() { describe("global_defs", function() { it("should throw for non-trivial expressions", function() { - var result = Uglify.minify("alert(42);", { + var result = UglifyJS.minify("alert(42);", { compress: { global_defs: { "@alert": "debugger" @@ -246,7 +246,7 @@ describe("minify", function() { it("should skip inherited properties", function() { var foo = Object.create({ skip: this }); foo.bar = 42; - var result = Uglify.minify("alert(FOO);", { + var result = UglifyJS.minify("alert(FOO);", { compress: { global_defs: { FOO: foo @@ -266,7 +266,7 @@ describe("minify", function() { "}", "f();", ].join("\n"); - var ast = Uglify.minify(code, { + var ast = UglifyJS.minify(code, { compress: false, mangle: false, output: { @@ -279,7 +279,7 @@ describe("minify", function() { assert.strictEqual(ast.body[0].body.length, 2); assert.strictEqual(ast.body[0].body[0].TYPE, "SimpleStatement"); var stat = ast.body[0].body[0]; - Uglify.minify(ast, { + UglifyJS.minify(ast, { compress: { sequences: false }, @@ -294,7 +294,7 @@ describe("minify", function() { it("Should be repeatable", function() { var code = "!function(x){return x(x)}(y);"; for (var i = 0; i < 2; i++) { - assert.strictEqual(Uglify.minify(code, { + assert.strictEqual(UglifyJS.minify(code, { compress: { toplevel: true, }, @@ -307,7 +307,7 @@ describe("minify", function() { describe("enclose", function() { var code = read("test/input/enclose/input.js"); it("Should work with true", function() { - var result = Uglify.minify(code, { + var result = UglifyJS.minify(code, { compress: false, enclose: true, mangle: false, @@ -316,7 +316,7 @@ describe("minify", function() { assert.strictEqual(result.code, '(function(){function enclose(){console.log("test enclose")}enclose()})();'); }); it("Should work with arg", function() { - var result = Uglify.minify(code, { + var result = UglifyJS.minify(code, { compress: false, enclose: 'undefined', mangle: false, @@ -325,7 +325,7 @@ describe("minify", function() { assert.strictEqual(result.code, '(function(undefined){function enclose(){console.log("test enclose")}enclose()})();'); }); it("Should work with arg:value", function() { - var result = Uglify.minify(code, { + var result = UglifyJS.minify(code, { compress: false, enclose: 'window,undefined:window', mangle: false, @@ -334,7 +334,7 @@ describe("minify", function() { assert.strictEqual(result.code, '(function(window,undefined){function enclose(){console.log("test enclose")}enclose()})(window);'); }); it("Should work alongside wrap", function() { - var result = Uglify.minify(code, { + var result = UglifyJS.minify(code, { compress: false, enclose: 'window,undefined:window', mangle: false, |