react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / fileset / tests / helper.js
80684 views1var EventEmitter = require('events').EventEmitter,2assert = require('assert'),3tests = {};45module.exports = test;6test.run = run;78// ## Test helpers910function test(msg, handler) {11tests[msg] = handler;12}1314function run() {15var specs = Object.keys(tests),16specsRemaining = specs.length;1718specs.forEach(function(spec) {19var handler = tests[spec];2021// grab the set of asserts for this spec22var shoulds = handler(),23keys = Object.keys(shoulds),24remaining = keys.length;2526keys.forEach(function(should) {27var em = new EventEmitter(),28to = setTimeout(function() {29assert.fail('never ended');30}, 5000);3132em33.on('error', function assertFail(err) { assert.fail(err) })34.on('end', function assertOk() {35clearTimeout(to);36shoulds[should].status = true;3738// till we get to 039if(!(--remaining)) {40console.log([41'',42'» ' + spec,43keys.map(function(k) { return ' » ' + k; }).join('\n'),44'',45' Total: ' + keys.length,46' Failed: ' + keys.map(function(item) { return shoulds[should].status; }).filter(function(status) { return !status; }).length,47''48].join('\n'));4950if(!(--specsRemaining)) {51console.log('All done');52}5354}55});5657shoulds[should](em);58});59});60}616263