Name: js-handler/node_modules/nodeunit/bin/nodeunit
| 1: | #!/usr/bin/env node |
| 2: | |
| 3: | var |
| 4: | fs = require('fs'), |
| 5: | path = require('path'); |
| 6: | |
| 7: | // TODO: remove this when https://github.com/joyent/node/pull/1312 |
| 8: | // lands in core. |
| 9: | // |
| 10: | // Until then, use console.log from npm (https://gist.github.com/1077544) |
| 11: | require('../deps/console.log'); |
| 12: | |
| 13: | //require.paths.push(process.cwd()); |
| 14: | var args = (process.ARGV || process.argv).slice(2); |
| 15: | |
| 16: | var files = []; |
| 17: | |
| 18: | var testrunner, |
| 19: | config_file, |
| 20: | config_param_found = false, |
| 21: | output_param_found = false, |
| 22: | reporter_file = 'default', |
| 23: | reporter_param_found = false, |
| 24: | testspec_param_found = false; |
| 25: | testFullSpec_param_found = false; |
| 26: | |
| 27: | var usage = "Usage: nodeunit [options] testmodule1.js testfolder [...] \n" + |
| 28: | "Options:\n\n" + |
| 29: | " --config FILE the path to a JSON file with options\n" + |
| 30: | " --reporter FILE optional path to a reporter file to customize the output\n" + |
| 31: | " --list-reporters list available build-in reporters\n" + |
| 32: | " -t name, specify a test to run\n" + |
| 33: | " -f fullname, specify a specific test to run. fullname is built so: \"outerGroup - .. - innerGroup - testName\"\n" + |
| 34: | " -h, --help display this help and exit\n" + |
| 35: | " -v, --version output version information and exit"; |
| 36: | |
| 37: | |
| 38: | |
| 39: | // load default options |
| 40: | var content = fs.readFileSync(__dirname + '/nodeunit.json', 'utf8'); |
| 41: | var options = JSON.parse(content); |
| 42: | |
| 43: | // a very basic pseudo --options parser |
| 44: | args.forEach(function (arg) { |
| 45: | if (arg.slice(0, 9) === "--config=") { |
| 46: | config_file = arg.slice(9); |
| 47: | } else if (arg === '--config') { |
| 48: | config_param_found = true; |
| 49: | } else if (config_param_found) { |
| 50: | config_file = arg; |
| 51: | config_param_found = false; |
| 52: | } else if (arg.slice(0, 9) === "--output=") { |
| 53: | options.output = arg.slice(9); |
| 54: | } else if (arg === '--output') { |
| 55: | output_param_found = true; |
| 56: | } else if (output_param_found) { |
| 57: | options.output = arg; |
| 58: | output_param_found = false; |
| 59: | } else if (arg.slice(0, 11) === "--reporter=") { |
| 60: | reporter_file = arg.slice(11); |
| 61: | } else if (arg === '--reporter') { |
| 62: | reporter_param_found = true; |
| 63: | } else if (reporter_param_found) { |
| 64: | reporter_file = arg; |
| 65: | reporter_param_found = false; |
| 66: | } else if (arg === '-t') { |
| 67: | testspec_param_found = true; |
| 68: | } else if (testspec_param_found) { |
| 69: | options.testspec = arg; |
| 70: | testspec_param_found = false; |
| 71: | } else if (arg === '-f') { |
| 72: | testFullSpec_param_found = true; |
| 73: | } else if (testFullSpec_param_found) { |
| 74: | options.testFullSpec= arg; |
| 75: | testFullSpec_param_found = false; |
| 76: | } else if (arg === '--list-reporters') { |
| 77: | var reporters = fs.readdirSync(__dirname + '/../lib/reporters'); |
| 78: | reporters = reporters.filter(function (reporter_file) { |
| 79: | return (/\.js$/).test(reporter_file); |
| 80: | }).map(function (reporter_file) { |
| 81: | return reporter_file.replace(/\.js$/, ''); |
| 82: | }).filter(function (reporter_file) { |
| 83: | return reporter_file !== 'index'; |
| 84: | }); |
| 85: | console.log('Build-in reporters: '); |
| 86: | reporters.forEach(function (reporter_file) { |
| 87: | var reporter = require('../lib/reporters/' + reporter_file); |
| 88: | console.log(' * ' + reporter_file + (reporter.info ? ': ' + reporter.info : '')); |
| 89: | }); |
| 90: | process.exit(0); |
| 91: | } else if ((arg === '-v') || (arg === '--version')) { |
| 92: | var content = fs.readFileSync(__dirname + '/../package.json', 'utf8'); |
| 93: | var pkg = JSON.parse(content); |
| 94: | console.log(pkg.version); |
| 95: | process.exit(0); |
| 96: | } else if ((arg === '-h') || (arg === '--help')) { |
| 97: | console.log(usage); |
| 98: | process.exit(0); |
| 99: | } else { |
| 100: | files.push(arg); |
| 101: | } |
| 102: | }); |
| 103: | |
| 104: | if (files.length === 0) { |
| 105: | console.log('Files required.'); |
| 106: | console.log(usage); |
| 107: | process.exit(1); |
| 108: | } |
| 109: | |
| 110: | if (config_file) { |
| 111: | content = fs.readFileSync(config_file, 'utf8'); |
| 112: | var custom_options = JSON.parse(content); |
| 113: | |
| 114: | for (var option in custom_options) { |
| 115: | if (typeof option === 'string') { |
| 116: | options[option] = custom_options[option]; |
| 117: | } |
| 118: | } |
| 119: | } |
| 120: | |
| 121: | var builtin_reporters = require(__dirname + '/../lib/reporters'); |
| 122: | if (reporter_file in builtin_reporters) { |
| 123: | testrunner = builtin_reporters[reporter_file]; |
| 124: | } |
| 125: | else { |
| 126: | testrunner = require(reporter_file); |
| 127: | } |
| 128: | |
| 129: | testrunner.run(files, options, function(err) { |
| 130: | if (err) { |
| 131: | process.exit(1); |
| 132: | } |
| 133: | }); |
