Name: js-handler/node_modules/nodeunit/lib/nodeunit.js
| 1: | /*! |
| 2: | * Nodeunit |
| 3: | * Copyright (c) 2010 Caolan McMahon |
| 4: | * MIT Licensed |
| 5: | */ |
| 6: | |
| 7: | /** |
| 8: | * Module dependencies |
| 9: | */ |
| 10: | |
| 11: | var async = require('../deps/async'), |
| 12: | types = require('./types'), |
| 13: | utils = require('./utils'), |
| 14: | core = require('./core'), |
| 15: | reporters = require('./reporters'), |
| 16: | assert = require('./assert'), |
| 17: | path = require('path'), |
| 18: | events = require('events'); |
| 19: | |
| 20: | |
| 21: | /** |
| 22: | * Export sub-modules. |
| 23: | */ |
| 24: | |
| 25: | exports.types = types; |
| 26: | exports.utils = utils; |
| 27: | exports.reporters = reporters; |
| 28: | exports.assert = assert; |
| 29: | |
| 30: | // backwards compatibility |
| 31: | exports.testrunner = { |
| 32: | run: function () { |
| 33: | console.log( |
| 34: | 'WARNING: nodeunit.testrunner is going to be deprecated, please ' + |
| 35: | 'use nodeunit.reporters.default instead!' |
| 36: | ); |
| 37: | return reporters['default'].run.apply(this, arguments); |
| 38: | } |
| 39: | }; |
| 40: | |
| 41: | |
| 42: | /** |
| 43: | * Export all core functions |
| 44: | */ |
| 45: | |
| 46: | for (var k in core) { |
| 47: | exports[k] = core[k]; |
| 48: | }; |
| 49: | |
| 50: | |
| 51: | /** |
| 52: | * Load modules from paths array and run all exported tests in series. If a path |
| 53: | * is a directory, load all supported file types inside it as modules. This only |
| 54: | * reads 1 level deep in the directory and does not recurse through |
| 55: | * sub-directories. |
| 56: | * |
| 57: | * @param {Array} paths |
| 58: | * @param {Object} opt |
| 59: | * @api public |
| 60: | */ |
| 61: | |
| 62: | exports.runFiles = function (paths, opt) { |
| 63: | var all_assertions = []; |
| 64: | var options = types.options(opt); |
| 65: | var start = new Date().getTime(); |
| 66: | |
| 67: | if (!paths.length) { |
| 68: | return options.done(types.assertionList(all_assertions)); |
| 69: | } |
| 70: | |
| 71: | utils.modulePaths(paths, function (err, files) { |
| 72: | if (err) throw err; |
| 73: | async.concatSeries(files, function (file, cb) { |
| 74: | var name = path.basename(file); |
| 75: | exports.runModule(name, require(file), options, cb); |
| 76: | }, |
| 77: | function (err, all_assertions) { |
| 78: | var end = new Date().getTime(); |
| 79: | exports.done() |
| 80: | options.done(types.assertionList(all_assertions, end - start)); |
| 81: | }); |
| 82: | }); |
| 83: | |
| 84: | }; |
| 85: | |
| 86: | /* Export all prototypes from events.EventEmitter */ |
| 87: | var label; |
| 88: | for (label in events.EventEmitter.prototype) { |
| 89: | exports[label] = events.EventEmitter.prototype[label]; |
| 90: | } |
| 91: | |
| 92: | /* Emit event 'complete' on completion of a test suite. */ |
| 93: | exports.complete = function(name, assertions) |
| 94: | { |
| 95: | exports.emit('complete', name, assertions); |
| 96: | }; |
| 97: | |
| 98: | /* Emit event 'complete' on completion of all tests. */ |
| 99: | exports.done = function() |
| 100: | { |
| 101: | exports.emit('done'); |
| 102: | }; |
| 103: | |
| 104: | module.exports = exports; |
