aboutsummaryrefslogtreecommitdiff
path: root/test/mocha/glob.js
blob: eb5d477d6a1b233bdd5caafbef40c41bec6a4686 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var assert = require("assert");
var exec = require("child_process").exec;
var path = require("path");
var readFileSync = require("fs").readFileSync;

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;

            assert.strictEqual(stdout, 'function foo(o){print("Foo:",2*o)}var print=console.log.bind(console);\n');
            done();
        });
    });
    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();
        });
    });
    it("bin/uglifyjs with multiple input file globs.", function(done) {
        var command = uglifyjscmd + ' "test/input/issue-1242/???.es5" "test/input/issue-1242/*.js" -mc toplevel,passes=2';

        exec(command, function(err, stdout) {
            if (err) throw err;

            assert.strictEqual(stdout, 'var print=console.log.bind(console);print("qux",9,6),print("Foo:",22);\n');
            done();
        });
    });
    it("should throw with non-matching glob string", function(done) {
        var command = uglifyjscmd + ' "test/input/issue-1242/blah.*"';

        exec(command, function(err, stdout, stderr) {
            assert.ok(err);
            assert.ok(/^ERROR: ENOENT/.test(stderr));
            done();
        });
    });
    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();
        });
    });
    it("should handle special characters in glob string", function(done) {
        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();
        });
    });
    it("should handle array of glob strings - matching and otherwise", function(done) {
        var dir = "test/input/issue-1242";
        var command = uglifyjscmd + ' "' + [
            path.join(dir, "b*.es5"),
            path.join(dir, "z*.es5"),
            path.join(dir, "*.js")
        ].join('" "') + '"';

        exec(command, function(err, stdout, stderr) {
            assert.ok(err);
            assert.ok(/^ERROR: ENOENT.*?z\*\.es5/.test(stderr));
            done();
        });
    });
});