Merge Aether tools

This commit is contained in:
Joshua Granick
2014-09-30 17:41:39 -07:00
parent f1e3707ad9
commit 540aa48c39
272 changed files with 35574 additions and 127 deletions

View File

@@ -0,0 +1 @@
npm-debug.log

View File

@@ -0,0 +1,187 @@
/*
* portfinder.js: A simple tool to find an open port on the current machine.
*
* (C) 2011, Charlie Robbins
*
*/
var fs = require('fs'),
net = require('net'),
path = require('path'),
mkdirp = require('mkdirp').mkdirp;
//
// ### @basePort {Number}
// The lowest port to begin any port search from
//
exports.basePort = 8000;
//
// ### @basePath {string}
// Default path to begin any socket search from
//
exports.basePath = '/tmp/portfinder'
//
// ### function getPort (options, callback)
// #### @options {Object} Settings to use when finding the necessary port
// #### @callback {function} Continuation to respond to when complete.
// Responds with a unbound port on the current machine.
//
exports.getPort = function (options, callback) {
if (!callback) {
callback = options;
options = {};
}
options.port = options.port || exports.basePort;
options.host = options.host || null;
options.server = options.server || net.createServer(function () {
//
// Create an empty listener for the port testing server.
//
});
function onListen () {
options.server.removeListener('error', onError);
options.server.close();
callback(null, options.port)
}
function onError (err) {
options.server.removeListener('listening', onListen);
if (err.code !== 'EADDRINUSE') {
return callback(err);
}
exports.getPort({
port: exports.nextPort(options.port),
host: options.host,
server: options.server
}, callback);
}
options.server.once('error', onError);
options.server.once('listening', onListen);
options.server.listen(options.port, options.host);
};
//
// ### function getSocket (options, callback)
// #### @options {Object} Settings to use when finding the necessary port
// #### @callback {function} Continuation to respond to when complete.
// Responds with a unbound socket using the specified directory and base
// name on the current machine.
//
exports.getSocket = function (options, callback) {
if (!callback) {
callback = options;
options = {};
}
options.mod = options.mod || 0755;
options.path = options.path || exports.basePath + '.sock';
//
// Tests the specified socket
//
function testSocket () {
fs.stat(options.path, function (err) {
//
// If file we're checking doesn't exist (thus, stating it emits ENOENT),
// we should be OK with listening on this socket.
//
if (err) {
if (err.code == 'ENOENT') {
callback(null, options.path);
}
else {
callback(err);
}
}
else {
//
// This file exists, so it isn't possible to listen on it. Lets try
// next socket.
//
options.path = exports.nextSocket(options.path);
exports.getSocket(options, callback);
}
});
}
//
// Create the target `dir` then test connection
// against the socket.
//
function createAndTestSocket (dir) {
mkdirp(dir, options.mod, function (err) {
if (err) {
return callback(err);
}
options.exists = true;
testSocket();
});
}
//
// Check if the parent directory of the target
// socket path exists. If it does, test connection
// against the socket. Otherwise, create the directory
// then test connection.
//
function checkAndTestSocket () {
var dir = path.dirname(options.path);
fs.stat(dir, function (err, stats) {
if (err || !stats.isDirectory()) {
return createAndTestSocket(dir);
}
options.exists = true;
testSocket();
});
}
//
// If it has been explicitly stated that the
// target `options.path` already exists, then
// simply test the socket.
//
return options.exists
? testSocket()
: checkAndTestSocket();
};
//
// ### function nextPort (port)
// #### @port {Number} Port to increment from.
// Gets the next port in sequence from the
// specified `port`.
//
exports.nextPort = function (port) {
return port + 1;
};
//
// ### function nextSocket (socketPath)
// #### @socketPath {string} Path to increment from
// Gets the next socket path in sequence from the
// specified `socketPath`.
//
exports.nextSocket = function (socketPath) {
var dir = path.dirname(socketPath),
name = path.basename(socketPath, '.sock'),
match = name.match(/^([a-zA-z]+)(\d*)$/i),
index = parseInt(match[2]),
base = match[1];
if (isNaN(index)) {
index = 0;
}
index += 1;
return path.join(dir, base + index + '.sock');
};

View File

@@ -0,0 +1,15 @@
#!/bin/sh
basedir=`dirname "$0"`
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../vows/bin/vows" "$@"
ret=$?
else
node "$basedir/../vows/bin/vows" "$@"
ret=$?
fi
exit $ret

View File

@@ -0,0 +1,5 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\vows\bin\vows" %*
) ELSE (
node "%~dp0\..\vows\bin\vows" %*
)

View File

@@ -0,0 +1,9 @@
[submodule "deps/nodeunit"]
path = deps/nodeunit
url = git://github.com/caolan/nodeunit.git
[submodule "deps/UglifyJS"]
path = deps/UglifyJS
url = https://github.com/mishoo/UglifyJS.git
[submodule "deps/nodelint"]
path = deps/nodelint
url = https://github.com/tav/nodelint.git

View File

@@ -0,0 +1,4 @@
deps
dist
test
nodelint.cfg

View File

@@ -0,0 +1,19 @@
Copyright (c) 2010 Caolan McMahon
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.

View File

@@ -0,0 +1,25 @@
PACKAGE = asyncjs
NODEJS = $(if $(shell test -f /usr/bin/nodejs && echo "true"),nodejs,node)
CWD := $(shell pwd)
NODEUNIT = $(CWD)/node_modules/nodeunit/bin/nodeunit
UGLIFY = $(CWD)/node_modules/uglify-js/bin/uglifyjs
NODELINT = $(CWD)/node_modules/nodelint/nodelint
BUILDDIR = dist
all: clean test build
build: $(wildcard lib/*.js)
mkdir -p $(BUILDDIR)
$(UGLIFY) lib/async.js > $(BUILDDIR)/async.min.js
test:
$(NODEUNIT) test
clean:
rm -rf $(BUILDDIR)
lint:
$(NODELINT) --config nodelint.cfg lib/async.js
.PHONY: test build all

View File

@@ -0,0 +1,3 @@
// This file is just added for convenience so this repository can be
// directly checked out into a project's deps folder
module.exports = require('./lib/async');

View File

@@ -0,0 +1,692 @@
/*global setTimeout: false, console: false */
(function () {
var async = {};
// global on the server, window in the browser
var root = this,
previous_async = root.async;
if (typeof module !== 'undefined' && module.exports) {
module.exports = async;
}
else {
root.async = async;
}
async.noConflict = function () {
root.async = previous_async;
return async;
};
//// cross-browser compatiblity functions ////
var _forEach = function (arr, iterator) {
if (arr.forEach) {
return arr.forEach(iterator);
}
for (var i = 0; i < arr.length; i += 1) {
iterator(arr[i], i, arr);
}
};
var _map = function (arr, iterator) {
if (arr.map) {
return arr.map(iterator);
}
var results = [];
_forEach(arr, function (x, i, a) {
results.push(iterator(x, i, a));
});
return results;
};
var _reduce = function (arr, iterator, memo) {
if (arr.reduce) {
return arr.reduce(iterator, memo);
}
_forEach(arr, function (x, i, a) {
memo = iterator(memo, x, i, a);
});
return memo;
};
var _keys = function (obj) {
if (Object.keys) {
return Object.keys(obj);
}
var keys = [];
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
keys.push(k);
}
}
return keys;
};
//// exported async module functions ////
//// nextTick implementation with browser-compatible fallback ////
if (typeof process === 'undefined' || !(process.nextTick)) {
async.nextTick = function (fn) {
setTimeout(fn, 0);
};
}
else {
async.nextTick = process.nextTick;
}
async.forEach = function (arr, iterator, callback) {
callback = callback || function () {};
if (!arr.length) {
return callback();
}
var completed = 0;
_forEach(arr, function (x) {
iterator(x, function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
completed += 1;
if (completed === arr.length) {
callback(null);
}
}
});
});
};
async.forEachSeries = function (arr, iterator, callback) {
callback = callback || function () {};
if (!arr.length) {
return callback();
}
var completed = 0;
var iterate = function () {
iterator(arr[completed], function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
completed += 1;
if (completed === arr.length) {
callback(null);
}
else {
iterate();
}
}
});
};
iterate();
};
async.forEachLimit = function (arr, limit, iterator, callback) {
callback = callback || function () {};
if (!arr.length || limit <= 0) {
return callback();
}
var completed = 0;
var started = 0;
var running = 0;
(function replenish () {
if (completed === arr.length) {
return callback();
}
while (running < limit && started < arr.length) {
started += 1;
running += 1;
iterator(arr[started - 1], function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
completed += 1;
running -= 1;
if (completed === arr.length) {
callback();
}
else {
replenish();
}
}
});
}
})();
};
var doParallel = function (fn) {
return function () {
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [async.forEach].concat(args));
};
};
var doSeries = function (fn) {
return function () {
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [async.forEachSeries].concat(args));
};
};
var _asyncMap = function (eachfn, arr, iterator, callback) {
var results = [];
arr = _map(arr, function (x, i) {
return {index: i, value: x};
});
eachfn(arr, function (x, callback) {
iterator(x.value, function (err, v) {
results[x.index] = v;
callback(err);
});
}, function (err) {
callback(err, results);
});
};
async.map = doParallel(_asyncMap);
async.mapSeries = doSeries(_asyncMap);
// reduce only has a series version, as doing reduce in parallel won't
// work in many situations.
async.reduce = function (arr, memo, iterator, callback) {
async.forEachSeries(arr, function (x, callback) {
iterator(memo, x, function (err, v) {
memo = v;
callback(err);
});
}, function (err) {
callback(err, memo);
});
};
// inject alias
async.inject = async.reduce;
// foldl alias
async.foldl = async.reduce;
async.reduceRight = function (arr, memo, iterator, callback) {
var reversed = _map(arr, function (x) {
return x;
}).reverse();
async.reduce(reversed, memo, iterator, callback);
};
// foldr alias
async.foldr = async.reduceRight;
var _filter = function (eachfn, arr, iterator, callback) {
var results = [];
arr = _map(arr, function (x, i) {
return {index: i, value: x};
});
eachfn(arr, function (x, callback) {
iterator(x.value, function (v) {
if (v) {
results.push(x);
}
callback();
});
}, function (err) {
callback(_map(results.sort(function (a, b) {
return a.index - b.index;
}), function (x) {
return x.value;
}));
});
};
async.filter = doParallel(_filter);
async.filterSeries = doSeries(_filter);
// select alias
async.select = async.filter;
async.selectSeries = async.filterSeries;
var _reject = function (eachfn, arr, iterator, callback) {
var results = [];
arr = _map(arr, function (x, i) {
return {index: i, value: x};
});
eachfn(arr, function (x, callback) {
iterator(x.value, function (v) {
if (!v) {
results.push(x);
}
callback();
});
}, function (err) {
callback(_map(results.sort(function (a, b) {
return a.index - b.index;
}), function (x) {
return x.value;
}));
});
};
async.reject = doParallel(_reject);
async.rejectSeries = doSeries(_reject);
var _detect = function (eachfn, arr, iterator, main_callback) {
eachfn(arr, function (x, callback) {
iterator(x, function (result) {
if (result) {
main_callback(x);
main_callback = function () {};
}
else {
callback();
}
});
}, function (err) {
main_callback();
});
};
async.detect = doParallel(_detect);
async.detectSeries = doSeries(_detect);
async.some = function (arr, iterator, main_callback) {
async.forEach(arr, function (x, callback) {
iterator(x, function (v) {
if (v) {
main_callback(true);
main_callback = function () {};
}
callback();
});
}, function (err) {
main_callback(false);
});
};
// any alias
async.any = async.some;
async.every = function (arr, iterator, main_callback) {
async.forEach(arr, function (x, callback) {
iterator(x, function (v) {
if (!v) {
main_callback(false);
main_callback = function () {};
}
callback();
});
}, function (err) {
main_callback(true);
});
};
// all alias
async.all = async.every;
async.sortBy = function (arr, iterator, callback) {
async.map(arr, function (x, callback) {
iterator(x, function (err, criteria) {
if (err) {
callback(err);
}
else {
callback(null, {value: x, criteria: criteria});
}
});
}, function (err, results) {
if (err) {
return callback(err);
}
else {
var fn = function (left, right) {
var a = left.criteria, b = right.criteria;
return a < b ? -1 : a > b ? 1 : 0;
};
callback(null, _map(results.sort(fn), function (x) {
return x.value;
}));
}
});
};
async.auto = function (tasks, callback) {
callback = callback || function () {};
var keys = _keys(tasks);
if (!keys.length) {
return callback(null);
}
var results = {};
var listeners = [];
var addListener = function (fn) {
listeners.unshift(fn);
};
var removeListener = function (fn) {
for (var i = 0; i < listeners.length; i += 1) {
if (listeners[i] === fn) {
listeners.splice(i, 1);
return;
}
}
};
var taskComplete = function () {
_forEach(listeners.slice(0), function (fn) {
fn();
});
};
addListener(function () {
if (_keys(results).length === keys.length) {
callback(null, results);
callback = function () {};
}
});
_forEach(keys, function (k) {
var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
var taskCallback = function (err) {
if (err) {
callback(err);
// stop subsequent errors hitting callback multiple times
callback = function () {};
}
else {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
results[k] = args;
taskComplete();
}
};
var requires = task.slice(0, Math.abs(task.length - 1)) || [];
var ready = function () {
return _reduce(requires, function (a, x) {
return (a && results.hasOwnProperty(x));
}, true) && !results.hasOwnProperty(k);
};
if (ready()) {
task[task.length - 1](taskCallback, results);
}
else {
var listener = function () {
if (ready()) {
removeListener(listener);
task[task.length - 1](taskCallback, results);
}
};
addListener(listener);
}
});
};
async.waterfall = function (tasks, callback) {
callback = callback || function () {};
if (!tasks.length) {
return callback();
}
var wrapIterator = function (iterator) {
return function (err) {
if (err) {
callback(err);
callback = function () {};
}
else {
var args = Array.prototype.slice.call(arguments, 1);
var next = iterator.next();
if (next) {
args.push(wrapIterator(next));
}
else {
args.push(callback);
}
async.nextTick(function () {
iterator.apply(null, args);
});
}
};
};
wrapIterator(async.iterator(tasks))();
};
async.parallel = function (tasks, callback) {
callback = callback || function () {};
if (tasks.constructor === Array) {
async.map(tasks, function (fn, callback) {
if (fn) {
fn(function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
callback.call(null, err, args);
});
}
}, callback);
}
else {
var results = {};
async.forEach(_keys(tasks), function (k, callback) {
tasks[k](function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
results[k] = args;
callback(err);
});
}, function (err) {
callback(err, results);
});
}
};
async.series = function (tasks, callback) {
callback = callback || function () {};
if (tasks.constructor === Array) {
async.mapSeries(tasks, function (fn, callback) {
if (fn) {
fn(function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
callback.call(null, err, args);
});
}
}, callback);
}
else {
var results = {};
async.forEachSeries(_keys(tasks), function (k, callback) {
tasks[k](function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 1) {
args = args[0];
}
results[k] = args;
callback(err);
});
}, function (err) {
callback(err, results);
});
}
};
async.iterator = function (tasks) {
var makeCallback = function (index) {
var fn = function () {
if (tasks.length) {
tasks[index].apply(null, arguments);
}
return fn.next();
};
fn.next = function () {
return (index < tasks.length - 1) ? makeCallback(index + 1): null;
};
return fn;
};
return makeCallback(0);
};
async.apply = function (fn) {
var args = Array.prototype.slice.call(arguments, 1);
return function () {
return fn.apply(
null, args.concat(Array.prototype.slice.call(arguments))
);
};
};
var _concat = function (eachfn, arr, fn, callback) {
var r = [];
eachfn(arr, function (x, cb) {
fn(x, function (err, y) {
r = r.concat(y || []);
cb(err);
});
}, function (err) {
callback(err, r);
});
};
async.concat = doParallel(_concat);
async.concatSeries = doSeries(_concat);
async.whilst = function (test, iterator, callback) {
if (test()) {
iterator(function (err) {
if (err) {
return callback(err);
}
async.whilst(test, iterator, callback);
});
}
else {
callback();
}
};
async.until = function (test, iterator, callback) {
if (!test()) {
iterator(function (err) {
if (err) {
return callback(err);
}
async.until(test, iterator, callback);
});
}
else {
callback();
}
};
async.queue = function (worker, concurrency) {
var workers = 0;
var q = {
tasks: [],
concurrency: concurrency,
saturated: null,
empty: null,
drain: null,
push: function (data, callback) {
if(data.constructor !== Array) {
data = [data];
}
_forEach(data, function(task) {
q.tasks.push({
data: task,
callback: typeof callback === 'function' ? callback : null
});
if (q.saturated && q.tasks.length == concurrency) {
q.saturated();
}
async.nextTick(q.process);
});
},
process: function () {
if (workers < q.concurrency && q.tasks.length) {
var task = q.tasks.shift();
if(q.empty && q.tasks.length == 0) q.empty();
workers += 1;
worker(task.data, function () {
workers -= 1;
if (task.callback) {
task.callback.apply(task, arguments);
}
if(q.drain && q.tasks.length + workers == 0) q.drain();
q.process();
});
}
},
length: function () {
return q.tasks.length;
},
running: function () {
return workers;
}
};
return q;
};
var _console_fn = function (name) {
return function (fn) {
var args = Array.prototype.slice.call(arguments, 1);
fn.apply(null, args.concat([function (err) {
var args = Array.prototype.slice.call(arguments, 1);
if (typeof console !== 'undefined') {
if (err) {
if (console.error) {
console.error(err);
}
}
else if (console[name]) {
_forEach(args, function (x) {
console[name](x);
});
}
}
}]));
};
};
async.log = _console_fn('log');
async.dir = _console_fn('dir');
/*async.info = _console_fn('info');
async.warn = _console_fn('warn');
async.error = _console_fn('error');*/
async.memoize = function (fn, hasher) {
var memo = {};
var queues = {};
hasher = hasher || function (x) {
return x;
};
var memoized = function () {
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
var key = hasher.apply(null, args);
if (key in memo) {
callback.apply(null, memo[key]);
}
else if (key in queues) {
queues[key].push(callback);
}
else {
queues[key] = [callback];
fn.apply(null, args.concat([function () {
memo[key] = arguments;
var q = queues[key];
delete queues[key];
for (var i = 0, l = q.length; i < l; i++) {
q[i].apply(null, arguments);
}
}]));
}
};
memoized.unmemoized = fn;
return memoized;
};
async.unmemoize = function (fn) {
return function () {
return (fn.unmemoized || fn).apply(null, arguments);
};
};
}());

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
node_modules/
npm-debug.log

View File

@@ -0,0 +1,2 @@
node_modules/
npm-debug.log

View File

@@ -0,0 +1,5 @@
--- /dev/null
+++ .gitignore
@@ -0,0 +1,2 @@
+node_modules/
+npm-debug.log

View File

@@ -0,0 +1,21 @@
Copyright 2010 James Halliday (mail@substack.net)
This project is free software released under the MIT/X11 license:
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.

View File

@@ -0,0 +1,20 @@
var path = require('path');
var fs = require('fs');
var exports = module.exports = function mkdirP (p, mode, f) {
var cb = f || function () {};
p = path.resolve(p);
var ps = path.normalize(p).split('/');
path.exists(p, function (exists) {
if (exists) cb(null);
else mkdirP(ps.slice(0,-1).join('/'), mode, function (err) {
if (err && err.code !== 'EEXIST') cb(err)
else fs.mkdir(p, mode, function (err) {
if (err && err.code !== 'EEXIST') cb(err)
else cb()
});
});
});
};
exports.mkdirp = exports.mkdirP = module.exports;

View File

@@ -0,0 +1,39 @@
{
"name": "mkdirp",
"description": "Recursively mkdir, like `mkdir -p`",
"version": "0.0.7",
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"main": "./index",
"keywords": [
"mkdir",
"directory"
],
"repository": {
"type": "git",
"url": "http://github.com/substack/node-mkdirp.git"
},
"scripts": {
"test": "node node_modules/tap/bin/tap.js test/*.js"
},
"devDependencies": {
"tap": "0.0.x"
},
"license": "MIT/X11",
"engines": {
"node": "*"
},
"readme": "mkdirp\n======\n\nLike `mkdir -p`, but in node.js!\n\nExample\n=======\n\npow.js\n------\n var mkdirp = require('mkdirp');\n \n mkdirp('/tmp/foo/bar/baz', 0755, function (err) {\n if (err) console.error(err)\n else console.log('pow!')\n });\n\nOutput\n pow!\n\nAnd now /tmp/foo/bar/baz exists, huzzah!\n",
"readmeFilename": "README.markdown",
"bugs": {
"url": "https://github.com/substack/node-mkdirp/issues"
},
"homepage": "https://github.com/substack/node-mkdirp",
"_id": "mkdirp@0.0.7",
"_shasum": "d89b4f0e4c3e5e5ca54235931675e094fe1a5072",
"_from": "mkdirp@0.0.x",
"_resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.0.7.tgz"
}

View File

@@ -0,0 +1 @@
node_modules

View File

@@ -0,0 +1,20 @@
Copyright (c) 2009 cloudhead
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.

View File

@@ -0,0 +1,7 @@
#
# Run all tests
#
test:
@@bin/vows test/*
.PHONY: test install

View File

@@ -0,0 +1,518 @@
#!/usr/bin/env node
var path = require('path'),
fs = require('fs'),
util = require('util'),
events = require('events');
//
// Attempt to load Coffee-Script. If it's not available, continue on our
// merry way, if it is available, set it up so we can include `*.coffee`
// scripts and start searching for them.
//
var fileExt, specFileExt;
try {
var coffee = require('coffee-script');
if (require.extensions) {
require.extensions['.coffee'] = function (module, filename) {
var content = coffee.compile(fs.readFileSync(filename, 'utf8'));
return module._compile(content, filename);
};
} else {
require.registerExtension('.coffee', function (content) { return coffee.compile(content) });
}
fileExt = /\.(js|coffee)$/;
specFileExt = /[.-](test|spec)\.(js|coffee)$/;
} catch (_) {
fileExt = /\.js$/;
specFileExt = /[.-](test|spec)\.js$/;
}
var inspect = require('eyes').inspector({
stream: null,
styles: { string: 'grey', regexp: 'grey' }
});
var vows = require('../lib/vows');
var cutils = require('../lib/vows/console');
var stylize = require('../lib/vows/console').stylize;
var _reporter = require('../lib/vows/reporters/dot-matrix'), reporter = {
name: _reporter.name
};
var _coverage;
var help = [
"usage: vows [FILE, ...] [options]",
"",
"options:",
" -v, --verbose Enable verbose output",
" -w, --watch Watch mode",
" -s, --silent Don't report",
" -i, --isolate Run each test in it's own vows process",
" -m PATTERN Only run tests matching the PATTERN string",
" -r PATTERN Only run tests matching the PATTERN regexp",
" --json Use JSON reporter",
" --spec Use Spec reporter",
" --dot-matrix Use Dot-Matrix reporter",
" --xunit Use xUnit reporter",
" --cover-plain Print plain coverage map if detected",
" --cover-html Write coverage map to \"coverage.html\"",
" --cover-json Write unified coverage map to \"coverage.json\"",
//" --no-color Don't use terminal colors",
" --version Show version",
" -h, --help You're staring at it"
].join('\n');
var options = {
reporter: reporter,
matcher: /.*/,
watch: false,
coverage: false,
isolate: false
};
var files = [];
// Get rid of process runner
// ('node' in most cases)
var arg, args = [], argv = process.argv.slice(2);
// Current directory index,
// and path of test folder.
var root, testFolder;
//
// Parse command-line parameters
//
while (arg = argv.shift()) {
if (arg === __filename) { continue }
if (arg[0] !== '-') {
args.push(arg);
} else {
arg = arg.match(/^--?(.+)/)[1];
if (arg[0] === 'r') {
options.matcher = new(RegExp)(argv.shift());
} else if (arg[0] === 'm') {
options.matcher = (function (str) { // Create an escaped RegExp
var specials = '. * + ? | ( ) [ ] { } \\ ^ ? ! = : $'.split(' ').join('|\\'),
regex = new(RegExp)('(\\' + specials + ')', 'g');
return new(RegExp)(str.replace(regex, '\\$1'));
})(argv.shift());
} else if (arg in options) {
options[arg] = true;
} else {
switch (arg) {
case 'json':
_reporter = require('../lib/vows/reporters/json');
break;
case 'spec':
_reporter = require('../lib/vows/reporters/spec');
break;
case 'dot-matrix':
_reporter = require('../lib/vows/reporters/dot-matrix');
break;
case 'silent':
case 's':
_reporter = require('../lib/vows/reporters/silent');
break;
case 'xunit':
_reporter = require('../lib/vows/reporters/xunit');
break;
case 'cover-plain':
options.coverage = true;
_coverage = require('../lib/vows/coverage/report-plain');
break;
case 'cover-html':
options.coverage = true;
_coverage = require('../lib/vows/coverage/report-html');
break;
case 'cover-json':
options.coverage = true;
_coverage = require('../lib/vows/coverage/report-json');
break;
case 'verbose':
case 'v':
options.verbose = true;
break;
case 'watch':
case 'w':
options.watch = true;
break;
case 'supress-stdout':
options.supressStdout = true;
break;
case 'isolate':
case 'i':
options.isolate = true;
break;
case 'no-color':
options.nocolor = true;
break;
case 'no-error':
options.error = false;
break;
case 'version':
console.log('vows ' + vows.version);
process.exit(0);
case 'help':
case 'h':
console.log(help);
process.exit(0);
break;
}
}
}
}
if (options.supressStdout) {
_reporter.setStream && _reporter.setStream(process.stdout);
var devNullStream = fs.createWriteStream('/dev/null');
process.__defineGetter__('stdout', function () {
return devNullStream;
});
}
if (options.watch) {
options.reporter = reporter = require('../lib/vows/reporters/watch');
}
msg('bin', 'argv', args);
msg('bin', 'options', { reporter: options.reporter.name, matcher: options.matcher });
if (args.length === 0 || options.watch) {
msg('bin', 'discovering', 'folder structure');
root = fs.readdirSync('.');
if (root.indexOf('test') !== -1) {
testFolder = 'test';
} else if (root.indexOf('spec') !== -1) {
testFolder = 'spec';
} else {
abort("runner", "couldn't find test folder");
}
msg('bin', 'discovered', "./" + testFolder);
if (args.length === 0) {
args = paths(testFolder).filter(function (f) {
return new(RegExp)('-' + testFolder + '.(js|coffee)$').test(f);
});
if (options.watch) {
args = args.concat(paths('lib'),
paths('src'));
}
}
}
if (! options.watch) {
reporter.report = function (data, filename) {
switch (data[0]) {
case 'subject':
case 'vow':
case 'context':
case 'error':
_reporter.report(data, filename);
break;
case 'end':
(options.verbose || _reporter.name === 'json') &&
_reporter.report(data);
break;
case 'finish':
options.verbose ?
_reporter.print('\n')
:
_reporter.print(' ');
break;
}
};
reporter.reset = function () { _reporter.reset && _reporter.reset() };
reporter.print = _reporter.print;
files = args.map(function (a) {
return (!a.match(/^\//))
? path.join(process.cwd(), a.replace(fileExt, ''))
: a.replace(fileExt, '');
});
runSuites(importSuites(files), function (results) {
var status = results.errored ? 2 : (results.broken ? 1 : 0);
!options.verbose && _reporter.print('\n');
msg('runner', 'finish');
_reporter.report(['finish', results], {
write: function (str) {
util.print(str.replace(/^\n\n/, '\n'));
}
});
try {
if (options.coverage === true && _$jscoverage !== undefined) {
_coverage.report(_$jscoverage);
}
} catch (err) {
// ignore the undefined jscoverage
}
if (process.stdout.write('')) { // Check if stdout is drained
process.exit(status);
} else {
process.stdout.on('drain', function () {
process.exit(status);
});
}
});
} else {
//
// Watch mode
//
(function () {
var pendulum = [
'. ', '.. ', '... ', ' ...',
' ..', ' .', ' .', ' ..',
'... ', '.. ', '. '
];
var strobe = ['.', ' '];
var status,
cue,
current = 0,
running = 0,
lastRun,
colors = ['32m', '33m', '31m'],
timer = setInterval(tick, 100);
process.on('uncaughtException', cleanup);
process.on('exit', cleanup);
process.on('SIGINT', function () {
process.exit(0);
});
process.on('SIGQUIT', function () {
changed();
});
cursorHide();
// Run every 100ms
function tick() {
if (running && (cue !== strobe)) {
cue = strobe, current = 0;
} else if (!running && (cue !== pendulum)) {
cue = pendulum, current = 0;
}
eraseLine();
lastRun && !running && esc(colors[status.errored ? 2 : (status.broken ? 1 : 0)]);
print(cue[current]);
if (current == cue.length - 1) { current = -1 }
current ++;
esc('39m');
cursorRestore();
}
//
// Utility functions
//
function print(str) { util.print(str) }
function esc(str) { print("\x1b[" + str) }
function eraseLine() { esc("0K") }
function cursorRestore() { esc("0G") }
function cursorHide() { esc("?25l") }
function cursorShow() { esc("?25h") }
function cleanup() { eraseLine(), cursorShow(), clearInterval(timer), print('\n') }
//
// Called when a file has been modified.
// Run the matching tests and change the status.
//
function changed(file) {
status = { honored: 0, broken: 0, errored: 0, pending: 0 };
msg('watcher', 'detected change in', file);
file = (specFileExt.test(file) ? path.join(testFolder, file)
: path.join(testFolder, file + '-' + testFolder));
try {
fs.statSync(file);
} catch (e) {
msg('watcher', 'no equivalence found, running all tests.');
file = null;
}
var files = (specFileExt.test(file) ? [file] : paths(testFolder)).map(function (p) {
return path.join(process.cwd(), p);
}).map(function (p) {
var cache = require.main.moduleCache || require.cache;
if (cache[p]) { delete(cache[p]) }
return p;
}).map(function (p) {
return p.replace(fileExt, '');
});
running ++;
runSuites(importSuites(files), function (results) {
delete(results.time);
print(cutils.result(results).join('') + '\n\n');
lastRun = new(Date);
status = results;
running --;
});
}
msg('watcher', 'watching', args);
//
// Watch all relevant files,
// and call `changed()` on change.
//
args.forEach(function (p) {
fs.watchFile(p, function (current, previous) {
if (new(Date)(current.mtime).valueOf() ===
new(Date)(previous.mtime).valueOf()) { return }
else {
changed(p);
}
});
});
})();
}
function runSuites(suites, callback) {
var results = {
honored: 0,
broken: 0,
errored: 0,
pending: 0,
total: 0,
time: 0
};
reporter.reset();
(function run(suites, callback) {
var suite = suites.shift();
if (suite) {
msg('runner', "running", suite.subject + ' ', options.watch ? false : true);
suite.run(options, function (result) {
Object.keys(result).forEach(function (k) {
results[k] += result[k];
});
run(suites, callback);
});
} else {
callback(results);
}
})(suites, callback);
}
function importSuites(files) {
msg(options.watcher ? 'watcher' : 'runner', 'loading', files);
var spawn = require('child_process').spawn;
function cwdname(f) {
return f.replace(process.cwd() + '/', '') + '.js';
}
function wrapSpawn(f) {
f = cwdname(f);
return function (options, callback) {
var args = [process.argv[1], '--json', '--supress-stdout', f],
p = spawn(process.argv[0], args),
result;
p.on('exit', function (code) {
callback(
!result ?
{errored: 1, total: 1}
:
result
);
});
var buffer = [];
p.stdout.on('data', function (data) {
data = data.toString().split(/\n/g);
if (data.length == 1) {
buffer.push(data[0]);
} else {
data[0] = buffer.concat(data[0]).join('');
buffer = [data.pop()];
data.forEach(function (data) {
if (data) {
data = JSON.parse(data);
if (data && data[0] === 'finish') {
result = data[1];
} else {
reporter.report(data);
}
}
});
}
});
p.stderr.pipe(process.stderr);
}
}
return files.reduce(options.isolate ? function (suites, f) {
return suites.concat({
run: wrapSpawn(f)
});
} : function (suites, f) {
var obj = require(f);
return suites.concat(Object.keys(obj).map(function (s) {
obj[s]._filename = cwdname(f);
return obj[s];
}));
}, [])
}
//
// Recursively traverse a hierarchy, returning
// a list of all relevant .js files.
//
function paths(dir) {
var paths = [];
try { fs.statSync(dir) }
catch (e) { return [] }
(function traverse(dir, stack) {
stack.push(dir);
fs.readdirSync(stack.join('/')).forEach(function (file) {
var path = stack.concat([file]).join('/'),
stat = fs.statSync(path);
if (file[0] == '.' || file === 'vendor') {
return;
} else if (stat.isFile() && fileExt.test(file)) {
paths.push(path);
} else if (stat.isDirectory()) {
traverse(file, stack);
}
});
stack.pop();
})(dir || '.', []);
return paths;
}
function msg(cmd, subject, str, p) {
if (options.verbose) {
util[p ? 'print' : 'puts']( stylize('vows ', 'green')
+ stylize(cmd, 'bold')
+ ' ' + subject + ' '
+ (str ? (typeof(str) === 'string' ? str : inspect(str)) : '')
);
}
}
function abort(cmd, str) {
console.log(stylize('vows ', 'red') + stylize(cmd, 'bold') + ' ' + str);
console.log(stylize('vows ', 'red') + stylize(cmd, 'bold') + ' exiting');
process.exit(-1);
}

View File

@@ -0,0 +1,31 @@
var stylize = require('../vows/console').stylize;
var inspect = require('../vows/console').inspect;
require('assert').AssertionError.prototype.toString = function () {
var that = this,
source;
if (this.stack) {
source = this.stack.match(/([a-zA-Z0-9._-]+\.js)(:\d+):\d+/);
}
function parse(str) {
return str.replace(/{actual}/g, inspect(that.actual)).
replace(/{operator}/g, stylize(that.operator, 'bold')).
replace(/{expected}/g, (that.expected instanceof Function)
? that.expected.name
: inspect(that.expected));
}
if (this.message) {
return stylize(parse(this.message), 'yellow') +
((source) ? stylize(' // ' + source[1] + source[2], 'grey') : '');
} else {
return stylize([
this.expected,
this.operator,
this.actual
].join(' '), 'yellow');
}
};

View File

@@ -0,0 +1,215 @@
var assert = require('assert'),
utils = require('./utils');
var messages = {
'equal' : "expected {expected},\n\tgot\t {actual} ({operator})",
'notEqual' : "didn't expect {actual} ({operator})"
};
messages['strictEqual'] = messages['deepEqual'] = messages['equal'];
messages['notStrictEqual'] = messages['notDeepEqual'] = messages['notEqual'];
for (var key in messages) {
assert[key] = (function (key, callback) {
return function (actual, expected, message) {
callback(actual, expected, message || messages[key]);
};
})(key, assert[key]);
}
assert.ok = (function (callback) {
return function (actual, message) {
callback(actual, message || "expected expression to evaluate to {expected}, but was {actual}");
};
})(assert.ok);
assert.match = function (actual, expected, message) {
if (! expected.test(actual)) {
assert.fail(actual, expected, message || "expected {actual} to match {expected}", "match", assert.match);
}
};
assert.matches = assert.match;
assert.isTrue = function (actual, message) {
if (actual !== true) {
assert.fail(actual, true, message || "expected {expected}, got {actual}", "===", assert.isTrue);
}
};
assert.isFalse = function (actual, message) {
if (actual !== false) {
assert.fail(actual, false, message || "expected {expected}, got {actual}", "===", assert.isFalse);
}
};
assert.isZero = function (actual, message) {
if (actual !== 0) {
assert.fail(actual, 0, message || "expected {expected}, got {actual}", "===", assert.isZero);
}
};
assert.isNotZero = function (actual, message) {
if (actual === 0) {
assert.fail(actual, 0, message || "expected non-zero value, got {actual}", "===", assert.isNotZero);
}
};
assert.greater = function (actual, expected, message) {
if (actual <= expected) {
assert.fail(actual, expected, message || "expected {actual} to be greater than {expected}", ">", assert.greater);
}
};
assert.lesser = function (actual, expected, message) {
if (actual >= expected) {
assert.fail(actual, expected, message || "expected {actual} to be lesser than {expected}", "<", assert.lesser);
}
};
assert.inDelta = function (actual, expected, delta, message) {
var lower = expected - delta;
var upper = expected + delta;
if (actual < lower || actual > upper) {
assert.fail(actual, expected, message || "expected {actual} to be in within *" + delta.toString() + "* of {expected}", null, assert.inDelta);
}
};
//
// Inclusion
//
assert.include = function (actual, expected, message) {
if ((function (obj) {
if (isArray(obj) || isString(obj)) {
return obj.indexOf(expected) === -1;
} else if (isObject(actual)) {
return ! obj.hasOwnProperty(expected);
}
return false;
})(actual)) {
assert.fail(actual, expected, message || "expected {actual} to include {expected}", "include", assert.include);
}
};
assert.includes = assert.include;
assert.deepInclude = function (actual, expected, message) {
if (!isArray(actual)) {
return assert.include(actual, expected, message);
}
if (!actual.some(function (item) { return utils.deepEqual(item, expected) })) {
assert.fail(actual, expected, message || "expected {actual} to include {expected}", "include", assert.deepInclude);
}
};
assert.deepIncludes = assert.deepInclude;
//
// Length
//
assert.isEmpty = function (actual, message) {
if ((isObject(actual) && Object.keys(actual).length > 0) || actual.length > 0) {
assert.fail(actual, 0, message || "expected {actual} to be empty", "length", assert.isEmpty);
}
};
assert.isNotEmpty = function (actual, message) {
if ((isObject(actual) && Object.keys(actual).length === 0) || actual.length === 0) {
assert.fail(actual, 0, message || "expected {actual} to be not empty", "length", assert.isNotEmpty);
}
};
assert.lengthOf = function (actual, expected, message) {
if (actual.length !== expected) {
assert.fail(actual, expected, message || "expected {actual} to have {expected} element(s)", "length", assert.length);
}
};
//
// Type
//
assert.isArray = function (actual, message) {
assertTypeOf(actual, 'array', message || "expected {actual} to be an Array", assert.isArray);
};
assert.isObject = function (actual, message) {
assertTypeOf(actual, 'object', message || "expected {actual} to be an Object", assert.isObject);
};
assert.isNumber = function (actual, message) {
if (isNaN(actual)) {
assert.fail(actual, 'number', message || "expected {actual} to be of type {expected}", "isNaN", assert.isNumber);
} else {
assertTypeOf(actual, 'number', message || "expected {actual} to be a Number", assert.isNumber);
}
};
assert.isBoolean = function (actual, message) {
if (actual !== true && actual !== false) {
assert.fail(actual, 'boolean', message || "expected {actual} to be a Boolean", "===", assert.isBoolean);
}
};
assert.isNaN = function (actual, message) {
if (actual === actual) {
assert.fail(actual, 'NaN', message || "expected {actual} to be NaN", "===", assert.isNaN);
}
};
assert.isNull = function (actual, message) {
if (actual !== null) {
assert.fail(actual, null, message || "expected {expected}, got {actual}", "===", assert.isNull);
}
};
assert.isNotNull = function (actual, message) {
if (actual === null) {
assert.fail(actual, null, message || "expected non-null value, got {actual}", "===", assert.isNotNull);
}
};
assert.isUndefined = function (actual, message) {
if (actual !== undefined) {
assert.fail(actual, undefined, message || "expected {actual} to be {expected}", "===", assert.isUndefined);
}
};
assert.isDefined = function (actual, message) {
if(actual === undefined) {
assert.fail(actual, 0, message || "expected {actual} to be defined", "===", assert.isDefined);
}
};
assert.isString = function (actual, message) {
assertTypeOf(actual, 'string', message || "expected {actual} to be a String", assert.isString);
};
assert.isFunction = function (actual, message) {
assertTypeOf(actual, 'function', message || "expected {actual} to be a Function", assert.isFunction);
};
assert.typeOf = function (actual, expected, message) {
assertTypeOf(actual, expected, message, assert.typeOf);
};
assert.instanceOf = function (actual, expected, message) {
if (! (actual instanceof expected)) {
assert.fail(actual, expected, message || "expected {actual} to be an instance of {expected}", "instanceof", assert.instanceOf);
}
};
//
// Utility functions
//
function assertTypeOf(actual, expected, message, caller) {
if (typeOf(actual) !== expected) {
assert.fail(actual, expected, message || "expected {actual} to be of type {expected}", "typeOf", caller);
}
};
function isArray (obj) {
return Array.isArray(obj);
}
function isString (obj) {
return typeof(obj) === 'string' || obj instanceof String;
}
function isObject (obj) {
return typeof(obj) === 'object' && obj && !isArray(obj);
}
// A better `typeof`
function typeOf(value) {
var s = typeof(value),
types = [Object, Array, String, RegExp, Number, Function, Boolean, Date];
if (s === 'object' || s === 'function') {
if (value) {
types.forEach(function (t) {
if (value instanceof t) { s = t.name.toLowerCase() }
});
} else { s = 'null' }
}
return s;
}

View File

@@ -0,0 +1,77 @@
// Taken from node/lib/assert.js
exports.deepEqual = function (actual, expected) {
if (actual === expected) {
return true;
} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
if (actual.length != expected.length) return false;
for (var i = 0; i < actual.length; i++) {
if (actual[i] !== expected[i]) return false;
}
return true;
} else if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();
} else if (typeof actual != 'object' && typeof expected != 'object') {
return actual == expected;
} else {
return objEquiv(actual, expected);
}
}
// Taken from node/lib/assert.js
exports.notDeepEqual = function (actual, expected, message) {
if (exports.deepEqual(actual, expected)) {
fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
}
}
// Taken from node/lib/assert.js
function isUndefinedOrNull(value) {
return value === null || value === undefined;
}
// Taken from node/lib/assert.js
function isArguments(object) {
return Object.prototype.toString.call(object) == '[object Arguments]';
}
// Taken from node/lib/assert.js
function objEquiv(a, b) {
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
return false;
if (a.prototype !== b.prototype) return false;
if (isArguments(a)) {
if (!isArguments(b)) {
return false;
}
a = pSlice.call(a);
b = pSlice.call(b);
return exports.deepEqual(a, b);
}
try {
var ka = Object.keys(a),
kb = Object.keys(b),
key, i;
} catch (e) {
return false;
}
if (ka.length != kb.length)
return false;
ka.sort();
kb.sort();
for (i = ka.length - 1; i >= 0; i--) {
if (ka[i] != kb[i])
return false;
}
for (i = ka.length - 1; i >= 0; i--) {
key = ka[i];
if (!exports.deepEqual(a[key], b[key])) return false;
}
return true;
}

View File

@@ -0,0 +1,192 @@
//
// Vows.js - asynchronous event-based BDD for node.js
//
// usage:
//
// var vows = require('vows');
//
// vows.describe('Deep Thought').addBatch({
// "An instance of DeepThought": {
// topic: new DeepThought,
//
// "should know the answer to the ultimate question of life": function (deepThought) {
// assert.equal (deepThought.question('what is the answer to the universe?'), 42);
// }
// }
// }).run();
//
var util = require('util'),
path = require('path'),
events = require('events'),
vows = exports;
// Options
vows.options = {
Emitter: events.EventEmitter,
reporter: require('./vows/reporters/dot-matrix'),
matcher: /.*/,
error: true // Handle "error" event
};
vows.__defineGetter__('reporter', function () {
return vows.options.reporter;
});
var stylize = require('./vows/console').stylize;
var console = require('./vows/console');
vows.inspect = require('./vows/console').inspect;
vows.prepare = require('./vows/extras').prepare;
vows.tryEnd = require('./vows/suite').tryEnd;
//
// Assertion Macros & Extensions
//
require('./assert/error');
require('./assert/macros');
//
// Suite constructor
//
var Suite = require('./vows/suite').Suite;
//
// This function gets added to events.EventEmitter.prototype, by default.
// It's essentially a wrapper around `on`, which adds all the specification
// goodness.
//
function addVow(vow) {
var batch = vow.batch;
batch.total ++;
batch.vows.push(vow);
return this.on("success", function () {
var args = Array.prototype.slice.call(arguments);
// If the callback is expecting two or more arguments,
// pass the error as the first (null) and the result after.
if (vow.callback.length >= 2 && batch.suite.options.error) {
args.unshift(null);
}
runTest(args, this.ctx);
vows.tryEnd(batch);
}).on("error", function (err) {
if (vow.callback.length >= 2 || !batch.suite.options.error) {
runTest(arguments, this.ctx);
} else {
output('errored', { type: 'promise', error: err.stack || err.message || JSON.stringify(err) });
}
vows.tryEnd(batch);
});
function runTest(args, ctx) {
if (vow.callback instanceof String) {
return output('pending');
}
// Run the test, and try to catch `AssertionError`s and other exceptions;
// increment counters accordingly.
try {
vow.callback.apply(ctx === global || !ctx ? vow.binding : ctx, args);
output('honored');
} catch (e) {
if (e.name && e.name.match(/AssertionError/)) {
output('broken', e.toString());
} else {
output('errored', e.stack || e.message || e);
}
}
}
function output(status, exception) {
batch[status] ++;
vow.status = status;
if (vow.context && batch.lastContext !== vow.context) {
batch.lastContext = vow.context;
batch.suite.report(['context', vow.context]);
}
batch.suite.report(['vow', {
title: vow.description,
context: vow.context,
status: status,
exception: exception || null
}]);
}
};
//
// On exit, check that all promises have been fired.
// If not, report an error message.
//
process.on('exit', function () {
var results = { honored: 0, broken: 0, errored: 0, pending: 0, total: 0 }, failure;
vows.suites.forEach(function (s) {
if ((s.results.total > 0) && (s.results.time === null)) {
s.reporter.print('\n\n');
s.reporter.report(['error', { error: "Asynchronous Error", suite: s }]);
}
s.batches.forEach(function (b) {
var unFired = [];
b.vows.forEach(function (vow) {
if (! vow.status) {
if (unFired.indexOf(vow.context) === -1) {
unFired.push(vow.context);
}
}
});
if (unFired.length > 0) { util.print('\n') }
unFired.forEach(function (title) {
s.reporter.report(['error', {
error: "callback not fired",
context: title,
batch: b,
suite: s
}]);
});
if (b.status === 'begin') {
failure = true;
results.errored ++;
results.total ++;
}
Object.keys(results).forEach(function (k) { results[k] += b[k] });
});
});
if (failure) {
util.puts(console.result(results));
}
});
vows.suites = [];
//
// Create a new test suite
//
vows.describe = function (subject) {
var suite = new(Suite)(subject);
this.options.Emitter.prototype.addVow = addVow;
this.suites.push(suite);
//
// Add any additional arguments as batches if they're present
//
if (arguments.length > 1) {
for (var i = 1, l = arguments.length; i < l; ++i) {
suite.addBatch(arguments[i]);
}
}
return suite;
};
vows.version = JSON.parse(require('fs')
.readFileSync(path.join(__dirname, '..', 'package.json')))
.version

View File

@@ -0,0 +1,131 @@
var eyes = require('eyes').inspector({ stream: null, styles: false });
// Stylize a string
this.stylize = function stylize(str, style) {
var styles = {
'bold' : [1, 22],
'italic' : [3, 23],
'underline' : [4, 24],
'cyan' : [96, 39],
'yellow' : [33, 39],
'green' : [32, 39],
'red' : [31, 39],
'grey' : [90, 39],
'green-hi' : [92, 32],
};
return '\033[' + styles[style][0] + 'm' + str +
'\033[' + styles[style][1] + 'm';
};
var $ = this.$ = function (str) {
str = new(String)(str);
['bold', 'grey', 'yellow', 'red', 'green', 'white', 'cyan', 'italic'].forEach(function (style) {
Object.defineProperty(str, style, {
get: function () {
return exports.$(exports.stylize(this, style));
}
});
});
return str;
};
this.puts = function (options) {
var stylize = exports.stylize;
options.stream || (options.stream = process.stdout);
options.tail = options.tail || '';
return function (args) {
args = Array.prototype.slice.call(arguments);
if (!options.raw) {
args = args.map(function (a) {
return a.replace(/`([^`]+)`/g, function (_, capture) { return stylize(capture, 'italic') })
.replace(/\*([^*]+)\*/g, function (_, capture) { return stylize(capture, 'bold') });
});
}
return options.stream.write(args.join('\n') + options.tail);
};
};
this.result = function (event) {
var result = [], buffer = [], time = '', header;
var complete = event.honored + event.pending + event.errored + event.broken;
var status = (event.errored && 'errored') || (event.broken && 'broken') ||
(event.honored && 'honored') || (event.pending && 'pending');
if (event.total === 0) {
return [$("Could not find any tests to run.").bold.red];
}
event.honored && result.push($(event.honored).bold + " honored");
event.broken && result.push($(event.broken).bold + " broken");
event.errored && result.push($(event.errored).bold + " errored");
event.pending && result.push($(event.pending).bold + " pending");
if (complete < event.total) {
result.push($(event.total - complete).bold + " dropped");
}
result = result.join(' ∙ ');
header = {
honored: '✓ ' + $('OK').bold.green,
broken: '✗ ' + $('Broken').bold.yellow,
errored: '✗ ' + $('Errored').bold.red,
pending: '- ' + $('Pending').bold.cyan
}[status] + ' » ';
if (typeof(event.time) === 'number') {
time = ' (' + event.time.toFixed(3) + 's)';
time = this.stylize(time, 'grey');
}
buffer.push(header + result + time + '\n');
return buffer;
};
this.inspect = function inspect(val) {
return '\033[1m' + eyes(val) + '\033[22m';
};
this.error = function (obj) {
var string = '✗ ' + $('Errored ').red + '» ';
string += $(obj.error).red.bold + '\n';
string += (obj.context ? ' in ' + $(obj.context).red + '\n': '');
string += ' in ' + $(obj.suite.subject).red + '\n';
string += ' in ' + $(obj.suite._filename).red;
return string;
};
this.contextText = function (event) {
return ' ' + event;
};
this.vowText = function (event) {
var buffer = [];
buffer.push(' ' + {
honored: ' ✓ ',
broken: ' ✗ ',
errored: ' ✗ ',
pending: ' - '
}[event.status] + this.stylize(event.title, ({
honored: 'green',
broken: 'yellow',
errored: 'red',
pending: 'cyan'
})[event.status]));
if (event.status === 'broken') {
buffer.push(' » ' + event.exception);
} else if (event.status === 'errored') {
if (event.exception.type === 'promise') {
buffer.push(' » ' + this.stylize("An unexpected error was caught: " +
this.stylize(event.exception.error, 'bold'), 'red'));
} else {
buffer.push(' ' + this.stylize(event.exception, 'red'));
}
}
return buffer.join('\n');
};

View File

@@ -0,0 +1,55 @@
this.Context = function (vow, ctx, env) {
var that = this;
this.tests = vow.callback;
this.topics = (ctx.topics || []).slice(0);
this.emitter = null;
this.env = env || {};
this.env.context = this;
this.env.callback = function (/* arguments */) {
var ctx = this;
var args = Array.prototype.slice.call(arguments);
var emit = (function (args) {
//
// Convert callback-style results into events.
//
if (vow.batch.suite.options.error) {
return function () {
var e = args.shift();
that.emitter.ctx = ctx;
// We handle a special case, where the first argument is a
// boolean, in which case we treat it as a result, and not
// an error. This is useful for `path.exists` and other
// functions like it, which only pass a single boolean
// parameter instead of the more common (error, result) pair.
if (typeof(e) === 'boolean' && args.length === 0) {
that.emitter.emit.call(that.emitter, 'success', e);
} else {
if (e) { that.emitter.emit.apply(that.emitter, ['error', e].concat(args)) }
else { that.emitter.emit.apply(that.emitter, ['success'].concat(args)) }
}
};
} else {
return function () {
that.emitter.ctx = ctx;
that.emitter.emit.apply(that.emitter, ['success'].concat(args));
};
}
})(args.slice(0));
// If `this.callback` is called synchronously,
// the emitter will not have been set yet,
// so we defer the emition, that way it'll behave
// asynchronously.
if (that.emitter) { emit() }
else { process.nextTick(emit) }
};
this.name = vow.description;
this.title = [
ctx.title || '',
vow.description || ''
].join(/^[#.:]/.test(vow.description) ? '' : ' ').trim();
};

View File

@@ -0,0 +1,29 @@
exports.coverage = function (filename, data) {
var ret = {
filename: filename,
coverage: 0,
hits: 0,
misses: 0,
sloc : 0
};
var source = data.source;
ret.source = source.map(function (line, num) {
num++;
if (data[num] === 0) {
ret.misses++;
ret.sloc++;
} else if (data[num] !== undefined) {
ret.hits++;
ret.sloc++;
}
return { line: line, coverage: (data[num] === undefined ? '' : data[num]) };
});
ret.coverage = (ret.hits / ret.sloc) * 100;
return ret;
};

View File

@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.covered {
background-color: green;
}
.uncovered {
background-color: red;
}
.coverage {
font-size: 0.8em;
color: #333;
}
.coverage.fullCoverage {
background-color:#0f0;
color: #111;
}
.coverage.okCoverage {
background-color: orange;
}
.coverage.poorCoverage {
background-color: red;
}
.code {
font-family: "Consolas", "Courier New", Courier, mono;
white-space: pre;
line-height: 16px;
}
.collapsed {
display: none;
}
body {
margin-left: 20px;
margin-top: 8px;
background-color: white;
color: black;
font-size: 16px;
}
ol {
margin-left: 20px;
margin-bottom: 40px;
width: 800px;
line-height: 18px;
-moz-box-shadow: 10px 10px 5px #888;
-webkit-box-shadow: 10px 10px 5px #888;
box-shadow: 10px 10px 5px #888;
}
</style>
<script type="text/javascript">
function expando(elem) {
// We're skipping the '/n' text element sibling.
var olElement= elem.nextSibling.nextSibling;
var currentState= olElement.className;
if( currentState == "collapsed" ) currentState= "";
else currentState= "collapsed";
olElement.className= currentState;
}
</script>
</head>
<body>

View File

@@ -0,0 +1,54 @@
var util = require('util'),
fs = require('fs'),
file = require('./file');
this.name = 'coverage-report-html';
function getCoverageClass( data ) {
var fullCoverage= (data.coverage == 100);
var okCoverage= (!fullCoverage && data.coverage >=60);
var coverageClass= '';
if( fullCoverage ) coverageClass= 'fullCoverage';
else if( okCoverage) coverageClass= 'okCoverage';
else coverageClass= 'poorCoverage';
return coverageClass;
}
this.report = function (coverageMap) {
var out, head, foot;
try {
out = fs.openSync("coverage.html", "w");
head = fs.readFileSync(__dirname + "/fragments/coverage-head.html", "utf8");
foot = fs.readFileSync(__dirname + "/fragments/coverage-foot.html", "utf8");
} catch (error) {
util.print("Error: Unable to write to file coverage.html\n");
return;
}
fs.writeSync(out, head);
for (var filename in coverageMap) {
if (coverageMap.hasOwnProperty(filename)) {
var data = file.coverage(filename, coverageMap[filename]);
var coverageClass= getCoverageClass( data );
fs.writeSync(out, "<h2>" + filename + "</h2>\n");
fs.writeSync(out, '<span class="coverage '+ coverageClass+'">' + "[ hits: " + data.hits);
fs.writeSync(out, ", misses: " + data.misses + ", sloc: " + data.sloc);
fs.writeSync(out, ", coverage: " + data.coverage.toFixed(2) + "% ]" + "</span> <a href='#' onclick='expando(this)'>[+]</a>\n");
fs.writeSync(out, "<ol class='collapsed'>\n");
for (var i = 0; i < data.source.length; i++) {
fs.writeSync(out, ' <li class="code ');
fs.writeSync(out, (data.source[i].coverage === 0 ? 'uncovered' : 'covered'));
fs.writeSync(out, '" coverage="' + data.source[i].coverage + '">');
fs.writeSync(out, data.source[i].line + "</li>\n");
}
fs.writeSync(out, "</ol>\n");
fs.writeSync(out, "<hr/>\n");
}
}
fs.writeSync(out, foot);
fs.close(out);
};

View File

@@ -0,0 +1,54 @@
var util = require('util'),
fs = require('fs'),
file = require('./file');
this.name = 'coverage-report-json';
this.report = function (coverageMap) {
var output = {
meta: {
"generator": "vowsjs",
"generated": new Date().toString(),
"instrumentation": "node-jscoverage",
"file-version": "1.0"
},
files: [ ],
coverage: [ ]
};
for (var filename in coverageMap) {
if (coverageMap.hasOwnProperty(filename)) {
var data = file.coverage(filename, coverageMap[filename]);
var coverage = {
file: filename,
coverage: data.coverage.toFixed(2),
hits: data.hits,
misses: data.misses,
sloc: data.sloc,
source: { }
};
for (var i = 0; i < data.source.length; i++) {
coverage.source[i + 1] = {
line: data.source[i].line,
coverage: data.source[i].coverage
};
}
output.coverage.push(coverage);
output.files.push(filename);
}
}
try {
out = fs.openSync("coverage.json", "w");
fs.writeSync(out, JSON.stringify(output));
fs.close(out);
} catch (error) {
util.print("Error: Unable to write to file coverage.json\n");
return;
}
};

View File

@@ -0,0 +1,38 @@
var util = require('util'),
file = require('./file');
this.name = 'coverage-report-plain';
function lpad(str, width) {
str = String(str);
var n = width - str.length;
if (n < 1) {
return str;
}
while (n--) {
str = ' ' + str;
}
return str;
}
this.report = function (coverageMap) {
for (var filename in coverageMap) {
if (coverageMap.hasOwnProperty(filename)) {
var data = file.coverage(filename, coverageMap[filename]);
util.print(filename + ":\n");
util.print("[ hits: " + data.hits + ", misses: " + data.misses);
util.print(", sloc: " + data.sloc + ", coverage: " + data.coverage.toFixed(2) + "% ]\n");
for (var i = 0; i < data.source.length; i++) {
util.print(lpad(data.source[i].coverage, 5) + " | " + data.source[i].line + "\n");
}
util.print("\n");
}
}
};

View File

@@ -0,0 +1,28 @@
var events = require('events');
//
// Wrap a Node.js style async function into an EventEmmitter
//
this.prepare = function (obj, targets) {
targets.forEach(function (target) {
if (target in obj) {
obj[target] = (function (fun) {
return function () {
var args = Array.prototype.slice.call(arguments);
var ee = new(events.EventEmitter);
args.push(function (err /* [, data] */) {
var args = Array.prototype.slice.call(arguments, 1);
if (err) { ee.emit.apply(ee, ['error', err].concat(args)) }
else { ee.emit.apply(ee, ['success'].concat(args)) }
});
fun.apply(obj, args);
return ee;
};
})(obj[target]);
}
});
return obj;
};

View File

@@ -0,0 +1,67 @@
var options = { tail: '' },
console = require('../../vows/console'),
stylize = console.stylize,
puts = console.puts(options);
//
// Console reporter
//
var messages = [], lastContext;
this.name = 'dot-matrix';
this.setStream = function (s) {
options.stream = s;
};
this.reset = function () {
messages = [];
lastContext = null;
};
this.report = function (data) {
var event = data[1];
switch (data[0]) {
case 'subject':
// messages.push(stylize(event, 'underline') + '\n');
break;
case 'context':
break;
case 'vow':
if (event.status === 'honored') {
puts(stylize('·', 'green'));
} else if (event.status === 'pending') {
puts(stylize('-', 'cyan'));
} else {
if (lastContext !== event.context) {
lastContext = event.context;
messages.push(' ' + event.context);
}
if (event.status === 'broken') {
puts(stylize('✗', 'yellow'));
messages.push(console.vowText(event));
} else if (event.status === 'errored') {
puts(stylize('✗', 'red'));
messages.push(console.vowText(event));
}
messages.push('');
}
break;
case 'end':
puts(' ');
break;
case 'finish':
if (messages.length) {
puts('\n\n' + messages.join('\n'));
} else {
puts('');
}
puts(console.result(event).join('\n'));
break;
case 'error':
puts(console.error(event));
break;
}
};
this.print = function (str) {
puts(str);
};

View File

@@ -0,0 +1,16 @@
var options = { tail: '\n', raw: true };
var console = require('../../vows/console');
var puts = console.puts(options);
//
// Console JSON reporter
//
this.name = 'json';
this.setStream = function (s) {
options.stream = s;
};
this.report = function (obj) {
puts(JSON.stringify(obj));
};
this.print = function (str) {};

View File

@@ -0,0 +1,8 @@
//
// Silent reporter - "Shhh"
//
this.name = 'silent';
this.reset = function () {};
this.report = function () {};
this.print = function () {};

View File

@@ -0,0 +1,44 @@
var util = require('util');
var options = { tail: '\n' };
var console = require('../../vows/console');
var stylize = console.stylize,
puts = console.puts(options);
//
// Console reporter
//
this.name = 'spec';
this.setStream = function (s) {
options.stream = s;
};
this.report = function (data) {
var event = data[1];
buffer = [];
switch (data[0]) {
case 'subject':
puts('\n♢ ' + stylize(event, 'bold') + '\n');
break;
case 'context':
puts(console.contextText(event));
break;
case 'vow':
puts(console.vowText(event));
break;
case 'end':
util.print('\n');
break;
case 'finish':
puts(console.result(event).join('\n'));
break;
case 'error':
puts(console.error(event));
break;
}
};
this.print = function (str) {
util.print(str);
};

View File

@@ -0,0 +1,37 @@
var options = {};
var console = require('../../vows/console');
var spec = require('../../vows/reporters/spec');
var stylize = console.stylize,
puts = console.puts(options);
//
// Console reporter
//
var lastContext;
this.name = 'watch';
this.setStream = function (s) {
options.stream = s;
};
this.reset = function () {
lastContext = null;
};
this.report = function (data) {
var event = data[1];
switch (data[0]) {
case 'vow':
if (['honored', 'pending'].indexOf(event.status) === -1) {
if (lastContext !== event.context) {
lastContext = event.context;
puts(console.contextText(event.context));
}
puts(console.vowText(event));
puts('');
}
break;
case 'error':
puts(console.error(event));
break;
}
};
this.print = function (str) {};

View File

@@ -0,0 +1,90 @@
// xunit outoput for vows, so we can run things under hudson
//
// The translation to xunit is simple. Most likely more tags/attributes can be
// added, see: http://ant.1045680.n5.nabble.com/schema-for-junit-xml-output-td1375274.html
//
var puts = require('util').puts;
var buffer = [],
curSubject = null;
function xmlEnc(value) {
return !value ? value : String(value).replace(/&/g, "&amp;")
.replace(/>/g, "&gt;")
.replace(/</g, "&lt;")
.replace(/"/g, "&quot;")
.replace(/\u001b\[\d{1,2}m/g, '');
}
function tag(name, attribs, single, content) {
var strAttr = [], t, end = '>';
for (var attr in attribs) {
if (attribs.hasOwnProperty(attr)) {
strAttr.push(attr + '="' + xmlEnc(attribs[attr]) + '"');
}
}
if (single) {
end = ' />';
}
if (strAttr.length) {
t = '<' + name + ' ' + strAttr.join(' ') + end;
} else {
t = '<' + name + end;
}
if (typeof content !== 'undefined') {
return t + content + '</' + name + end;
}
return t;
}
function end(name) {
return '</' + name + '>';
}
function cdata(data) {
return '<![CDATA[' + xmlEnc(data) + ']]>';
}
this.name = 'xunit';
this.report = function (data) {
var event = data[1];
switch (data[0]) {
case 'subject':
curSubject = event;
break;
case 'context':
break;
case 'vow':
switch (event.status) {
case 'honored':
buffer.push(tag('testcase', {classname: curSubject, name: event.context + ': ' + event.title}, true));
break;
case 'broken':
var err = tag('error', {type: 'vows.event.broken', message: 'Broken test'}, false, cdata(event.exception));
buffer.push(tag('testcase', {classname: curSubject, name: event.context + ': ' + event.title}, false, err));
break;
case 'errored':
var skip = tag('skipped', {type: 'vows.event.errored', message: 'Errored test'}, false, cdata(event.exception));
buffer.push(tag('testcase', {classname: curSubject, name: event.context + ': ' + event.title}, false, skip));
break;
case 'pending':
// nop
break;
}
break;
case 'end':
buffer.push(end('testcase'));
break;
case 'finish':
buffer.unshift(tag('testsuite', {name: 'Vows test', tests: event.total, timestamp: (new Date()).toUTCString(), errors: event.errored, failures: event.broken, skip: event.pending, time: event.time}));
buffer.push(end('testsuite'));
puts(buffer.join('\n'));
break;
case 'error':
break;
}
};
this.print = function (str) { };

View File

@@ -0,0 +1,319 @@
var events = require('events'),
path = require('path');
var vows = require('../vows');
var Context = require('../vows/context').Context;
this.Suite = function (subject) {
this.subject = subject;
this.matcher = /.*/;
this.reporter = require('./reporters/dot-matrix');
this.batches = [];
this.options = { error: true };
this.reset();
};
this.Suite.prototype = new(function () {
this.reset = function () {
this.results = {
honored: 0,
broken: 0,
errored: 0,
pending: 0,
total: 0,
time: null
};
this.batches.forEach(function (b) {
b.lastContext = null;
b.remaining = b._remaining;
b.honored = b.broken = b.errored = b.total = b.pending = 0;
b.vows.forEach(function (vow) { vow.status = null });
b.teardowns = [];
});
};
this.addBatch = function (tests) {
this.batches.push({
tests: tests,
suite: this,
vows: [],
remaining: 0,
_remaining: 0,
honored: 0,
broken: 0,
errored: 0,
pending: 0,
total: 0,
teardowns: []
});
return this;
};
this.addVows = this.addBatch;
this.parseBatch = function (batch, matcher) {
var tests = batch.tests;
if ('topic' in tests) {
throw new(Error)("missing top-level context.");
}
// Count the number of vows/promises expected to fire,
// so we know when the tests are over.
// We match the keys against `matcher`, to decide
// whether or not they should be included in the test.
// Any key, including assertion function keys can be matched.
// If a child matches, then the n parent topics must not be skipped.
(function count(tests, _match) {
var match = false;
var keys = Object.keys(tests).filter(function (k) {
return k !== 'topic' && k !== 'teardown';
});
for (var i = 0, key; i < keys.length; i++) {
key = keys[i];
// If the parent node, or this one matches.
match = _match || matcher.test(key);
if (typeof(tests[key]) === 'object') {
match = count(tests[key], match);
} else {
if (typeof(tests[key]) === 'string') {
tests[key] = new(String)(tests[key]);
}
if (! match) {
tests[key]._skip = true;
}
}
}
// If any of the children matched,
// don't skip this node.
for (var i = 0; i < keys.length; i++) {
if (! tests[keys[i]]._skip) { match = true }
}
if (match) { batch.remaining ++ }
else { tests._skip = true }
return match;
})(tests, false);
batch._remaining = batch.remaining;
};
this.runBatch = function (batch) {
var topic,
tests = batch.tests,
promise = batch.promise = new(events.EventEmitter);
var that = this;
batch.status = 'begin';
// The test runner, it calls itself recursively, passing the
// previous context to the inner contexts. This is so the `topic`
// functions have access to all the previous context topics in their
// arguments list.
// It is defined and invoked at the same time.
// If it encounters a `topic` function, it waits for the returned
// promise to emit (the topic), at which point it runs the functions under it,
// passing the topic as an argument.
(function run(ctx, lastTopic) {
var old = false;
topic = ctx.tests.topic;
if (typeof(topic) === 'function') {
// Run the topic, passing the previous context topics
topic = topic.apply(ctx.env, ctx.topics);
if (typeof(topic) === 'undefined') { ctx._callback = true }
}
// If this context has a topic, store it in `lastTopic`,
// if not, use the last topic, passed down by a parent
// context.
if (typeof(topic) !== 'undefined' || ctx._callback) {
lastTopic = topic;
} else {
old = true;
topic = lastTopic;
}
// If the topic doesn't return an event emitter (such as a promise),
// we create it ourselves, and emit the value on the next tick.
if (! (topic && topic.constructor === events.EventEmitter)) {
ctx.emitter = new(events.EventEmitter);
if (! ctx._callback) {
process.nextTick(function (val) {
return function () { ctx.emitter.emit("success", val) };
}(topic));
}
topic = ctx.emitter;
}
topic.on('success', function (val) {
// Once the topic fires, add the return value
// to the beginning of the topics list, so it
// becomes the first argument for the next topic.
// If we're using the parent topic, no need to
// prepend it to the topics list, or we'll get
// duplicates.
if (! old) Array.prototype.unshift.apply(ctx.topics, arguments);
});
if (topic.setMaxListeners) { topic.setMaxListeners(Infinity) }
// Now run the tests, or sub-contexts
Object.keys(ctx.tests).filter(function (k) {
return ctx.tests[k] && k !== 'topic' &&
k !== 'teardown' && !ctx.tests[k]._skip;
}).forEach(function (item) {
// Create a new evaluation context,
// inheriting from the parent one.
var env = Object.create(ctx.env);
env.suite = that;
// Holds the current test or context
var vow = Object.create({
callback: ctx.tests[item],
context: ctx.title,
description: item,
binding: ctx.env,
status: null,
batch: batch
});
// If we encounter a function, add it to the callbacks
// of the `topic` function, so it'll get called once the
// topic fires.
// If we encounter an object literal, we recurse, sending it
// our current context.
if ((typeof(vow.callback) === 'function') || (vow.callback instanceof String)) {
topic.addVow(vow);
} else if (typeof(vow.callback) === 'object') {
// If there's a setup stage, we have to wait for it to fire,
// before calling the inner context. Else, just run the inner context
// synchronously.
if (topic) {
topic.on("success", function (ctx) {
return function (val) {
return run(new(Context)(vow, ctx, env), lastTopic);
};
}(ctx));
} else {
run(new(Context)(vow, ctx, env), lastTopic);
}
}
});
// Teardown
if (ctx.tests.teardown) {
batch.teardowns.push(ctx);
}
if (! ctx.tests._skip) {
batch.remaining --;
}
// Check if we're done running the tests
exports.tryEnd(batch);
// This is our initial, empty context
})(new(Context)({ callback: tests, context: null, description: null }, {}));
return promise;
};
this.report = function () {
return this.reporter.report.apply(this.reporter, arguments);
};
this.run = function (options, callback) {
var that = this, start;
options = options || {};
for (var k in options) { this.options[k] = options[k] }
this.matcher = this.options.matcher || this.matcher;
this.reporter = this.options.reporter || this.reporter;
this.batches.forEach(function (batch) {
that.parseBatch(batch, that.matcher);
});
this.reset();
start = new(Date);
if (this.batches.filter(function (b) { return b.remaining > 0 }).length) {
this.report(['subject', this.subject]);
}
return (function run(batches) {
var batch = batches.shift();
if (batch) {
// If the batch has no vows to run,
// go to the next one.
if (batch.remaining === 0) {
run(batches);
} else {
that.runBatch(batch).on('end', function () {
run(batches);
});
}
} else {
that.results.time = (new(Date) - start) / 1000;
that.report(['finish', that.results]);
if (callback) { callback(that.results) }
if (that.results.honored + that.results.pending === that.results.total) {
return 0;
} else {
return 1;
}
}
})(this.batches.slice(0));
};
this.runParallel = function () {};
this.export = function (module, options) {
for (var k in (options || {})) { this.options[k] = options[k] }
if (require.main === module) {
return this.run();
} else {
return module.exports[this.subject] = this;
}
};
this.exportTo = function (module, options) { // Alias, for JSLint
return this.export(module, options);
};
});
//
// Checks if all the tests in the batch have been run,
// and triggers the next batch (if any), by emitting the 'end' event.
//
this.tryEnd = function (batch) {
var result, style, time;
if (batch.honored + batch.broken + batch.errored + batch.pending === batch.total &&
batch.remaining === 0) {
Object.keys(batch).forEach(function (k) {
(k in batch.suite.results) && (batch.suite.results[k] += batch[k]);
});
// Run teardowns
if (batch.teardowns) {
for (var i = batch.teardowns.length - 1, ctx; i >= 0; i--) {
ctx = batch.teardowns[i];
ctx.tests.teardown.apply(ctx.env, ctx.topics);
}
}
batch.status = 'end';
batch.suite.report(['end']);
batch.promise.emit('end', batch.honored, batch.broken, batch.errored, batch.pending);
}
};

View File

@@ -0,0 +1,45 @@
{
"name": "vows",
"description": "Asynchronous BDD & continuous integration for node.js",
"url": "http://vowsjs.org",
"keywords": [
"testing",
"spec",
"test",
"BDD"
],
"author": {
"name": "Alexis Sellier",
"email": "self@cloudhead.net"
},
"contributors": [
{
"name": "Charlie Robbins",
"email": "charlie.robbins@gmail.com"
}
],
"dependencies": {
"eyes": ">=0.1.6"
},
"main": "./lib/vows",
"bin": {
"vows": "./bin/vows"
},
"directories": {
"test": "./test",
"bin": "./bin"
},
"version": "0.5.13",
"scripts": {
"test": "./bin/vows --spec"
},
"engines": {
"node": ">=0.2.6"
},
"readme": "Vows\n====\n\n> Asynchronous BDD & continuous integration for node.js\n\n#### <http://vowsjs.org> #\n\nintroduction\n------------\nThere are two reasons why we might want asynchronous testing. The first, and obvious reason is that node.js is asynchronous, and therefore our tests need to be. The second reason is to make test suites which target I/O libraries run much faster.\n\n_Vows_ is an experiment in making this possible, while adding a minimum of overhead.\n\nsynopsis\n--------\n\n var vows = require('vows'),\n assert = require('assert');\n\n vows.describe('Deep Thought').addBatch({\n 'An instance of DeepThought': {\n topic: new DeepThought,\n\n 'should know the answer to the ultimate question of life': function (deepThought) {\n assert.equal (deepThought.question('what is the answer to the universe?'), 42);\n }\n }\n });\n\ninstallation\n------------\n\n $ npm install vows\n\ndocumentation\n-------------\n\nHead over to <http://vowsjs.org>\n\nauthors\n-------\n\nAlexis Sellier <<alexis@cloudhead.io>>, Charlie Robbins,\n\n*...and many others*\n\n",
"readmeFilename": "README.md",
"_id": "vows@0.5.13",
"_shasum": "f6fd9ee9c36d3f20bd6680455cff8090c4b29cde",
"_from": "vows@0.5.x",
"_resolved": "https://registry.npmjs.org/vows/-/vows-0.5.13.tgz"
}

View File

@@ -0,0 +1,42 @@
{
"name": "portfinder",
"version": "0.2.1",
"description": "A simple tool to find an open port on the current machine",
"author": {
"name": "Charlie Robbins",
"email": "charlie.robbins@gmail.com"
},
"repository": {
"type": "git",
"url": "git@github.com:indexzero/node-portfinder.git"
},
"keywords": [
"http",
"ports",
"utilities"
],
"dependencies": {
"mkdirp": "0.0.x"
},
"devDependencies": {
"async": "0.1.x",
"vows": "0.5.x"
},
"main": "./lib/portfinder",
"scripts": {
"test": "vows test/*-test.js --spec"
},
"engines": {
"node": ">= 0.4.0"
},
"readme": "# node-portfinder\n\n## Installation\n\n### Installing npm (node package manager)\n``` bash\n curl http://npmjs.org/install.sh | sh\n```\n\n### Installing node-portfinder\n``` bash\n $ [sudo] npm install portfinder\n```\n\n## Usage\nThe `portfinder` module has a simple interface:\n\n``` js\n var portfinder = require('portfinder');\n \n portfinder.getPort(function (err, port) {\n //\n // `port` is guarenteed to be a free port \n // in this scope.\n //\n });\n```\n\nBy default `portfinder` will start searching from `8000`. To change this simply set `portfinder.basePort`.\n\n## Run Tests\n``` bash\n $ npm test\n```\n\n#### Author: [Charlie Robbins][0]\n[0]: http://nodejitsu.com",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/indexzero/node-portfinder/issues"
},
"homepage": "https://github.com/indexzero/node-portfinder",
"_id": "portfinder@0.2.1",
"_shasum": "b2b9b0164f9e17fa3a9c7db2304d0a75140c71ad",
"_from": "portfinder@0.2.x",
"_resolved": "https://registry.npmjs.org/portfinder/-/portfinder-0.2.1.tgz"
}