mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
91 lines
2.8 KiB
JavaScript
Executable File
91 lines
2.8 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/*
|
|
run.js: test runner for core tests
|
|
|
|
Copyright (c) 2011 Nodejitsu
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
a copy of this software and associated documentation files (the
|
|
"Software"), to deal in the Software without restriction, including
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
var fs = require('fs'),
|
|
path = require('path'),
|
|
spawn = require('child_process').spawn,
|
|
async = require('async'),
|
|
colors = require('colors'),
|
|
optimist = require('optimist');
|
|
|
|
optimist.argv.color && (colors.mode = optimist.argv.color);
|
|
|
|
var testTimeout = 15000;
|
|
var results = {};
|
|
|
|
function runTest(test, callback) {
|
|
var child = spawn(path.join(__dirname, 'run-single'), [ test ]);
|
|
|
|
var killTimeout = setTimeout(function () {
|
|
child.kill();
|
|
console.log(' ' + path.basename(test).yellow + ' timed out'.red);
|
|
}, testTimeout);
|
|
|
|
child.on('exit', function (exitCode) {
|
|
clearTimeout(killTimeout);
|
|
|
|
console.log(' ' + ((exitCode) ? '✘'.red : '✔'.green) + ' ' +
|
|
path.basename(test) +
|
|
(exitCode ? (' (exit code: ' + exitCode + ')') : ''));
|
|
results[test] = { exitCode: exitCode };
|
|
callback();
|
|
//
|
|
// We don't want tests to be stopped after first failure, and that's what
|
|
// async does when it receives truthy value in callback.
|
|
//
|
|
});
|
|
};
|
|
|
|
var tests = process.argv.slice(2).filter(function (test) {
|
|
return test.substr(0, 2) != '--';
|
|
});
|
|
|
|
if (!tests.length) {
|
|
var pathPrefix = path.join(__dirname, 'simple');
|
|
tests = fs.readdirSync(pathPrefix).map(function (test) {
|
|
return path.join(pathPrefix, test);
|
|
});
|
|
//
|
|
// We only run simple tests by default.
|
|
//
|
|
}
|
|
|
|
console.log('Running tests:'.bold);
|
|
async.forEachSeries(tests, runTest, function () {
|
|
var failed = [], ok = [];
|
|
for (var test in results) {
|
|
(results[test].exitCode != 0 ? failed : ok).push(test);
|
|
}
|
|
|
|
console.log('\nSummary:'.bold);
|
|
console.log((' ' + ok.length + '\tpassed tests').green);
|
|
console.log((' ' + failed.length + '\tfailed tests').red);
|
|
});
|
|
|
|
// vim:filetype=javascript
|
|
|