2016-07-30 01:27:30 +00:00
|
|
|
var assert = require("assert");
|
2017-04-15 15:50:50 +00:00
|
|
|
var exec = require("child_process").exec;
|
2017-03-22 22:11:16 +00:00
|
|
|
var path = require("path");
|
2016-07-30 01:27:30 +00:00
|
|
|
|
2017-04-15 15:50:50 +00:00
|
|
|
describe("bin/uglifyjs with input file globs", function() {
|
|
|
|
|
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
|
|
|
|
|
it("bin/uglifyjs with one input file extension glob.", function(done) {
|
|
|
|
|
var command = uglifyjscmd + ' "test/input/issue-1242/foo.*" -cm';
|
|
|
|
|
|
|
|
|
|
exec(command, function(err, stdout) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
2017-12-20 09:05:40 +00:00
|
|
|
assert.strictEqual(stdout, 'var print=console.log.bind(console);function foo(o){print("Foo:",2*o)}\n');
|
2017-04-15 15:50:50 +00:00
|
|
|
done();
|
|
|
|
|
});
|
2016-07-30 01:27:30 +00:00
|
|
|
});
|
2017-04-15 15:50:50 +00:00
|
|
|
it("bin/uglifyjs with one input file name glob.", function(done) {
|
|
|
|
|
var command = uglifyjscmd + ' "test/input/issue-1242/b*.es5" -cm';
|
|
|
|
|
|
|
|
|
|
exec(command, function(err, stdout) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(stdout, 'function bar(n){return 3*n}function baz(n){return n/2}\n');
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-07-30 01:27:30 +00:00
|
|
|
});
|
2017-04-15 15:50:50 +00:00
|
|
|
it("bin/uglifyjs with multiple input file globs.", function(done) {
|
2017-12-15 05:28:30 +00:00
|
|
|
var command = uglifyjscmd + ' "test/input/issue-1242/???.es5" "test/input/issue-1242/*.js" -mc toplevel,passes=3';
|
2017-04-15 15:50:50 +00:00
|
|
|
|
|
|
|
|
exec(command, function(err, stdout) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
2017-07-01 17:05:14 +00:00
|
|
|
assert.strictEqual(stdout, 'var print=console.log.bind(console);print("qux",9,6),print("Foo:",22);\n');
|
2017-04-15 15:50:50 +00:00
|
|
|
done();
|
2016-07-30 01:27:30 +00:00
|
|
|
});
|
|
|
|
|
});
|
2018-06-28 10:16:49 +00:00
|
|
|
it("Should throw with non-matching glob string", function(done) {
|
2017-04-15 15:50:50 +00:00
|
|
|
var command = uglifyjscmd + ' "test/input/issue-1242/blah.*"';
|
|
|
|
|
|
|
|
|
|
exec(command, function(err, stdout, stderr) {
|
|
|
|
|
assert.ok(err);
|
|
|
|
|
assert.ok(/^ERROR: ENOENT/.test(stderr));
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-03-22 22:11:16 +00:00
|
|
|
});
|
2017-04-15 15:50:50 +00:00
|
|
|
it('"?" in glob string should not match "/"', function(done) {
|
|
|
|
|
var command = uglifyjscmd + ' "test/input?issue-1242/foo.*"';
|
|
|
|
|
|
|
|
|
|
exec(command, function(err, stdout, stderr) {
|
|
|
|
|
assert.ok(err);
|
|
|
|
|
assert.ok(/^ERROR: ENOENT/.test(stderr));
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-03-22 22:11:16 +00:00
|
|
|
});
|
2018-06-28 10:16:49 +00:00
|
|
|
it("Should handle special characters in glob string", function(done) {
|
2017-04-15 15:50:50 +00:00
|
|
|
var command = uglifyjscmd + ' "test/input/issue-1632/^{*}[???](*)+$.??" -cm';
|
|
|
|
|
|
|
|
|
|
exec(command, function(err, stdout) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(stdout, "console.log(x);\n");
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-03-22 22:11:16 +00:00
|
|
|
});
|
2018-06-28 10:16:49 +00:00
|
|
|
it("Should handle array of glob strings - matching and otherwise", function(done) {
|
2017-03-22 22:11:16 +00:00
|
|
|
var dir = "test/input/issue-1242";
|
2017-04-15 15:50:50 +00:00
|
|
|
var command = uglifyjscmd + ' "' + [
|
2017-03-22 22:11:16 +00:00
|
|
|
path.join(dir, "b*.es5"),
|
|
|
|
|
path.join(dir, "z*.es5"),
|
2017-04-15 15:50:50 +00:00
|
|
|
path.join(dir, "*.js")
|
|
|
|
|
].join('" "') + '"';
|
|
|
|
|
|
|
|
|
|
exec(command, function(err, stdout, stderr) {
|
|
|
|
|
assert.ok(err);
|
|
|
|
|
assert.ok(/^ERROR: ENOENT.*?z\*\.es5/.test(stderr));
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-03-22 22:11:16 +00:00
|
|
|
});
|
2016-07-30 01:27:30 +00:00
|
|
|
});
|