aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/fileset/tests/test.js
blob: 3df267a4b9506a9299ca50e5dd89d39ae7265d93 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var EventEmitter = require('events').EventEmitter,
  fileset = require('../'),
  assert = require('assert'),
  test = require('./helper');

// Given a **.coffee pattern
test('Given a **.md pattern', function() {

  return {
    'should return the list of matching file in this repo': function(em) {
      fileset('*.md', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.ok(results.length, 'should return at least one element');
        assert.equal(results.length, 1, 'actually, should return only one');
        em.emit('end');
      });
    }
  }
});

test('Say we want the **.js files, but not those in node_modules', function() {

  return {
    'Should recursively walk the dir and return the matching list': function(em) {
      fileset('**/*.js', 'node_modules/**', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.equal(results.length, 4);
        em.emit('end');
      });
    },

    'Should support multiple paths at once': function(em) {
      fileset('**/*.js *.md', 'node_modules/**', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.equal(results.length, 5);

        assert.deepEqual(results, [
          'README.md',
          'lib/fileset.js',
          'tests/fixtures/an (odd) filename.js',
          'tests/helper.js',
          'tests/test.js'
        ]);

        em.emit('end');
      });
    },

    'Should support multiple paths for excludes as well': function(em) {
      fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.equal(results.length, 2);

        assert.deepEqual(results, [
          'lib/fileset.js',
          'tests/fixtures/an (odd) filename.js',
        ]);

        em.emit('end');
      });
    }
  }
});


test('Testing out emmited events', function() {

  // todos: the tests for match, include, exclude events, but seems like it's ok
  return {
    'Should recursively walk the dir and return the matching list': function(em) {
      fileset('**/*.js', 'node_modules/**')
        .on('error', em.emit.bind(em, 'error'))
        .on('end', function(results) {
          assert.ok(Array.isArray(results), 'should be an array');
          assert.equal(results.length, 4);
          em.emit('end');
        });
    },

    'Should support multiple paths at once': function(em) {
      fileset('**/*.js *.md', 'node_modules/**')
        .on('error', em.emit.bind(em, 'error'))
        .on('end', function(results) {
          assert.ok(Array.isArray(results), 'should be an array');
          assert.equal(results.length, 5);

          assert.deepEqual(results, [
            'README.md',
            'lib/fileset.js',
            'tests/fixtures/an (odd) filename.js',
            'tests/helper.js',
            'tests/test.js'
          ]);

          em.emit('end');
        });
    }
  }
});


test('Testing patterns passed as arrays', function() {

  return {
    'Should match files passed as an array with odd filenames': function(em) {
      fileset(['lib/*.js', 'tests/fixtures/an (odd) filename.js'], ['node_modules/**'])
        .on('error', em.emit.bind(em, 'error'))
        .on('end', function(results) {
          assert.ok(Array.isArray(results), 'should be an array');
          assert.equal(results.length, 2);

          assert.deepEqual(results, [
            'lib/fileset.js',
            'tests/fixtures/an (odd) filename.js',
          ]);

          em.emit('end');
        });
    }
  }

});



test.run();