From 686106d544ecc3b6ffd4db2b665d3bc879a58d8c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 24 Sep 2012 16:22:07 -0400 Subject: ok --- node_modules/mongoose/support/expresso/.gitmodules | 3 + node_modules/mongoose/support/expresso/.npmignore | 3 + node_modules/mongoose/support/expresso/History.md | 128 +++ node_modules/mongoose/support/expresso/Makefile | 53 + node_modules/mongoose/support/expresso/Readme.md | 61 ++ .../mongoose/support/expresso/bin/expresso | 874 ++++++++++++++++ .../mongoose/support/expresso/docs/api.html | 1080 ++++++++++++++++++++ .../mongoose/support/expresso/docs/index.html | 377 +++++++ .../mongoose/support/expresso/docs/index.md | 290 ++++++ .../support/expresso/docs/layout/foot.html | 3 + .../support/expresso/docs/layout/head.html | 42 + node_modules/mongoose/support/expresso/lib/bar.js | 4 + node_modules/mongoose/support/expresso/lib/foo.js | 16 + .../mongoose/support/expresso/package.json | 12 + .../mongoose/support/expresso/test/assert.test.js | 91 ++ .../mongoose/support/expresso/test/async.test.js | 12 + .../mongoose/support/expresso/test/bar.test.js | 13 + .../mongoose/support/expresso/test/foo.test.js | 14 + .../mongoose/support/expresso/test/http.test.js | 109 ++ .../support/expresso/test/serial/async.test.js | 39 + .../support/expresso/test/serial/http.test.js | 48 + 21 files changed, 3272 insertions(+) create mode 100644 node_modules/mongoose/support/expresso/.gitmodules create mode 100644 node_modules/mongoose/support/expresso/.npmignore create mode 100644 node_modules/mongoose/support/expresso/History.md create mode 100644 node_modules/mongoose/support/expresso/Makefile create mode 100644 node_modules/mongoose/support/expresso/Readme.md create mode 100755 node_modules/mongoose/support/expresso/bin/expresso create mode 100644 node_modules/mongoose/support/expresso/docs/api.html create mode 100644 node_modules/mongoose/support/expresso/docs/index.html create mode 100644 node_modules/mongoose/support/expresso/docs/index.md create mode 100644 node_modules/mongoose/support/expresso/docs/layout/foot.html create mode 100644 node_modules/mongoose/support/expresso/docs/layout/head.html create mode 100644 node_modules/mongoose/support/expresso/lib/bar.js create mode 100644 node_modules/mongoose/support/expresso/lib/foo.js create mode 100644 node_modules/mongoose/support/expresso/package.json create mode 100644 node_modules/mongoose/support/expresso/test/assert.test.js create mode 100644 node_modules/mongoose/support/expresso/test/async.test.js create mode 100644 node_modules/mongoose/support/expresso/test/bar.test.js create mode 100644 node_modules/mongoose/support/expresso/test/foo.test.js create mode 100644 node_modules/mongoose/support/expresso/test/http.test.js create mode 100644 node_modules/mongoose/support/expresso/test/serial/async.test.js create mode 100644 node_modules/mongoose/support/expresso/test/serial/http.test.js (limited to 'node_modules/mongoose/support') diff --git a/node_modules/mongoose/support/expresso/.gitmodules b/node_modules/mongoose/support/expresso/.gitmodules new file mode 100644 index 0000000..191ddeb --- /dev/null +++ b/node_modules/mongoose/support/expresso/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/jscoverage"] + path = deps/jscoverage + url = git://github.com/visionmedia/node-jscoverage.git diff --git a/node_modules/mongoose/support/expresso/.npmignore b/node_modules/mongoose/support/expresso/.npmignore new file mode 100644 index 0000000..432563f --- /dev/null +++ b/node_modules/mongoose/support/expresso/.npmignore @@ -0,0 +1,3 @@ +.DS_Store +lib-cov +*.seed \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/History.md b/node_modules/mongoose/support/expresso/History.md new file mode 100644 index 0000000..cb16fa9 --- /dev/null +++ b/node_modules/mongoose/support/expresso/History.md @@ -0,0 +1,128 @@ + +0.7.2 / 2010-12-29 +================== + + * Fixed problem with `listen()` sometimes firing on the same tick [guillermo] + +0.7.1 / 2010-12-28 +================== + + * Fixed `assert.request()` client logic into an issue() function, fired upon the `listen()` callback if the server doesn't have an assigned fd. [guillermo] + * Removed `--watch` + +0.7.0 / 2010-11-19 +================== + + * Removed `assert` from test function signature + Just use `require('assert')` :) this will make integration + with libraries like [should](http://github.com/visionmedia/should) cleaner. + +0.6.4 / 2010-11-02 +================== + + * Added regexp support to `assert.response()` headers + * Removed `waitForExit` code, causing issues + +0.6.3 / 2010-11-02 +================== + + * Added `assert.response()` body RegExp support + * Fixed issue with _--serial_ not executing files sequentially. Closes #42 + * Fixed hang when modules use `setInterval` - monitor running tests & force the process to quit after all have completed + timeout [Steve Mason] + +0.6.2 / 2010-09-17 +================== + + * Added _node-jsocoverage_ to package.json (aka will respect npm's binroot) + * Added _-t, --timeout_ MS option, defaulting to 2000 ms + * Added _-s, --serial_ + * __PREFIX__ clobberable + * Fixed `assert.response()` for latest node + * Fixed cov reporting from exploding on empty files + +0.6.2 / 2010-08-03 +================== + + * Added `assert.type()` + * Renamed `assert.isNotUndefined()` to `assert.isDefined()` + * Fixed `assert.includes()` param ordering + +0.6.0 / 2010-07-31 +================== + + * Added _docs/api.html_ + * Added -w, --watch + * Added `Array` support to `assert.includes()` + * Added; outputting exceptions immediately. Closes #19 + * Fixed `assert.includes()` param ordering + * Fixed `assert.length()` param ordering + * Fixed jscoverage links + +0.5.0 / 2010-07-16 +================== + + * Added support for async exports + * Added timeout support to `assert.response()`. Closes #3 + * Added 4th arg callback support to `assert.response()` + * Added `assert.length()` + * Added `assert.match()` + * Added `assert.isUndefined()` + * Added `assert.isNull()` + * Added `assert.includes()` + * Added growlnotify support via -g, --growl + * Added -o, --only TESTS. Ex: --only "test foo()" --only "test foo(), test bar()" + * Removed profanity + +0.4.0 / 2010-07-09 +================== + + * Added reporting source coverage (respects --boring for color haters) + * Added callback to assert.response(). Closes #12 + * Fixed; putting exceptions to stderr. Closes #13 + +0.3.1 / 2010-06-28 +================== + + * Faster assert.response() + +0.3.0 / 2010-06-28 +================== + + * Added -p, --port NUM flags + * Added assert.response(). Closes #11 + +0.2.1 / 2010-06-25 +================== + + * Fixed issue with reporting object assertions + +0.2.0 / 2010-06-21 +================== + + * Added `make uninstall` + * Added better readdir() failure message + * Fixed `make install` for kiwi + +0.1.0 / 2010-06-15 +================== + + * Added better usage docs via --help + * Added better conditional color support + * Added pre exit assertion support + +0.0.3 / 2010-06-02 +================== + + * Added more room for filenames in test coverage + * Added boring output support via --boring (suppress colored output) + * Fixed async failure exit status + +0.0.2 / 2010-05-30 +================== + + * Fixed exit status for CI support + +0.0.1 / 2010-05-30 +================== + + * Initial release \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/Makefile b/node_modules/mongoose/support/expresso/Makefile new file mode 100644 index 0000000..8acfe56 --- /dev/null +++ b/node_modules/mongoose/support/expresso/Makefile @@ -0,0 +1,53 @@ + +PREFIX ?= /usr/local +BIN = bin/expresso +JSCOV = deps/jscoverage/node-jscoverage +DOCS = docs/index.md +HTMLDOCS = $(DOCS:.md=.html) + +test: $(BIN) + @./$(BIN) -I lib --growl $(TEST_FLAGS) test/*.test.js + +test-cov: + @./$(BIN) -I lib --cov $(TEST_FLAGS) test/*.test.js + +test-serial: + @./$(BIN) --serial -I lib $(TEST_FLAGS) test/serial/*.test.js + +install: install-jscov install-expresso + +uninstall: + rm -f $(PREFIX)/bin/expresso + rm -f $(PREFIX)/bin/node-jscoverage + +install-jscov: $(JSCOV) + install $(JSCOV) $(PREFIX)/bin + +install-expresso: + install $(BIN) $(PREFIX)/bin + +$(JSCOV): + cd deps/jscoverage && ./configure && make && mv jscoverage node-jscoverage + +clean: + @cd deps/jscoverage && git clean -fd + +docs: docs/api.html $(HTMLDOCS) + +%.html: %.md + @echo "... $< > $@" + @ronn -5 --pipe --fragment $< \ + | cat docs/layout/head.html - docs/layout/foot.html \ + > $@ + +docs/api.html: bin/expresso + dox \ + --title "Expresso" \ + --ribbon "http://github.com/visionmedia/expresso" \ + --desc "Insanely fast TDD framework for [node](http://nodejs.org) featuring code coverage reporting." \ + $< > $@ + +docclean: + rm -f docs/*.html + +.PHONY: test test-cov install uninstall install-expresso install-jscov clean docs docclean \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/Readme.md b/node_modules/mongoose/support/expresso/Readme.md new file mode 100644 index 0000000..05c972e --- /dev/null +++ b/node_modules/mongoose/support/expresso/Readme.md @@ -0,0 +1,61 @@ + +# Expresso + + TDD framework for [nodejs](http://nodejs.org). + +## Features + + - light-weight + - intuitive async support + - intuitive test runner executable + - test coverage support and reporting + - uses the _assert_ module + - `assert.eql()` alias of `assert.deepEqual()` + - `assert.response()` http response utility + - `assert.includes()` + - `assert.type()` + - `assert.isNull()` + - `assert.isUndefined()` + - `assert.isNotNull()` + - `assert.isDefined()` + - `assert.match()` + - `assert.length()` + +## Installation + +To install both expresso _and_ node-jscoverage run: + + $ make install + +To install expresso alone (no build required) run: + + $ make install-expresso + +Install via npm: + + $ npm install expresso + +## License + +(The MIT License) + +Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca> + +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. diff --git a/node_modules/mongoose/support/expresso/bin/expresso b/node_modules/mongoose/support/expresso/bin/expresso new file mode 100755 index 0000000..fd98fff --- /dev/null +++ b/node_modules/mongoose/support/expresso/bin/expresso @@ -0,0 +1,874 @@ +#!/usr/bin/env node + +/* + * Expresso + * Copyright(c) TJ Holowaychuk + * (MIT Licensed) + */ + +/** + * Module dependencies. + */ + +var assert = require('assert'), + childProcess = require('child_process'), + http = require('http'), + path = require('path'), + sys = require('sys'), + cwd = process.cwd(), + fs = require('fs'), + defer; + +/** + * Expresso version. + */ + +var version = '0.7.2'; + +/** + * Failure count. + */ + +var failures = 0; + + +/** + * Number of tests executed. + */ + +var testcount = 0; + +/** + * Whitelist of tests to run. + */ + +var only = []; + +/** + * Boring output. + */ + +var boring = false; + +/** + * Growl notifications. + */ + +var growl = false; + +/** + * Server port. + */ + +var port = 5555; + +/** + * Execute serially. + */ + +var serial = false; + +/** + * Default timeout. + */ + +var timeout = 2000; + +/** + * Quiet output. + */ + +var quiet = false; + +/** + * Usage documentation. + */ + +var usage = '' + + '[bold]{Usage}: expresso [options] ' + + '\n' + + '\n[bold]{Options}:' + + '\n -g, --growl Enable growl notifications' + + '\n -c, --coverage Generate and report test coverage' + + '\n -q, --quiet Suppress coverage report if 100%' + + '\n -t, --timeout MS Timeout in milliseconds, defaults to 2000' + + '\n -r, --require PATH Require the given module path' + + '\n -o, --only TESTS Execute only the comma sperated TESTS (can be set several times)' + + '\n -I, --include PATH Unshift the given path to require.paths' + + '\n -p, --port NUM Port number for test servers, starts at 5555' + + '\n -s, --serial Execute tests serially' + + '\n -b, --boring Suppress ansi-escape colors' + + '\n -v, --version Output version number' + + '\n -h, --help Display help information' + + '\n'; + +// Parse arguments + +var files = [], + args = process.argv.slice(2); + +while (args.length) { + var arg = args.shift(); + switch (arg) { + case '-h': + case '--help': + print(usage + '\n'); + process.exit(1); + break; + case '-v': + case '--version': + sys.puts(version); + process.exit(1); + break; + case '-i': + case '-I': + case '--include': + if (arg = args.shift()) { + require.paths.unshift(arg); + } else { + throw new Error('--include requires a path'); + } + break; + case '-o': + case '--only': + if (arg = args.shift()) { + only = only.concat(arg.split(/ *, */)); + } else { + throw new Error('--only requires comma-separated test names'); + } + break; + case '-p': + case '--port': + if (arg = args.shift()) { + port = parseInt(arg, 10); + } else { + throw new Error('--port requires a number'); + } + break; + case '-r': + case '--require': + if (arg = args.shift()) { + require(arg); + } else { + throw new Error('--require requires a path'); + } + break; + case '-t': + case '--timeout': + if (arg = args.shift()) { + timeout = parseInt(arg, 10); + } else { + throw new Error('--timeout requires an argument'); + } + break; + case '-c': + case '--cov': + case '--coverage': + defer = true; + childProcess.exec('rm -fr lib-cov && node-jscoverage lib lib-cov', function(err){ + if (err) throw err; + require.paths.unshift('lib-cov'); + run(files); + }) + break; + case '-q': + case '--quiet': + quiet = true; + break; + case '-b': + case '--boring': + boring = true; + break; + case '-g': + case '--growl': + growl = true; + break; + case '-s': + case '--serial': + serial = true; + break; + default: + if (/\.js$/.test(arg)) { + files.push(arg); + } + break; + } +} + +/** + * Colorized sys.error(). + * + * @param {String} str + */ + +function print(str){ + sys.error(colorize(str)); +} + +/** + * Colorize the given string using ansi-escape sequences. + * Disabled when --boring is set. + * + * @param {String} str + * @return {String} + */ + +function colorize(str){ + var colors = { bold: 1, red: 31, green: 32, yellow: 33 }; + return str.replace(/\[(\w+)\]\{([^]*?)\}/g, function(_, color, str){ + return boring + ? str + : '\x1B[' + colors[color] + 'm' + str + '\x1B[0m'; + }); +} + +// Alias deepEqual as eql for complex equality + +assert.eql = assert.deepEqual; + +/** + * Assert that `val` is null. + * + * @param {Mixed} val + * @param {String} msg + */ + +assert.isNull = function(val, msg) { + assert.strictEqual(null, val, msg); +}; + +/** + * Assert that `val` is not null. + * + * @param {Mixed} val + * @param {String} msg + */ + +assert.isNotNull = function(val, msg) { + assert.notStrictEqual(null, val, msg); +}; + +/** + * Assert that `val` is undefined. + * + * @param {Mixed} val + * @param {String} msg + */ + +assert.isUndefined = function(val, msg) { + assert.strictEqual(undefined, val, msg); +}; + +/** + * Assert that `val` is not undefined. + * + * @param {Mixed} val + * @param {String} msg + */ + +assert.isDefined = function(val, msg) { + assert.notStrictEqual(undefined, val, msg); +}; + +/** + * Assert that `obj` is `type`. + * + * @param {Mixed} obj + * @param {String} type + * @api public + */ + +assert.type = function(obj, type, msg){ + var real = typeof obj; + msg = msg || 'typeof ' + sys.inspect(obj) + ' is ' + real + ', expected ' + type; + assert.ok(type === real, msg); +}; + +/** + * Assert that `str` matches `regexp`. + * + * @param {String} str + * @param {RegExp} regexp + * @param {String} msg + */ + +assert.match = function(str, regexp, msg) { + msg = msg || sys.inspect(str) + ' does not match ' + sys.inspect(regexp); + assert.ok(regexp.test(str), msg); +}; + +/** + * Assert that `val` is within `obj`. + * + * Examples: + * + * assert.includes('foobar', 'bar'); + * assert.includes(['foo', 'bar'], 'foo'); + * + * @param {String|Array} obj + * @param {Mixed} val + * @param {String} msg + */ + +assert.includes = function(obj, val, msg) { + msg = msg || sys.inspect(obj) + ' does not include ' + sys.inspect(val); + assert.ok(obj.indexOf(val) >= 0, msg); +}; + +/** + * Assert length of `val` is `n`. + * + * @param {Mixed} val + * @param {Number} n + * @param {String} msg + */ + +assert.length = function(val, n, msg) { + msg = msg || sys.inspect(val) + ' has length of ' + val.length + ', expected ' + n; + assert.equal(n, val.length, msg); +}; + +/** + * Assert response from `server` with + * the given `req` object and `res` assertions object. + * + * @param {Server} server + * @param {Object} req + * @param {Object|Function} res + * @param {String} msg + */ + +assert.response = function(server, req, res, msg){ + // Check that the server is ready or defer + if (!server.fd) { + if (!('__deferred' in server)) { + server.__deferred = []; + } + server.__deferred.push(arguments); + if (!server.__started) { + server.listen(server.__port = port++, '127.0.0.1', function(){ + if (server.__deferred) { + process.nextTick(function(){ + server.__deferred.forEach(function(args){ + assert.response.apply(assert, args); + }); + }); + } + }); + server.__started = true; + } + return; + } + + // Callback as third or fourth arg + var callback = typeof res === 'function' + ? res + : typeof msg === 'function' + ? msg + : function(){}; + + // Default messate to test title + if (typeof msg === 'function') msg = null; + msg = msg || assert.testTitle; + msg += '. '; + + // Pending responses + server.__pending = server.__pending || 0; + server.__pending++; + + // Create client + if (!server.fd) { + server.listen(server.__port = port++, '127.0.0.1', issue); + } else { + issue(); + } + + function issue(){ + if (!server.client) + server.client = http.createClient(server.__port); + + // Issue request + var timer, + client = server.client, + method = req.method || 'GET', + status = res.status || res.statusCode, + data = req.data || req.body, + requestTimeout = req.timeout || 0; + + var request = client.request(method, req.url, req.headers); + + // Timeout + if (requestTimeout) { + timer = setTimeout(function(){ + --server.__pending || server.close(); + delete req.timeout; + assert.fail(msg + 'Request timed out after ' + requestTimeout + 'ms.'); + }, requestTimeout); + } + + if (data) request.write(data); + request.addListener('response', function(response){ + response.body = ''; + response.setEncoding('utf8'); + response.addListener('data', function(chunk){ response.body += chunk; }); + response.addListener('end', function(){ + --server.__pending || server.close(); + if (timer) clearTimeout(timer); + + // Assert response body + if (res.body !== undefined) { + var eql = res.body instanceof RegExp + ? res.body.test(response.body) + : res.body === response.body; + assert.ok( + eql, + msg + 'Invalid response body.\n' + + ' Expected: ' + sys.inspect(res.body) + '\n' + + ' Got: ' + sys.inspect(response.body) + ); + } + + // Assert response status + if (typeof status === 'number') { + assert.equal( + response.statusCode, + status, + msg + colorize('Invalid response status code.\n' + + ' Expected: [green]{' + status + '}\n' + + ' Got: [red]{' + response.statusCode + '}') + ); + } + + // Assert response headers + if (res.headers) { + var keys = Object.keys(res.headers); + for (var i = 0, len = keys.length; i < len; ++i) { + var name = keys[i], + actual = response.headers[name.toLowerCase()], + expected = res.headers[name], + eql = expected instanceof RegExp + ? expected.test(actual) + : expected == actual; + assert.ok( + eql, + msg + colorize('Invalid response header [bold]{' + name + '}.\n' + + ' Expected: [green]{' + expected + '}\n' + + ' Got: [red]{' + actual + '}') + ); + } + } + + // Callback + callback(response); + }); + }); + request.end(); + } +}; + +/** + * Pad the given string to the maximum width provided. + * + * @param {String} str + * @param {Number} width + * @return {String} + */ + +function lpad(str, width) { + str = String(str); + var n = width - str.length; + if (n < 1) return str; + while (n--) str = ' ' + str; + return str; +} + +/** + * Pad the given string to the maximum width provided. + * + * @param {String} str + * @param {Number} width + * @return {String} + */ + +function rpad(str, width) { + str = String(str); + var n = width - str.length; + if (n < 1) return str; + while (n--) str = str + ' '; + return str; +} + +/** + * Report test coverage. + * + * @param {Object} cov + */ + +function reportCoverage(cov) { + // Stats + print('\n [bold]{Test Coverage}\n'); + var sep = ' +------------------------------------------+----------+------+------+--------+', + lastSep = ' +----------+------+------+--------+'; + sys.puts(sep); + sys.puts(' | filename | coverage | LOC | SLOC | missed |'); + sys.puts(sep); + for (var name in cov) { + var file = cov[name]; + if (Array.isArray(file)) { + sys.print(' | ' + rpad(name, 40)); + sys.print(' | ' + lpad(file.coverage.toFixed(2), 8)); + sys.print(' | ' + lpad(file.LOC, 4)); + sys.print(' | ' + lpad(file.SLOC, 4)); + sys.print(' | ' + lpad(file.totalMisses, 6)); + sys.print(' |\n'); + } + } + sys.puts(sep); + sys.print(' ' + rpad('', 40)); + sys.print(' | ' + lpad(cov.coverage.toFixed(2), 8)); + sys.print(' | ' + lpad(cov.LOC, 4)); + sys.print(' | ' + lpad(cov.SLOC, 4)); + sys.print(' | ' + lpad(cov.totalMisses, 6)); + sys.print(' |\n'); + sys.puts(lastSep); + // Source + for (var name in cov) { + if (name.match(/\.js$/)) { + var file = cov[name]; + if ((file.coverage < 100) || !quiet) { + print('\n [bold]{' + name + '}:'); + print(file.source); + sys.print('\n'); + } + } + } +} + +/** + * Populate code coverage data. + * + * @param {Object} cov + */ + +function populateCoverage(cov) { + cov.LOC = + cov.SLOC = + cov.totalFiles = + cov.totalHits = + cov.totalMisses = + cov.coverage = 0; + for (var name in cov) { + var file = cov[name]; + if (Array.isArray(file)) { + // Stats + ++cov.totalFiles; + cov.totalHits += file.totalHits = coverage(file, true); + cov.totalMisses += file.totalMisses = coverage(file, false); + file.totalLines = file.totalHits + file.totalMisses; + cov.SLOC += file.SLOC = file.totalLines; + if (!file.source) file.source = []; + cov.LOC += file.LOC = file.source.length; + file.coverage = (file.totalHits / file.totalLines) * 100; + // Source + var width = file.source.length.toString().length; + file.source = file.source.map(function(line, i){ + ++i; + var hits = file[i] === 0 ? 0 : (file[i] || ' '); + if (!boring) { + if (hits === 0) { + hits = '\x1b[31m' + hits + '\x1b[0m'; + line = '\x1b[41m' + line + '\x1b[0m'; + } else { + hits = '\x1b[32m' + hits + '\x1b[0m'; + } + } + return '\n ' + lpad(i, width) + ' | ' + hits + ' | ' + line; + }).join(''); + } + } + cov.coverage = (cov.totalHits / cov.SLOC) * 100; +} + +/** + * Total coverage for the given file data. + * + * @param {Array} data + * @return {Type} + */ + +function coverage(data, val) { + var n = 0; + for (var i = 0, len = data.length; i < len; ++i) { + if (data[i] !== undefined && data[i] == val) ++n; + } + return n; +} + +/** + * Test if all files have 100% coverage + * + * @param {Object} cov + * @return {Boolean} + */ + +function hasFullCoverage(cov) { + for (var name in cov) { + var file = cov[name]; + if (file instanceof Array) { + if (file.coverage !== 100) { + return false; + } + } + } + return true; +} + +/** + * Run the given test `files`, or try _test/*_. + * + * @param {Array} files + */ + +function run(files) { + cursor(false); + if (!files.length) { + try { + files = fs.readdirSync('test').map(function(file){ + return 'test/' + file; + }); + } catch (err) { + print('\n failed to load tests in [bold]{./test}\n'); + ++failures; + process.exit(1); + } + } + runFiles(files); +} + +/** + * Show the cursor when `show` is true, otherwise hide it. + * + * @param {Boolean} show + */ + +function cursor(show) { + if (show) { + sys.print('\x1b[?25h'); + } else { + sys.print('\x1b[?25l'); + } +} + +/** + * Run the given test `files`. + * + * @param {Array} files + */ + +function runFiles(files) { + if (serial) { + (function next(){ + if (files.length) { + runFile(files.shift(), next); + } + })(); + } else { + files.forEach(runFile); + } +} + +/** + * Run tests for the given `file`, callback `fn()` when finished. + * + * @param {String} file + * @param {Function} fn + */ + +function runFile(file, fn) { + if (file.match(/\.js$/)) { + var title = path.basename(file), + file = path.join(cwd, file), + mod = require(file.replace(/\.js$/, '')); + (function check(){ + var len = Object.keys(mod).length; + if (len) { + runSuite(title, mod, fn); + } else { + setTimeout(check, 20); + } + })(); + } +} + +/** + * Report `err` for the given `test` and `suite`. + * + * @param {String} suite + * @param {String} test + * @param {Error} err + */ + +function error(suite, test, err) { + ++failures; + var name = err.name, + stack = err.stack.replace(err.name, ''), + label = test === 'uncaught' + ? test + : suite + ' ' + test; + print('\n [bold]{' + label + '}: [red]{' + name + '}' + stack + '\n'); +} + +/** + * Run the given tests, callback `fn()` when finished. + * + * @param {String} title + * @param {Object} tests + * @param {Function} fn + */ + +var dots = 0; +function runSuite(title, tests, fn) { + // Keys + var keys = only.length + ? only.slice(0) + : Object.keys(tests); + + // Setup + var setup = tests.setup || function(fn){ fn(); }; + + // Iterate tests + (function next(){ + if (keys.length) { + var key, + test = tests[key = keys.shift()]; + // Non-tests + if (key === 'setup') return next(); + + // Run test + if (test) { + try { + ++testcount; + assert.testTitle = key; + if (serial) { + sys.print('.'); + if (++dots % 25 === 0) sys.print('\n'); + setup(function(){ + if (test.length < 1) { + test(); + next(); + } else { + var id = setTimeout(function(){ + throw new Error("'" + key + "' timed out"); + }, timeout); + test(function(){ + clearTimeout(id); + next(); + }); + } + }); + } else { + test(function(fn){ + addBeforeExit(function(){ + try { + fn(); + } catch (err) { + error(title, key, err); + } + }); + }); + } + } catch (err) { + error(title, key, err); + } + } + if (!serial) next(); + } else if (serial) { + fn(); + } + })(); +} + +/** + * Adds before exit handlers with only one event handler + * + * @param {Function} callback + * @api private + */ + +var beforeExitHandlers = []; + +function addBeforeExit (fn) { + if (!beforeExitHandlers.length) + process.on('beforeExit', function () { + for (var i = 0, l = beforeExitHandlers.length; i < l; i++) + beforeExitHandlers[i](); + }); + beforeExitHandlers.push(fn); +}; + +/** + * Report exceptions. + */ + +function report() { + cursor(true); + process.emit('beforeExit'); + if (failures) { + print('\n [bold]{Failures}: [red]{' + failures + '}\n\n'); + notify('Failures: ' + failures); + } else { + if (serial) print(''); + print('\n [green]{100%} ' + testcount + ' tests\n'); + notify('100% ok'); + } + if (typeof _$jscoverage === 'object') { + populateCoverage(_$jscoverage); + if (!hasFullCoverage(_$jscoverage) || !quiet) { + reportCoverage(_$jscoverage); + } + } +} + +/** + * Growl notify the given `msg`. + * + * @param {String} msg + */ + +function notify(msg) { + if (growl) { + childProcess.exec('growlnotify -name Expresso -m "' + msg + '"'); + } +} + +// Report uncaught exceptions + +process.addListener('uncaughtException', function(err){ + error('uncaught', 'uncaught', err); +}); + +// Show cursor + +['INT', 'TERM', 'QUIT'].forEach(function(sig){ + process.addListener('SIG' + sig, function(){ + cursor(true); + process.exit(1); + }); +}); + +// Report test coverage when available +// and emit "beforeExit" event to perform +// final assertions + +var orig = process.emit; +process.emit = function(event){ + if (event === 'exit') { + report(); + process.reallyExit(failures); + } + orig.apply(this, arguments); +}; + +// Run test files + +if (!defer) run(files); diff --git a/node_modules/mongoose/support/expresso/docs/api.html b/node_modules/mongoose/support/expresso/docs/api.html new file mode 100644 index 0000000..7b8fb2b --- /dev/null +++ b/node_modules/mongoose/support/expresso/docs/api.html @@ -0,0 +1,1080 @@ +Fork me on GitHub + + Expresso + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Expresso

Insanely fast TDD framework for node featuring code coverage reporting.

expresso

bin/expresso
+

!/usr/bin/env node

+
+

+ * Expresso
+ * Copyright(c) TJ Holowaychuk &lt;tj@vision-media.ca&gt;
+ * (MIT Licensed)
+ 
+
+

Module dependencies. +

+
+
var assert = require('assert'),
+    childProcess = require('child_process'),
+    http = require('http'),
+    path = require('path'),
+    sys = require('sys'),
+    cwd = process.cwd(),
+    fs = require('fs'),
+    defer;
+
+

Expresso version. +

+
+
var version = '0.6.4';
+
+

Failure count. +

+
+
var failures = 0;
+
+

Number of tests executed. +

+
+
var testcount = 0;
+
+

Whitelist of tests to run. +

+
+
var only = [];
+
+

Boring output. +

+
+
var boring = false;
+
+

Growl notifications. +

+
+
var growl = false;
+
+

Server port. +

+
+
var port = 5555;
+
+

Watch mode. +

+
+
var watch = false;
+
+

Execute serially. +

+
+
var serial = false;
+
+

Default timeout. +

+
+
var timeout = 2000;
+
+

Usage documentation. +

+
+
var usage = ''
+    + '[bold]{Usage}: expresso [options] <file ...>'
+    + '\n'
+    + '\n[bold]{Options}:'
+    + '\n  -w, --watch          Watch for modifications and re-execute tests'
+    + '\n  -g, --growl          Enable growl notifications'
+    + '\n  -c, --coverage       Generate and report test coverage'
+    + '\n  -t, --timeout MS     Timeout in milliseconds, defaults to 2000'
+    + '\n  -r, --require PATH   Require the given module path'
+    + '\n  -o, --only TESTS     Execute only the comma sperated TESTS (can be set several times)'
+    + '\n  -I, --include PATH   Unshift the given path to require.paths'
+    + '\n  -p, --port NUM       Port number for test servers, starts at 5555'
+    + '\n  -s, --serial         Execute tests serially'
+    + '\n  -b, --boring         Suppress ansi-escape colors'
+    + '\n  -v, --version        Output version number'
+    + '\n  -h, --help           Display help information'
+    + '\n';
+
+// Parse arguments
+
+var files = [],
+    args = process.argv.slice(2);
+
+while (args.length) {
+    var arg = args.shift();
+    switch (arg) {
+        case '-h':
+        case '--help':
+            print(usage + '\n');
+            process.exit(1);
+            break;
+        case '-v':
+        case '--version':
+            sys.puts(version);
+            process.exit(1);
+            break;
+        case '-i':
+        case '-I':
+        case '--include':
+            if (arg = args.shift()) {
+                require.paths.unshift(arg);
+            } else {
+                throw new Error('--include requires a path');
+            }
+            break;
+        case '-o':
+        case '--only':
+            if (arg = args.shift()) {
+                only = only.concat(arg.split(/ *, */));
+            } else {
+                throw new Error('--only requires comma-separated test names');
+            }
+            break;
+        case '-p':
+        case '--port':
+            if (arg = args.shift()) {
+                port = parseInt(arg, 10);
+            } else {
+                throw new Error('--port requires a number');
+            }
+            break;
+        case '-r':
+        case '--require':
+            if (arg = args.shift()) {
+                require(arg);
+            } else {
+                throw new Error('--require requires a path');
+            }
+            break;
+        case '-t':
+        case '--timeout':
+          if (arg = args.shift()) {
+            timeout = parseInt(arg, 10);
+          } else {
+            throw new Error('--timeout requires an argument');
+          }
+          break;
+        case '-c':
+        case '--cov':
+        case '--coverage':
+            defer = true;
+            childProcess.exec('rm -fr lib-cov && node-jscoverage lib lib-cov', function(err){
+                if (err) throw err;
+                require.paths.unshift('lib-cov');
+                run(files);
+            })
+            break;
+        case '-b':
+        case '--boring':
+        	boring = true;
+        	break;
+        case '-w':
+        case '--watch':
+            watch = true;
+            break;
+        case '-g':
+        case '--growl':
+            growl = true;
+            break;
+        case '-s':
+        case '--serial':
+            serial = true;
+            break;
+        default:
+            if (/\.js$/.test(arg)) {
+                files.push(arg);
+            }
+            break;
+    }
+}
+
+

Colorized sys.error().

+ +

+ +
  • param: String str

+
+
function print(str){
+    sys.error(colorize(str));
+}
+
+

Colorize the given string using ansi-escape sequences. +Disabled when --boring is set.

+ +

+ +
  • param: String str

  • return: String

+
+
function colorize(str){
+    var colors = { bold: 1, red: 31, green: 32, yellow: 33 };
+    return str.replace(/\[(\w+)\]\{([^]*?)\}/g, function(_, color, str){
+        return boring
+            ? str
+            : '\x1B[' + colors[color] + 'm' + str + '\x1B[0m';
+    });
+}
+
+// Alias deepEqual as eql for complex equality
+
+assert.eql = assert.deepEqual;
+
+

Assert that val is null.

+ +

+ +
  • param: Mixed val

  • param: String msg

+
+
assert.isNull = function(val, msg) {
+    assert.strictEqual(null, val, msg);
+};
+
+

Assert that val is not null.

+ +

+ +
  • param: Mixed val

  • param: String msg

+
+
assert.isNotNull = function(val, msg) {
+    assert.notStrictEqual(null, val, msg);
+};
+
+

Assert that val is undefined.

+ +

+ +
  • param: Mixed val

  • param: String msg

+
+
assert.isUndefined = function(val, msg) {
+    assert.strictEqual(undefined, val, msg);
+};
+
+

Assert that val is not undefined.

+ +

+ +
  • param: Mixed val

  • param: String msg

+
+
assert.isDefined = function(val, msg) {
+    assert.notStrictEqual(undefined, val, msg);
+};
+
+

Assert that obj is type.

+ +

+ +
  • param: Mixed obj

  • param: String type

  • api: public

+
+
assert.type = function(obj, type, msg){
+    var real = typeof obj;
+    msg = msg || 'typeof ' + sys.inspect(obj) + ' is ' + real + ', expected ' + type;
+    assert.ok(type === real, msg);
+};
+
+

Assert that str matches regexp.

+ +

+ +
  • param: String str

  • param: RegExp regexp

  • param: String msg

+
+
assert.match = function(str, regexp, msg) {
+    msg = msg || sys.inspect(str) + ' does not match ' + sys.inspect(regexp);
+    assert.ok(regexp.test(str), msg);
+};
+
+

Assert that val is within obj.

+ +

Examples

+ +

assert.includes('foobar', 'bar'); + assert.includes(['foo', 'bar'], 'foo');

+ +

+ +
  • param: String | Array obj

  • param: Mixed val

  • param: String msg

+
+
assert.includes = function(obj, val, msg) {
+    msg = msg || sys.inspect(obj) + ' does not include ' + sys.inspect(val);
+    assert.ok(obj.indexOf(val) &gt;= 0, msg);
+};
+
+

Assert length of val is n.

+ +

+ +
  • param: Mixed val

  • param: Number n

  • param: String msg

+
+
assert.length = function(val, n, msg) {
+    msg = msg || sys.inspect(val) + ' has length of ' + val.length + ', expected ' + n;
+    assert.equal(n, val.length, msg);
+};
+
+

Assert response from server with +the given req object and res assertions object.

+ +

+ +
  • param: Server server

  • param: Object req

  • param: Object | Function res

  • param: String msg

+
+
assert.response = function(server, req, res, msg){
+    // Callback as third or fourth arg
+    var callback = typeof res === 'function'
+        ? res
+        : typeof msg === 'function'
+            ? msg
+            : function(){};
+
+    // Default messate to test title
+    if (typeof msg === 'function') msg = null;
+    msg = msg || assert.testTitle;
+    msg += '. ';
+
+    // Pending responses
+    server.__pending = server.__pending || 0;
+    server.__pending++;
+
+    // Create client
+    if (!server.fd) {
+        server.listen(server.__port = port++, '127.0.0.1');
+        server.client = http.createClient(server.__port);
+    }
+
+    // Issue request
+    var timer,
+        client = server.client,
+        method = req.method || 'GET',
+        status = res.status || res.statusCode,
+        data = req.data || req.body,
+        requestTimeout = req.timeout || 0;
+
+    var request = client.request(method, req.url, req.headers);
+
+    // Timeout
+    if (requestTimeout) {
+        timer = setTimeout(function(){
+            --server.__pending || server.close();
+            delete req.timeout;
+            assert.fail(msg + 'Request timed out after ' + requestTimeout + 'ms.');
+        }, requestTimeout);
+    }
+
+    if (data) request.write(data);
+    request.addListener('response', function(response){
+        response.body = '';
+        response.setEncoding('utf8');
+        response.addListener('data', function(chunk){ response.body += chunk; });
+        response.addListener('end', function(){
+            --server.__pending || server.close();
+            if (timer) clearTimeout(timer);
+
+            // Assert response body
+            if (res.body !== undefined) {
+                var eql = res.body instanceof RegExp
+                  ? res.body.test(response.body)
+                  : res.body === response.body;
+                assert.ok(
+                    eql,
+                    msg + 'Invalid response body.\n'
+                        + '    Expected: ' + sys.inspect(res.body) + '\n'
+                        + '    Got: ' + sys.inspect(response.body)
+                );
+            }
+
+            // Assert response status
+            if (typeof status === 'number') {
+                assert.equal(
+                    response.statusCode,
+                    status,
+                    msg + colorize('Invalid response status code.\n'
+                        + '    Expected: [green]{' + status + '}\n'
+                        + '    Got: [red]{' + response.statusCode + '}')
+                );
+            }
+
+            // Assert response headers
+            if (res.headers) {
+                var keys = Object.keys(res.headers);
+                for (var i = 0, len = keys.length; i &lt; len; ++i) {
+                    var name = keys[i],
+                        actual = response.headers[name.toLowerCase()],
+                        expected = res.headers[name],
+                        eql = expected instanceof RegExp
+                          ? expected.test(actual)
+                          : expected == actual;
+                    assert.ok(
+                        eql,
+                        msg + colorize('Invalid response header [bold]{' + name + '}.\n'
+                            + '    Expected: [green]{' + expected + '}\n'
+                            + '    Got: [red]{' + actual + '}')
+                    );
+                }
+            }
+
+            // Callback
+            callback(response);
+        });
+    });
+    request.end();
+};
+
+

Pad the given string to the maximum width provided.

+ +

+ +
  • param: String str

  • param: Number width

  • return: String

+
+
function lpad(str, width) {
+    str = String(str);
+    var n = width - str.length;
+    if (n &lt; 1) return str;
+    while (n--) str = ' ' + str;
+    return str;
+}
+
+

Pad the given string to the maximum width provided.

+ +

+ +
  • param: String str

  • param: Number width

  • return: String

+
+
function rpad(str, width) {
+    str = String(str);
+    var n = width - str.length;
+    if (n &lt; 1) return str;
+    while (n--) str = str + ' ';
+    return str;
+}
+
+

Report test coverage.

+ +

+ +
  • param: Object cov

+
+
function reportCoverage(cov) {
+    populateCoverage(cov);
+    // Stats
+    print('\n   [bold]{Test Coverage}\n');
+    var sep = '   +------------------------------------------+----------+------+------+--------+',
+        lastSep = '                                              +----------+------+------+--------+';
+    sys.puts(sep);
+    sys.puts('   | filename                                 | coverage | LOC  | SLOC | missed |');
+    sys.puts(sep);
+    for (var name in cov) {
+        var file = cov[name];
+        if (Array.isArray(file)) {
+            sys.print('   | ' + rpad(name, 40));
+            sys.print(' | ' + lpad(file.coverage.toFixed(2), 8));
+            sys.print(' | ' + lpad(file.LOC, 4));
+            sys.print(' | ' + lpad(file.SLOC, 4));
+            sys.print(' | ' + lpad(file.totalMisses, 6));
+            sys.print(' |\n');
+        }
+    }
+    sys.puts(sep);
+    sys.print('     ' + rpad('', 40));
+    sys.print(' | ' + lpad(cov.coverage.toFixed(2), 8));
+    sys.print(' | ' + lpad(cov.LOC, 4));
+    sys.print(' | ' + lpad(cov.SLOC, 4));
+    sys.print(' | ' + lpad(cov.totalMisses, 6));
+    sys.print(' |\n');
+    sys.puts(lastSep);
+    // Source
+    for (var name in cov) {
+        if (name.match(/\.js$/)) {
+            var file = cov[name];
+            print('\n   [bold]{' + name + '}:');
+            print(file.source);
+            sys.print('\n');
+        }
+    }
+}
+
+

Populate code coverage data.

+ +

+ +
  • param: Object cov

+
+
function populateCoverage(cov) {
+    cov.LOC = 
+    cov.SLOC =
+    cov.totalFiles =
+    cov.totalHits =
+    cov.totalMisses = 
+    cov.coverage = 0;
+    for (var name in cov) {
+        var file = cov[name];
+        if (Array.isArray(file)) {
+            // Stats
+            ++cov.totalFiles;
+            cov.totalHits += file.totalHits = coverage(file, true);
+            cov.totalMisses += file.totalMisses = coverage(file, false);
+            file.totalLines = file.totalHits + file.totalMisses;
+            cov.SLOC += file.SLOC = file.totalLines;
+            if (!file.source) file.source = [];
+            cov.LOC += file.LOC = file.source.length;
+            file.coverage = (file.totalHits / file.totalLines) * 100;
+            // Source
+            var width = file.source.length.toString().length;
+            file.source = file.source.map(function(line, i){
+                ++i;
+                var hits = file[i] === 0 ? 0 : (file[i] || ' ');
+                if (!boring) {
+                    if (hits === 0) {
+                        hits = '\x1b[31m' + hits + '\x1b[0m';
+                        line = '\x1b[41m' + line + '\x1b[0m';
+                    } else {
+                        hits = '\x1b[32m' + hits + '\x1b[0m';
+                    }
+                }
+                return '\n     ' + lpad(i, width) + ' | ' + hits + ' | ' + line;
+            }).join('');
+        }
+    }
+    cov.coverage = (cov.totalHits / cov.SLOC) * 100;
+}
+
+

Total coverage for the given file data.

+ +

+ +
  • param: Array data

  • return: Type

+
+
function coverage(data, val) {
+    var n = 0;
+    for (var i = 0, len = data.length; i &lt; len; ++i) {
+        if (data[i] !== undefined &amp;&amp; data[i] == val) ++n;
+    }
+    return n;  
+}
+
+

Run the given test files, or try test/*.

+ +

+ +
  • param: Array files

+
+
function run(files) {
+    if (!files.length) {
+        try {
+            files = fs.readdirSync('test').map(function(file){
+                return 'test/' + file;
+            });
+        } catch (err) {
+            print('\n  failed to load tests in [bold]{./test}\n');
+            ++failures;
+            process.exit(1);
+        }
+    }
+    if (watch) watchFiles(files);
+    runFiles(files);
+}
+
+

Show the cursor when show is true, otherwise hide it.

+ +

+ +
  • param: Boolean show

+
+
function cursor(show) {
+    if (show) {
+        sys.print('\x1b[?25h');
+    } else {
+        sys.print('\x1b[?25l');
+    }
+}
+
+

Run the given test files.

+ +

+ +
  • param: Array files

+
+
function runFiles(files) {
+    if (serial) {
+        (function next(){
+            if (files.length) {
+                runFile(files.shift(), next);
+            }
+        })();
+    } else {
+      files.forEach(runFile);
+    }
+}
+
+

Run tests for the given file, callback fn() when finished.

+ +

+ +
  • param: String file

  • param: Function fn

+
+
function runFile(file, fn) {
+    if (file.match(/\.js$/)) {
+        var title = path.basename(file),
+            file = path.join(cwd, file),
+            mod = require(file.replace(/\.js$/, ''));
+        (function check(){
+           var len = Object.keys(mod).length;
+           if (len) {
+               runSuite(title, mod, fn);
+           } else {
+               setTimeout(check, 20);
+           }
+        })();
+    }
+}
+
+

Clear the module cache for the given file.

+ +

+ +
  • param: String file

+
+
function clearCache(file) {
+    var keys = Object.keys(module.moduleCache);
+    for (var i = 0, len = keys.length; i &lt; len; ++i) {
+        var key = keys[i];
+        if (key.indexOf(file) === key.length - file.length) {
+            delete module.moduleCache[key];
+        }
+    }
+}
+
+

Watch the given files for changes.

+ +

+ +
  • param: Array files

+
+
function watchFiles(files) {
+    var p = 0,
+        c = ['▫   ', '▫▫  ', '▫▫▫ ', ' ▫▫▫',
+             '  ▫▫', '   ▫', '   ▫', '  ▫▫',
+             '▫▫▫ ', '▫▫  ', '▫   '],
+        l = c.length;
+    cursor(false);
+    setInterval(function(){
+        sys.print(colorize('  [green]{' + c[p++ % l] + '} watching\r'));
+    }, 100);
+    files.forEach(function(file){
+        fs.watchFile(file, { interval: 100 }, function(curr, prev){
+            if (curr.mtime &gt; prev.mtime) {
+                print('  [yellow]{◦} ' + file);
+                clearCache(file);
+                runFile(file);
+            }
+        });
+    });
+}
+
+

Report err for the given test and suite.

+ +

+ +
  • param: String suite

  • param: String test

  • param: Error err

+
+
function error(suite, test, err) {
+    ++failures;
+    var name = err.name,
+        stack = err.stack.replace(err.name, ''),
+        label = test === 'uncaught'
+            ? test
+            : suite + ' ' + test;
+    print('\n   [bold]{' + label + '}: [red]{' + name + '}' + stack + '\n');
+    if (watch) notify(label + ' failed');
+}
+
+

Run the given tests, callback fn() when finished.

+ +

+ +
  • param: String title

  • param: Object tests

  • param: Function fn

+
+
var dots = 0;
+function runSuite(title, tests, fn) {
+    // Keys
+    var keys = only.length
+        ? only.slice(0)
+        : Object.keys(tests);
+
+    // Setup
+    var setup = tests.setup || function(fn){ fn(); };
+
+    // Iterate tests
+    (function next(){
+        if (keys.length) {
+            var key,
+                test = tests[key = keys.shift()];
+            // Non-tests
+            if (key === 'setup') return next();
+
+            // Run test
+            if (test) {
+                try {
+                    ++testcount;
+                    assert.testTitle = key;
+                    if (serial) {
+                        if (!watch) {
+                            sys.print('.');
+                            if (++dots % 25 === 0) sys.print('\n');
+                        }
+                        setup(function(){
+                            if (test.length &lt; 1) {
+                                test();
+                                next();
+                            } else {
+                                var id = setTimeout(function(){
+                                    throw new Error(&quot;'" + key + "' timed out&quot;);
+                                }, timeout);
+                                test(function(){
+                                    clearTimeout(id);
+                                    next();
+                                });
+                            } 
+                        });
+                    } else {
+                        test(function(fn){
+                            process.addListener('beforeExit', function(){
+                                try {
+                                    fn();
+                                } catch (err) {
+                                    error(title, key, err);
+                                }
+                            });
+                        });
+                    }
+                } catch (err) {
+                    error(title, key, err);
+                }
+            }
+            if (!serial) next();
+        } else if (serial) {
+          fn();
+        }
+    })();
+}
+
+

Report exceptions. +

+
+
function report() {
+    process.emit('beforeExit');
+    if (failures) {
+        print('\n   [bold]{Failures}: [red]{' + failures + '}\n\n');
+        notify('Failures: ' + failures);
+    } else {
+        if (serial) print('');
+        print('\n   [green]{100%} ' + testcount + ' tests\n');
+        notify('100% ok');
+    }
+    if (typeof _$jscoverage === 'object') {
+        reportCoverage(_$jscoverage);
+    }
+}
+
+

Growl notify the given msg.

+ +

+ +
  • param: String msg

+
+
function notify(msg) {
+    if (growl) {
+        childProcess.exec('growlnotify -name Expresso -m "' + msg + '"');
+    }
+}
+
+// Report uncaught exceptions
+
+process.addListener('uncaughtException', function(err){
+    error('uncaught', 'uncaught', err);
+});
+
+// Show cursor
+
+['INT', 'TERM', 'QUIT'].forEach(function(sig){
+    process.addListener('SIG' + sig, function(){
+        cursor(true);
+        process.exit(1);
+    });
+});
+
+// Report test coverage when available
+// and emit "beforeExit" event to perform
+// final assertions
+
+var orig = process.emit;
+process.emit = function(event){
+    if (event === 'exit') {
+        report();
+        process.reallyExit(failures);
+    }
+    orig.apply(this, arguments);
+};
+
+// Run test files
+
+if (!defer) run(files);
+
+
\ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/docs/index.html b/node_modules/mongoose/support/expresso/docs/index.html new file mode 100644 index 0000000..064313f --- /dev/null +++ b/node_modules/mongoose/support/expresso/docs/index.html @@ -0,0 +1,377 @@ + + + Expresso - TDD Framework For Node + + + + + Fork me on GitHub + +
+

Expresso

+
+

NAME

+

+ index +

+

Expresso is a JavaScript TDD framework written for nodejs. Expresso is extremely fast, and is packed with features such as additional assertion methods, code coverage reporting, CI support, and more.

+ +

Features

+ +
    +
  • light-weight
  • +
  • intuitive async support
  • +
  • intuitive test runner executable
  • +
  • test coverage support and reporting via node-jscoverage
  • +
  • uses and extends the core assert module
  • +
  • assert.eql() alias of assert.deepEqual()
  • +
  • assert.response() http response utility
  • +
  • assert.includes()
  • +
  • assert.isNull()
  • +
  • assert.isUndefined()
  • +
  • assert.isNotNull()
  • +
  • assert.isDefined()
  • +
  • assert.match()
  • +
  • assert.length()
  • +
+ + +

Installation

+ +

To install both expresso and node-jscoverage run +the command below, which will first compile node-jscoverage:

+ +
$ make install
+
+ +

To install expresso alone without coverage reporting run:

+ +
$ make install-expresso
+
+ +

Install via npm:

+ +
$ npm install expresso
+
+ +

Examples

+ +

To define tests we simply export several functions:

+ +
exports['test String#length'] = function(){
+    assert.equal(6, 'foobar'.length);
+};
+
+ +

Alternatively for large numbers of tests you may want to +export your own object containing the tests, however this +is essentially the as above:

+ +
module.exports = {
+    'test String#length': function(){
+        assert.equal(6, 'foobar'.length);
+    }
+};
+
+ +

If you prefer not to use quoted keys:

+ +
exports.testsStringLength = function(){
+    assert.equal(6, 'foobar'.length);
+};
+
+ +

The argument passed to each callback is beforeExit, +which is typically used to assert that callbacks have been +invoked.

+ +
exports.testAsync = function(beforeExit){
+    var n = 0;
+    setTimeout(function(){
+        ++n;
+        assert.ok(true);
+    }, 200);
+    setTimeout(function(){
+        ++n;
+        assert.ok(true);
+    }, 200);
+    beforeExit(function(){
+        assert.equal(2, n, 'Ensure both timeouts are called');
+    });
+};
+
+ +

Assert Utilities

+ +

assert.isNull(val[, msg])

+ +

Asserts that the given val is null.

+ +
assert.isNull(null);
+
+ +

assert.isNotNull(val[, msg])

+ +

Asserts that the given val is not null.

+ +
assert.isNotNull(undefined);
+assert.isNotNull(false);
+
+ +

assert.isUndefined(val[, msg])

+ +

Asserts that the given val is undefined.

+ +
assert.isUndefined(undefined);
+
+ +

assert.isDefined(val[, msg])

+ +

Asserts that the given val is not undefined.

+ +
assert.isDefined(null);
+assert.isDefined(false);
+
+ +

assert.match(str, regexp[, msg])

+ +

Asserts that the given str matches regexp.

+ +
assert.match('foobar', /^foo(bar)?/);
+assert.match('foo', /^foo(bar)?/);
+
+ +

assert.length(val, n[, msg])

+ +

Assert that the given val has a length of n.

+ +
assert.length([1,2,3], 3);
+assert.length('foo', 3);
+
+ +

assert.type(obj, type[, msg])

+ +

Assert that the given obj is typeof type.

+ +
assert.type(3, 'number');
+
+ +

assert.eql(a, b[, msg])

+ +

Assert that object b is equal to object a. This is an +alias for the core assert.deepEqual() method which does complex +comparisons, opposed to assert.equal() which uses ==.

+ +
assert.eql('foo', 'foo');
+assert.eql([1,2], [1,2]);
+assert.eql({ foo: 'bar' }, { foo: 'bar' });
+
+ +

assert.includes(obj, val[, msg])

+ +

Assert that obj is within val. This method supports Array_s +and Strings_s.

+ +
assert.includes([1,2,3], 3);
+assert.includes('foobar', 'foo');
+assert.includes('foobar', 'bar');
+
+ +

assert.response(server, req, res|fn[, msg|fn])

+ +

Performs assertions on the given server, which should not call +listen(), as this is handled internally by expresso and the server +is killed after all responses have completed. This method works with +any http.Server instance, so Connect and Express servers will work +as well.

+ +

The req object may contain:

+ +
    +
  • url request url
  • +
  • timeout timeout in milliseconds
  • +
  • method HTTP method
  • +
  • data request body
  • +
  • headers headers object
  • +
+ + +

The res object may be a callback function which +receives the response for assertions, or an object +which is then used to perform several assertions +on the response with the following properties:

+ +
    +
  • body assert response body (regexp or string)
  • +
  • status assert response status code
  • +
  • header assert that all given headers match (unspecified are ignored, use a regexp or string)
  • +
+ + +

When providing res you may then also pass a callback function +as the fourth argument for additional assertions.

+ +

Below are some examples:

+ +
assert.response(server, {
+    url: '/', timeout: 500
+}, {
+    body: 'foobar'
+});
+
+assert.response(server, {
+    url: '/',
+    method: 'GET'
+},{
+    body: '{"name":"tj"}',
+    status: 200,
+    headers: {
+        'Content-Type': 'application/json; charset=utf8',
+        'X-Foo': 'bar'
+    }
+});
+
+assert.response(server, {
+    url: '/foo',
+    method: 'POST',
+    data: 'bar baz'
+},{
+    body: '/foo bar baz',
+    status: 200
+}, 'Test POST');
+
+assert.response(server, {
+    url: '/foo',
+    method: 'POST',
+    data: 'bar baz'
+},{
+    body: '/foo bar baz',
+    status: 200
+}, function(res){
+    // All done, do some more tests if needed
+});
+
+assert.response(server, {
+    url: '/'
+}, function(res){
+    assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback');
+});
+
+ +

expresso(1)

+ +

To run a single test suite (file) run:

+ +
$ expresso test/a.test.js
+
+ +

To run several suites we may simply append another:

+ +
$ expresso test/a.test.js test/b.test.js
+
+ +

We can also pass a whitelist of tests to run within all suites:

+ +
$ expresso --only "foo()" --only "bar()"
+
+ +

Or several with one call:

+ +
$ expresso --only "foo(), bar()"
+
+ +

Globbing is of course possible as well:

+ +
$ expresso test/*
+
+ +

When expresso is called without any files, test/* is the default, +so the following is equivalent to the command above:

+ +
$ expresso
+
+ +

If you wish to unshift a path to require.paths before +running tests, you may use the -I or --include flag.

+ +
$ expresso --include lib test/*
+
+ +

The previous example is typically what I would recommend, since expresso +supports test coverage via node-jscoverage (bundled with expresso), +so you will need to expose an instrumented version of you library.

+ +

To instrument your library, simply run node-jscoverage, +passing the src and dest directories:

+ +
$ node-jscoverage lib lib-cov
+
+ +

Now we can run our tests again, using the lib-cov directory that has been +instrumented with coverage statements:

+ +
$ expresso -I lib-cov test/*
+
+ +

The output will look similar to below, depending on your test coverage of course :)

+ +

node coverage

+ +

To make this process easier expresso has the -c or --cov which essentially +does the same as the two commands above. The following two commands will +run the same tests, however one will auto-instrument, and unshift lib-cov, +and the other will run tests normally:

+ +
$ expresso -I lib test/*
+$ expresso -I lib --cov test/*
+
+ +

Currently coverage is bound to the lib directory, however in the +future --cov will most likely accept a path.

+ +

Async Exports

+ +

Sometimes it is useful to postpone running of tests until a callback or event has fired, currently the exports.foo = function(){}; syntax is supported for this:

+ +
setTimeout(function(){
+    exports['test async exports'] = function(){
+        assert.ok('wahoo');
+    };
+}, 100);
+
+ +
+
+ + \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/docs/index.md b/node_modules/mongoose/support/expresso/docs/index.md new file mode 100644 index 0000000..489f931 --- /dev/null +++ b/node_modules/mongoose/support/expresso/docs/index.md @@ -0,0 +1,290 @@ + +[Expresso](http://github.com/visionmedia/expresso) is a JavaScript [TDD](http://en.wikipedia.org/wiki/Test-driven_development) framework written for [nodejs](http://nodejs.org). Expresso is extremely fast, and is packed with features such as additional assertion methods, code coverage reporting, CI support, and more. + +## Features + + - light-weight + - intuitive async support + - intuitive test runner executable + - test coverage support and reporting via [node-jscoverage](http://github.com/visionmedia/node-jscoverage) + - uses and extends the core _assert_ module + - `assert.eql()` alias of `assert.deepEqual()` + - `assert.response()` http response utility + - `assert.includes()` + - `assert.isNull()` + - `assert.isUndefined()` + - `assert.isNotNull()` + - `assert.isDefined()` + - `assert.match()` + - `assert.length()` + +## Installation + +To install both expresso _and_ node-jscoverage run +the command below, which will first compile node-jscoverage: + + $ make install + +To install expresso alone without coverage reporting run: + + $ make install-expresso + +Install via npm: + + $ npm install expresso + +## Examples + +To define tests we simply export several functions: + + exports['test String#length'] = function(){ + assert.equal(6, 'foobar'.length); + }; + +Alternatively for large numbers of tests you may want to +export your own object containing the tests, however this +is essentially the as above: + + module.exports = { + 'test String#length': function(){ + assert.equal(6, 'foobar'.length); + } + }; + +If you prefer not to use quoted keys: + + exports.testsStringLength = function(){ + assert.equal(6, 'foobar'.length); + }; + +The argument passed to each callback is _beforeExit_, +which is typically used to assert that callbacks have been +invoked. + + exports.testAsync = function(beforeExit){ + var n = 0; + setTimeout(function(){ + ++n; + assert.ok(true); + }, 200); + setTimeout(function(){ + ++n; + assert.ok(true); + }, 200); + beforeExit(function(){ + assert.equal(2, n, 'Ensure both timeouts are called'); + }); + }; + +## Assert Utilities + +### assert.isNull(val[, msg]) + +Asserts that the given _val_ is _null_. + + assert.isNull(null); + +### assert.isNotNull(val[, msg]) + +Asserts that the given _val_ is not _null_. + + assert.isNotNull(undefined); + assert.isNotNull(false); + +### assert.isUndefined(val[, msg]) + +Asserts that the given _val_ is _undefined_. + + assert.isUndefined(undefined); + +### assert.isDefined(val[, msg]) + +Asserts that the given _val_ is not _undefined_. + + assert.isDefined(null); + assert.isDefined(false); + +### assert.match(str, regexp[, msg]) + +Asserts that the given _str_ matches _regexp_. + + assert.match('foobar', /^foo(bar)?/); + assert.match('foo', /^foo(bar)?/); + +### assert.length(val, n[, msg]) + +Assert that the given _val_ has a length of _n_. + + assert.length([1,2,3], 3); + assert.length('foo', 3); + +### assert.type(obj, type[, msg]) + +Assert that the given _obj_ is typeof _type_. + + assert.type(3, 'number'); + +### assert.eql(a, b[, msg]) + +Assert that object _b_ is equal to object _a_. This is an +alias for the core _assert.deepEqual()_ method which does complex +comparisons, opposed to _assert.equal()_ which uses _==_. + + assert.eql('foo', 'foo'); + assert.eql([1,2], [1,2]); + assert.eql({ foo: 'bar' }, { foo: 'bar' }); + +### assert.includes(obj, val[, msg]) + +Assert that _obj_ is within _val_. This method supports _Array_s +and _Strings_s. + + assert.includes([1,2,3], 3); + assert.includes('foobar', 'foo'); + assert.includes('foobar', 'bar'); + +### assert.response(server, req, res|fn[, msg|fn]) + +Performs assertions on the given _server_, which should _not_ call +listen(), as this is handled internally by expresso and the server +is killed after all responses have completed. This method works with +any _http.Server_ instance, so _Connect_ and _Express_ servers will work +as well. + +The _req_ object may contain: + + - _url_ request url + - _timeout_ timeout in milliseconds + - _method_ HTTP method + - _data_ request body + - _headers_ headers object + +The _res_ object may be a callback function which +receives the response for assertions, or an object +which is then used to perform several assertions +on the response with the following properties: + + - _body_ assert response body (regexp or string) + - _status_ assert response status code + - _header_ assert that all given headers match (unspecified are ignored, use a regexp or string) + +When providing _res_ you may then also pass a callback function +as the fourth argument for additional assertions. + +Below are some examples: + + assert.response(server, { + url: '/', timeout: 500 + }, { + body: 'foobar' + }); + + assert.response(server, { + url: '/', + method: 'GET' + },{ + body: '{"name":"tj"}', + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf8', + 'X-Foo': 'bar' + } + }); + + assert.response(server, { + url: '/foo', + method: 'POST', + data: 'bar baz' + },{ + body: '/foo bar baz', + status: 200 + }, 'Test POST'); + + assert.response(server, { + url: '/foo', + method: 'POST', + data: 'bar baz' + },{ + body: '/foo bar baz', + status: 200 + }, function(res){ + // All done, do some more tests if needed + }); + + assert.response(server, { + url: '/' + }, function(res){ + assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback'); + }); + + +## expresso(1) + +To run a single test suite (file) run: + + $ expresso test/a.test.js + +To run several suites we may simply append another: + + $ expresso test/a.test.js test/b.test.js + +We can also pass a whitelist of tests to run within all suites: + + $ expresso --only "foo()" --only "bar()" + +Or several with one call: + + $ expresso --only "foo(), bar()" + +Globbing is of course possible as well: + + $ expresso test/* + +When expresso is called without any files, _test/*_ is the default, +so the following is equivalent to the command above: + + $ expresso + +If you wish to unshift a path to `require.paths` before +running tests, you may use the `-I` or `--include` flag. + + $ expresso --include lib test/* + +The previous example is typically what I would recommend, since expresso +supports test coverage via [node-jscoverage](http://github.com/visionmedia/node-jscoverage) (bundled with expresso), +so you will need to expose an instrumented version of you library. + +To instrument your library, simply run [node-jscoverage](http://github.com/visionmedia/node-jscoverage), +passing the _src_ and _dest_ directories: + + $ node-jscoverage lib lib-cov + +Now we can run our tests again, using the _lib-cov_ directory that has been +instrumented with coverage statements: + + $ expresso -I lib-cov test/* + +The output will look similar to below, depending on your test coverage of course :) + +![node coverage](http://dl.dropbox.com/u/6396913/cov.png) + +To make this process easier expresso has the _-c_ or _--cov_ which essentially +does the same as the two commands above. The following two commands will +run the same tests, however one will auto-instrument, and unshift _lib-cov_, +and the other will run tests normally: + + $ expresso -I lib test/* + $ expresso -I lib --cov test/* + +Currently coverage is bound to the _lib_ directory, however in the +future `--cov` will most likely accept a path. + +## Async Exports + +Sometimes it is useful to postpone running of tests until a callback or event has fired, currently the _exports.foo = function(){};_ syntax is supported for this: + + setTimeout(function(){ + exports['test async exports'] = function(){ + assert.ok('wahoo'); + }; + }, 100); diff --git a/node_modules/mongoose/support/expresso/docs/layout/foot.html b/node_modules/mongoose/support/expresso/docs/layout/foot.html new file mode 100644 index 0000000..44d85e9 --- /dev/null +++ b/node_modules/mongoose/support/expresso/docs/layout/foot.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/docs/layout/head.html b/node_modules/mongoose/support/expresso/docs/layout/head.html new file mode 100644 index 0000000..567f62e --- /dev/null +++ b/node_modules/mongoose/support/expresso/docs/layout/head.html @@ -0,0 +1,42 @@ + + + Expresso - TDD Framework For Node + + + + + Fork me on GitHub + +
+

Expresso

diff --git a/node_modules/mongoose/support/expresso/lib/bar.js b/node_modules/mongoose/support/expresso/lib/bar.js new file mode 100644 index 0000000..e15aad4 --- /dev/null +++ b/node_modules/mongoose/support/expresso/lib/bar.js @@ -0,0 +1,4 @@ + +exports.bar = function(msg){ + return msg || 'bar'; +}; \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/lib/foo.js b/node_modules/mongoose/support/expresso/lib/foo.js new file mode 100644 index 0000000..15701a5 --- /dev/null +++ b/node_modules/mongoose/support/expresso/lib/foo.js @@ -0,0 +1,16 @@ + +exports.foo = function(msg){ + if (msg) { + return msg; + } else { + return generateFoo(); + } +}; + +function generateFoo() { + return 'foo'; +} + +function Foo(msg){ + this.msg = msg || 'foo'; +} diff --git a/node_modules/mongoose/support/expresso/package.json b/node_modules/mongoose/support/expresso/package.json new file mode 100644 index 0000000..569a54b --- /dev/null +++ b/node_modules/mongoose/support/expresso/package.json @@ -0,0 +1,12 @@ +{ "name": "expresso", + "version": "0.7.2", + "description": "TDD framework, light-weight, fast, CI-friendly", + "author": "TJ Holowaychuk ", + "bin": { + "expresso": "./bin/expresso", + "node-jscoverage": "./deps/jscoverage/node-jscoverage" + }, + "scripts": { + "preinstall": "make deps/jscoverage/node-jscoverage" + } +} \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/test/assert.test.js b/node_modules/mongoose/support/expresso/test/assert.test.js new file mode 100644 index 0000000..f822595 --- /dev/null +++ b/node_modules/mongoose/support/expresso/test/assert.test.js @@ -0,0 +1,91 @@ + +/** + * Module dependencies. + */ + +var assert = require('assert'); + +module.exports = { + 'assert.eql()': function(){ + assert.equal(assert.deepEqual, assert.eql); + }, + + 'assert.type()': function(){ + assert.type('foobar', 'string'); + assert.type(2, 'number'); + assert.throws(function(){ + assert.type([1,2,3], 'string'); + }); + }, + + 'assert.includes()': function(){ + assert.includes('some random string', 'dom'); + assert.throws(function(){ + assert.include('some random string', 'foobar'); + }); + + assert.includes(['foo', 'bar'], 'bar'); + assert.includes(['foo', 'bar'], 'foo'); + assert.includes([1,2,3], 3); + assert.includes([1,2,3], 2); + assert.includes([1,2,3], 1); + assert.throws(function(){ + assert.includes(['foo', 'bar'], 'baz'); + }); + + assert.throws(function(){ + assert.includes({ wrong: 'type' }, 'foo'); + }); + }, + + 'assert.isNull()': function(){ + assert.isNull(null); + assert.throws(function(){ + assert.isNull(undefined); + }); + assert.throws(function(){ + assert.isNull(false); + }); + }, + + 'assert.isUndefined()': function(){ + assert.isUndefined(undefined); + assert.throws(function(){ + assert.isUndefined(null); + }); + assert.throws(function(){ + assert.isUndefined(false); + }); + }, + + 'assert.isNotNull()': function(){ + assert.isNotNull(false); + assert.isNotNull(undefined); + assert.throws(function(){ + assert.isNotNull(null); + }); + }, + + 'assert.isDefined()': function(){ + assert.isDefined(false); + assert.isDefined(null); + assert.throws(function(){ + assert.isDefined(undefined); + }); + }, + + 'assert.match()': function(){ + assert.match('foobar', /foo(bar)?/); + assert.throws(function(){ + assert.match('something', /rawr/); + }); + }, + + 'assert.length()': function(){ + assert.length('test', 4); + assert.length([1,2,3,4], 4); + assert.throws(function(){ + assert.length([1,2,3], 4); + }); + } +}; \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/test/async.test.js b/node_modules/mongoose/support/expresso/test/async.test.js new file mode 100644 index 0000000..d1d2036 --- /dev/null +++ b/node_modules/mongoose/support/expresso/test/async.test.js @@ -0,0 +1,12 @@ + +/** + * Module dependencies. + */ + +var assert = require('assert'); + +setTimeout(function(){ + exports['test async exports'] = function(){ + assert.ok('wahoo'); + }; +}, 100); \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/test/bar.test.js b/node_modules/mongoose/support/expresso/test/bar.test.js new file mode 100644 index 0000000..cfc2e11 --- /dev/null +++ b/node_modules/mongoose/support/expresso/test/bar.test.js @@ -0,0 +1,13 @@ + +/** + * Module dependencies. + */ + +var assert = require('assert') + , bar = require('bar'); + +module.exports = { + 'bar()': function(){ + assert.equal('bar', bar.bar()); + } +}; \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/test/foo.test.js b/node_modules/mongoose/support/expresso/test/foo.test.js new file mode 100644 index 0000000..ee5cff3 --- /dev/null +++ b/node_modules/mongoose/support/expresso/test/foo.test.js @@ -0,0 +1,14 @@ + +/** + * Module dependencies. + */ + +var assert = require('assert') + , foo = require('foo'); + +module.exports = { + 'foo()': function(){ + assert.equal('foo', foo.foo()); + assert.equal('foo', foo.foo()); + } +}; \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/test/http.test.js b/node_modules/mongoose/support/expresso/test/http.test.js new file mode 100644 index 0000000..41648d2 --- /dev/null +++ b/node_modules/mongoose/support/expresso/test/http.test.js @@ -0,0 +1,109 @@ + +/** + * Module dependencies. + */ + +var assert = require('assert') + , http = require('http'); + +var server = http.createServer(function(req, res){ + if (req.method === 'GET') { + if (req.url === '/delay') { + setTimeout(function(){ + res.writeHead(200, {}); + res.end('delayed'); + }, 200); + } else { + var body = JSON.stringify({ name: 'tj' }); + res.writeHead(200, { + 'Content-Type': 'application/json; charset=utf8', + 'Content-Length': body.length + }); + res.end(body); + } + } else { + var body = ''; + req.setEncoding('utf8'); + req.addListener('data', function(chunk){ body += chunk }); + req.addListener('end', function(){ + res.writeHead(200, {}); + res.end(req.url + ' ' + body); + }); + } +}); + +var delayedServer = http.createServer(function(req, res){ + res.writeHead(200); + res.end('it worked'); +}); + +var oldListen = delayedServer.listen; +delayedServer.listen = function(){ + var args = arguments; + setTimeout(function(){ + oldListen.apply(delayedServer, args); + }, 100); +}; + +module.exports = { + 'test assert.response()': function(beforeExit){ + var called = 0; + + assert.response(server, { + url: '/', + method: 'GET' + },{ + body: '{"name":"tj"}', + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf8' + } + }); + + assert.response(server, { + url: '/foo', + method: 'POST', + data: 'bar baz' + },{ + body: '/foo bar baz', + status: 200 + }, function(res){ + ++called; + assert.ok(res); + }); + + assert.response(server, { + url: '/foo' + }, function(res){ + ++called; + assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback'); + }); + + assert.response(server, + { url: '/delay', timeout: 300 }, + { body: 'delayed' }); + + beforeExit(function(){ + assert.equal(2, called); + }); + }, + + 'test assert.response() regexp': function(){ + assert.response(server, + { url: '/foo', method: 'POST', data: 'foobar' }, + { body: /^\/foo foo(bar)?/ }); + }, + + 'test assert.response() regexp headers': function(){ + assert.response(server, + { url: '/' }, + { body: '{"name":"tj"}', headers: { 'Content-Type': /^application\/json/ } }); + }, + + // [!] if this test doesn't pass, an uncaught ECONNREFUSED will display + 'test assert.response() with deferred listen()': function(){ + assert.response(delayedServer, + { url: '/' }, + { body: 'it worked' }); + } +}; diff --git a/node_modules/mongoose/support/expresso/test/serial/async.test.js b/node_modules/mongoose/support/expresso/test/serial/async.test.js new file mode 100644 index 0000000..c596d5c --- /dev/null +++ b/node_modules/mongoose/support/expresso/test/serial/async.test.js @@ -0,0 +1,39 @@ + +var assert = require('assert') + , setup = 0 + , order = []; + +module.exports = { + setup: function(done){ + ++setup; + done(); + }, + + a: function(done){ + assert.equal(1, setup); + order.push('a'); + setTimeout(function(){ + done(); + }, 500); + }, + + b: function(done){ + assert.equal(2, setup); + order.push('b'); + setTimeout(function(){ + done(); + }, 200); + }, + + c: function(done){ + assert.equal(3, setup); + order.push('c'); + setTimeout(function(){ + done(); + }, 1000); + }, + + d: function(){ + assert.eql(order, ['a', 'b', 'c']); + } +}; \ No newline at end of file diff --git a/node_modules/mongoose/support/expresso/test/serial/http.test.js b/node_modules/mongoose/support/expresso/test/serial/http.test.js new file mode 100644 index 0000000..7783eb5 --- /dev/null +++ b/node_modules/mongoose/support/expresso/test/serial/http.test.js @@ -0,0 +1,48 @@ + +/** + * Module dependencies. + */ + +var assert = require('assert') + , http = require('http'); + +var server = http.createServer(function(req, res){ + if (req.method === 'GET') { + if (req.url === '/delay') { + setTimeout(function(){ + res.writeHead(200, {}); + res.end('delayed'); + }, 200); + } else { + var body = JSON.stringify({ name: 'tj' }); + res.writeHead(200, { + 'Content-Type': 'application/json; charset=utf8', + 'Content-Length': body.length + }); + res.end(body); + } + } else { + var body = ''; + req.setEncoding('utf8'); + req.addListener('data', function(chunk){ body += chunk }); + req.addListener('end', function(){ + res.writeHead(200, {}); + res.end(req.url + ' ' + body); + }); + } +}); + +module.exports = { + 'test assert.response()': function(done){ + assert.response(server, { + url: '/', + method: 'GET' + },{ + body: '{"name":"tj"}', + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf8' + } + }, done); + } +}; \ No newline at end of file -- cgit v1.2.3-70-g09d2