aboutsummaryrefslogtreecommitdiff
path: root/test/mocha/cli.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocha/cli.js')
-rw-r--r--test/mocha/cli.js89
1 files changed, 56 insertions, 33 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index b956309a..7162c816 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -2,6 +2,10 @@ var assert = require("assert");
var exec = require("child_process").exec;
var readFileSync = require("fs").readFileSync;
+function read(path) {
+ return readFileSync(path, "utf8");
+}
+
describe("bin/uglifyjs", function () {
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
it("should produce a functional build when using --self", function (done) {
@@ -20,7 +24,7 @@ describe("bin/uglifyjs", function () {
done();
});
});
- it("Should be able to filter comments correctly with `--comment 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) {
@@ -50,8 +54,8 @@ describe("bin/uglifyjs", function () {
done();
});
});
- it("Should append source map to output when using --source-map-inline", function (done) {
- var command = uglifyjscmd + ' test/input/issue-1323/sample.js --source-map-inline';
+ 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) {
if (err) throw err;
@@ -61,7 +65,7 @@ describe("bin/uglifyjs", function () {
done();
});
});
- it("should not append source map to output when not using --source-map-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) {
@@ -137,7 +141,7 @@ describe("bin/uglifyjs", function () {
exec(command, function (err, stdout) {
if (err) throw err;
- assert.strictEqual(stdout, readFileSync("test/input/issue-1482/default.js", "utf8"));
+ assert.strictEqual(stdout, read("test/input/issue-1482/default.js"));
done();
});
});
@@ -147,55 +151,59 @@ describe("bin/uglifyjs", function () {
exec(command, function (err, stdout) {
if (err) throw err;
- assert.strictEqual(stdout, readFileSync("test/input/issue-1482/bracketize.js", "utf8"));
+ assert.strictEqual(stdout, read("test/input/issue-1482/bracketize.js"));
done();
});
});
it("Should process inline source map", function(done) {
- var command = uglifyjscmd + ' test/input/issue-520/input.js -mc toplevel --in-source-map inline --source-map-inline';
+ var command = uglifyjscmd + " test/input/issue-520/input.js -mc toplevel --source-map content=inline,url=inline";
exec(command, function (err, stdout) {
if (err) throw err;
- assert.strictEqual(stdout, readFileSync("test/input/issue-520/output.js", "utf8"));
+ 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 --in-source-map inline';
+ var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline";
exec(command, function (err, stdout, stderr) {
if (err) throw err;
- assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n");
+ assert.strictEqual(stdout, [
+ "var bar=function(){function foo(bar){return bar}return foo}();",
+ "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxHQUFJQSxLQUFNLFdBQ04sUUFBU0MsS0FBS0QsS0FDVixNQUFPQSxLQUdYLE1BQU9DIn0=",
+ "",
+ ].join("\n"));
assert.strictEqual(stderr, "WARN: inline source map not found\n");
done();
});
});
it("Should fail with multiple input and inline source map", function(done) {
- var command = uglifyjscmd + ' test/input/issue-520/input.js test/input/issue-520/output.js --in-source-map inline --source-map-inline';
+ var command = uglifyjscmd + " test/input/issue-520/input.js test/input/issue-520/output.js --source-map content=inline,url=inline";
exec(command, function (err, stdout, stderr) {
assert.ok(err);
- assert.strictEqual(stderr, "ERROR: Inline source map only works with singular input\n");
+ assert.strictEqual(stderr, "ERROR: inline source map only works with singular input\n");
done();
});
});
it("Should fail with acorn and inline source map", function(done) {
- var command = uglifyjscmd + ' test/input/issue-520/input.js --in-source-map inline --source-map-inline --acorn';
+ var command = uglifyjscmd + " test/input/issue-520/input.js --source-map content=inline,url=inline -p acorn";
exec(command, function (err, stdout, stderr) {
assert.ok(err);
- assert.strictEqual(stderr, "ERROR: Inline source map only works with built-in parser\n");
+ assert.strictEqual(stderr, "ERROR: inline source map only works with built-in parser\n");
done();
});
});
it("Should fail with SpiderMonkey and inline source map", function(done) {
- var command = uglifyjscmd + ' test/input/issue-520/input.js --in-source-map inline --source-map-inline --spidermonkey';
+ var command = uglifyjscmd + " test/input/issue-520/input.js --source-map content=inline,url=inline -p spidermonkey";
exec(command, function (err, stdout, stderr) {
assert.ok(err);
- assert.strictEqual(stderr, "ERROR: Inline source map only works with built-in parser\n");
+ assert.strictEqual(stderr, "ERROR: inline source map only works with built-in parser\n");
done();
});
});
@@ -208,7 +216,7 @@ describe("bin/uglifyjs", function () {
assert.strictEqual(lines[0], "Parse error at test/input/invalid/simple.js:1,12");
assert.strictEqual(lines[1], "function f(a{}");
assert.strictEqual(lines[2], " ^");
- assert.strictEqual(lines[3], "SyntaxError: Unexpected token punc «{», expected punc «,»");
+ assert.strictEqual(lines[3], "ERROR: Unexpected token punc «{», expected punc «,»");
done();
});
});
@@ -221,7 +229,7 @@ describe("bin/uglifyjs", function () {
assert.strictEqual(lines[0], "Parse error at test/input/invalid/tab.js:1,12");
assert.strictEqual(lines[1], "\t\tfoo(\txyz, 0abc);");
assert.strictEqual(lines[2], "\t\t \t ^");
- assert.strictEqual(lines[3], "SyntaxError: Invalid syntax: 0abc");
+ assert.strictEqual(lines[3], "ERROR: Invalid syntax: 0abc");
done();
});
});
@@ -234,7 +242,7 @@ describe("bin/uglifyjs", function () {
assert.strictEqual(lines[0], "Parse error at test/input/invalid/eof.js:2,0");
assert.strictEqual(lines[1], "foo, bar(");
assert.strictEqual(lines[2], " ^");
- assert.strictEqual(lines[3], "SyntaxError: Unexpected token: eof (undefined)");
+ assert.strictEqual(lines[3], "ERROR: Unexpected token: eof (undefined)");
done();
});
});
@@ -247,20 +255,10 @@ describe("bin/uglifyjs", function () {
assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0");
assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) ");
assert.strictEqual(lines[2], " ^");
- assert.strictEqual(lines[3], "SyntaxError: Unexpected token: eof (undefined)");
+ assert.strictEqual(lines[3], "ERROR: Unexpected token: eof (undefined)");
done();
});
});
- it("Should support hyphen as shorthand", function(done) {
- var command = uglifyjscmd + ' test/input/issue-1431/sample.js -m keep-fnames=true';
-
- 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 throw syntax error (5--)", function(done) {
var command = uglifyjscmd + ' test/input/invalid/assign_1.js';
@@ -271,7 +269,7 @@ describe("bin/uglifyjs", function () {
"Parse error at test/input/invalid/assign_1.js:1,18",
"console.log(1 || 5--);",
" ^",
- "SyntaxError: Invalid use of -- operator"
+ "ERROR: Invalid use of -- operator"
].join("\n"));
done();
});
@@ -286,7 +284,7 @@ describe("bin/uglifyjs", function () {
"Parse error at test/input/invalid/assign_2.js:1,32",
"console.log(2 || (Math.random() /= 2));",
" ^",
- "SyntaxError: Invalid assignment"
+ "ERROR: Invalid assignment"
].join("\n"));
done();
});
@@ -301,9 +299,34 @@ describe("bin/uglifyjs", function () {
"Parse error at test/input/invalid/assign_3.js:1,18",
"console.log(3 || ++this);",
" ^",
- "SyntaxError: Invalid use of ++ operator"
+ "ERROR: Invalid use of ++ operator"
].join("\n"));
done();
});
});
+ it("Should handle literal string as source map input", function(done) {
+ var command = [
+ uglifyjscmd,
+ "test/input/issue-1236/simple.js",
+ "--source-map",
+ 'content="' + read_map() + '",url=inline'
+ ].join(" ");
+
+ 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LmpzIl0sIm5hbWVzIjpbImZvbyIsIngiLCJjb25zb2xlIiwibG9nIl0sIm1hcHBpbmdzIjoiWUFBQSxJQUFJQSxLQUFNLFFBQU5BLEtBQU1DLEdBQUEsTUFBSyxPQUFTQSxFQUN4QkMsU0FBUUMsSUFBSUgsSUFBSSJ9",
+ ""
+ ].join("\n"));
+ done();
+ });
+
+ function read_map() {
+ var map = JSON.parse(read("./test/input/issue-1236/simple.js.map"));
+ delete map.sourcesContent;
+ return JSON.stringify(map).replace(/"/g, '\\"');
+ }
+ });
});