aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/fileset/tests/helper.js
blob: 0fb0b25617532dcb9c6a90ecfb569821fd701fd7 (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
var EventEmitter = require('events').EventEmitter,
  assert = require('assert'),
  tests = {};

module.exports = test;
test.run = run;

// ## Test helpers

function test(msg, handler) {
  tests[msg] = handler;
}

function run() {
  var specs = Object.keys(tests),
    specsRemaining = specs.length;

  specs.forEach(function(spec) {
    var handler = tests[spec];

    // grab the set of asserts for this spec
    var shoulds = handler(),
      keys = Object.keys(shoulds),
      remaining = keys.length;

    keys.forEach(function(should) {
      var em = new EventEmitter(),
        to = setTimeout(function() {
          assert.fail('never ended');
        }, 5000);

      em
        .on('error', function assertFail(err) { assert.fail(err) })
        .on('end', function assertOk() {
          clearTimeout(to);
          shoulds[should].status = true;

          // till we get to 0
          if(!(--remaining)) {
            console.log([
              '',
              '» ' + spec,
              keys.map(function(k) { return '   » ' + k; }).join('\n'),
              '',
              '   Total: ' + keys.length,
              '   Failed: ' + keys.map(function(item) { return shoulds[should].status; }).filter(function(status) { return !status; }).length,
              ''
            ].join('\n'));

            if(!(--specsRemaining)) {
              console.log('All done');
            }

          }
        });

      shoulds[should](em);
    });
  });
}