Comparing version 0.0.1 to 0.1.0
var http = require('http'); | ||
var url_parse = require('url').parse; | ||
exports.get = function get(url, callback) { | ||
function req(method, url, data, callback) { | ||
@@ -12,2 +12,3 @@ url = url_parse(url); | ||
path: url.pathname + (url.search || ''), | ||
method: method, | ||
headers: { | ||
@@ -18,3 +19,3 @@ 'Accept': 'application/json', | ||
http.get(opts, function (resp) { | ||
var req = http.request(opts, function (resp) { | ||
@@ -52,10 +53,23 @@ if (resp.statusCode >= 400) { | ||
}).on('error', function (err) { | ||
}); | ||
req.on('error', function (err) { | ||
callback(err); | ||
}); | ||
if (data) { | ||
req.setHeader('Content-Type', 'application/json'); | ||
req.write(JSON.stringify(data)); | ||
} | ||
req.end(); | ||
}; | ||
exports.get = function get(url, callback) { | ||
req('GET', url, null, callback); | ||
}; | ||
exports.post = function post(url, data, callback) { | ||
callback(new Error("not implemented yet!")); | ||
req('POST', url, data, callback); | ||
}; |
@@ -36,4 +36,4 @@ { | ||
"dist": { | ||
"shasum": "08ba4eccc1d3caa046b2d6475d8f25fe019b6be3" | ||
"shasum": "330a0a649be617dfeaf2f61985ca8212d32bd618" | ||
} | ||
} |
@@ -40,2 +40,32 @@ @aseemk's changes | ||
* A static `should.be.defined(foo)` for when null is ok but undefined is not. | ||
Similarly, a static `should.be.undefined(foo)`. (Not submitted yet.) | ||
* Automatic detection for the common `should.not.exist(err)` use case: no need | ||
to pass in a custom assertion message; it just uses the error itself. | ||
([Pull request](https://github.com/visionmedia/should.js/pull/14); | ||
submitted as an extension to the should.exist() feature.) | ||
Major hat tip to TJ for the awesome and inspirational library. | ||
More ideas | ||
---------- | ||
In no particular order, more things I'd like to add: | ||
* The holy grail: support a much more flexible language by having everything | ||
support being both a dummy getter and an assertion method that can be called. | ||
E.g. `be` in both `foo.should.be(bar)` and `foo.should.be.a('string')`. | ||
* More and smarter aliases. E.g. `a` and `an` (assuming both were flexible as | ||
described above) should cover both the `typeof` and `instanceof` cases, just | ||
based on whether the argument is a string or (constructor) function. | ||
* Monkey-patch the static `should.equal()`, AKA the native `assert.equal()`, to | ||
use strict equality, to match the instance `foo.should.equal(bar)`. | ||
* Improve the custom message support to still inspect and output the expected and | ||
actual values, in addition to my custom message, in a nice format. | ||
If you would especially like to see any of these things, just let me know. |
@@ -55,3 +55,2 @@ | ||
message: msg || ('expected ' + i(obj) + ' to exist') | ||
, stackStartFunction: exports.exist | ||
}); | ||
@@ -73,4 +72,3 @@ } | ||
throw new AssertionError({ | ||
message: msg || ('expected ' + i(obj) + ' to not exist') | ||
, stackStartFunction: exports.not.exist | ||
message: msg || (obj instanceof Error && obj.toString()) || ('expected ' + i(obj) + ' to not exist') | ||
}); | ||
@@ -81,2 +79,40 @@ } | ||
/** | ||
* Asserts _obj_ is defined, with optional message. | ||
* | ||
* @param {Mixed} obj | ||
* @param {String} msg | ||
* @api public | ||
*/ | ||
exports.be = {}; | ||
exports.be.defined = function(obj, msg){ | ||
if (undefined === obj) { | ||
throw new AssertionError({ | ||
message: msg || ('expected ' + i(obj) + ' to be defined') | ||
}); | ||
} | ||
}; | ||
/** | ||
* Asserts _obj_ is undefined, with optional message. | ||
* | ||
* @param {Mixed} obj | ||
* @param {String} msg | ||
* @api public | ||
*/ | ||
exports.be.undefined = function(obj, msg){ | ||
if (undefined !== obj) { | ||
throw new AssertionError({ | ||
message: msg || ('expected ' + i(obj) + ' to be undefined') | ||
}); | ||
} | ||
}; | ||
// Aliases for should.be.defined and should.be.undefined: | ||
exports.not.be = {}; | ||
exports.not.be.defined = exports.be.undefined; | ||
exports.not.be.undefined = exports.be.defined; | ||
/** | ||
* Expose api via `Object#should`. | ||
@@ -83,0 +119,0 @@ * |
@@ -87,2 +87,14 @@ _should_ is an expressive, readable, test framework agnostic, assertion library for [node](http://nodejs.org). | ||
## defined (static) | ||
If you only care to test whether an object is undefined (i.e. null is okay): | ||
should.be.defined(foo) | ||
should.be.undefined(foo) | ||
Their negations are also available as aliases: | ||
should.not.be.defined(foo) // alias for should.be.undefined | ||
should.not.be.undefined(foo) // alias for should.be.defined | ||
## truthy | ||
@@ -89,0 +101,0 @@ |
@@ -9,9 +9,13 @@ | ||
function err(fn, msg) { | ||
var error; | ||
try { | ||
fn(); | ||
should.fail('expected an error'); | ||
} catch (err) { | ||
error = err; | ||
should.exist(err.message); | ||
err.message.should.equal(msg); | ||
} | ||
if (!error) { | ||
should.fail('expected an error'); | ||
} | ||
} | ||
@@ -56,4 +60,50 @@ | ||
}, 'test assertion message!'); | ||
err(function(){ | ||
try { | ||
foo.bar; | ||
} catch (e) { | ||
should.not.exist(e); | ||
} | ||
}, 'ReferenceError: foo is not defined'); | ||
}, | ||
'test [un]defined': function(){ | ||
should.be.defined('test'); | ||
should.be.defined(0); | ||
should.be.defined(null); | ||
should.not.be.defined(undefined); | ||
should.not.be.undefined('test'); | ||
should.not.be.undefined(false); | ||
should.not.be.undefined(''); | ||
should.be.undefined(undefined); | ||
err(function(){ | ||
should.be.defined(undefined); | ||
}, 'expected undefined to be defined'); | ||
err(function(){ | ||
should.not.be.defined(null); | ||
}, 'expected null to be undefined'); | ||
err(function(){ | ||
should.not.be.defined(false, 'test assertion message'); | ||
}, 'test assertion message'); | ||
err(function(){ | ||
should.be.undefined(null); | ||
}, 'expected null to be undefined'); | ||
err(function(){ | ||
should.not.be.undefined(undefined); | ||
}, 'expected undefined to be defined'); | ||
err(function(){ | ||
should.be.undefined({}, 'test assertion message'); | ||
}, 'test assertion message'); | ||
}, | ||
'test true': function(){ | ||
@@ -60,0 +110,0 @@ true.should.be.true(); |
@@ -40,2 +40,32 @@ @aseemk's changes | ||
* A static `should.be.defined(foo)` for when null is ok but undefined is not. | ||
Similarly, a static `should.be.undefined(foo)`. (Not submitted yet.) | ||
* Automatic detection for the common `should.not.exist(err)` use case: no need | ||
to pass in a custom assertion message; it just uses the error itself. | ||
([Pull request](https://github.com/visionmedia/should.js/pull/14); | ||
submitted as an extension to the should.exist() feature.) | ||
Major hat tip to TJ for the awesome and inspirational library. | ||
More ideas | ||
---------- | ||
In no particular order, more things I'd like to add: | ||
* The holy grail: support a much more flexible language by having everything | ||
support being both a dummy getter and an assertion method that can be called. | ||
E.g. `be` in both `foo.should.be(bar)` and `foo.should.be.a('string')`. | ||
* More and smarter aliases. E.g. `a` and `an` (assuming both were flexible as | ||
described above) should cover both the `typeof` and `instanceof` cases, just | ||
based on whether the argument is a string or (constructor) function. | ||
* Monkey-patch the static `should.equal()`, AKA the native `assert.equal()`, to | ||
use strict equality, to match the instance `foo.should.equal(bar)`. | ||
* Improve the custom message support to still inspect and output the expected and | ||
actual values, in addition to my custom message, in a nice format. | ||
If you would especially like to see any of these things, just let me know. |
@@ -55,3 +55,2 @@ | ||
message: msg || ('expected ' + i(obj) + ' to exist') | ||
, stackStartFunction: exports.exist | ||
}); | ||
@@ -73,4 +72,3 @@ } | ||
throw new AssertionError({ | ||
message: msg || ('expected ' + i(obj) + ' to not exist') | ||
, stackStartFunction: exports.not.exist | ||
message: msg || (obj instanceof Error && obj.toString()) || ('expected ' + i(obj) + ' to not exist') | ||
}); | ||
@@ -81,2 +79,40 @@ } | ||
/** | ||
* Asserts _obj_ is defined, with optional message. | ||
* | ||
* @param {Mixed} obj | ||
* @param {String} msg | ||
* @api public | ||
*/ | ||
exports.be = {}; | ||
exports.be.defined = function(obj, msg){ | ||
if (undefined === obj) { | ||
throw new AssertionError({ | ||
message: msg || ('expected ' + i(obj) + ' to be defined') | ||
}); | ||
} | ||
}; | ||
/** | ||
* Asserts _obj_ is undefined, with optional message. | ||
* | ||
* @param {Mixed} obj | ||
* @param {String} msg | ||
* @api public | ||
*/ | ||
exports.be.undefined = function(obj, msg){ | ||
if (undefined !== obj) { | ||
throw new AssertionError({ | ||
message: msg || ('expected ' + i(obj) + ' to be undefined') | ||
}); | ||
} | ||
}; | ||
// Aliases for should.be.defined and should.be.undefined: | ||
exports.not.be = {}; | ||
exports.not.be.defined = exports.be.undefined; | ||
exports.not.be.undefined = exports.be.defined; | ||
/** | ||
* Expose api via `Object#should`. | ||
@@ -83,0 +119,0 @@ * |
@@ -87,2 +87,14 @@ _should_ is an expressive, readable, test framework agnostic, assertion library for [node](http://nodejs.org). | ||
## defined (static) | ||
If you only care to test whether an object is undefined (i.e. null is okay): | ||
should.be.defined(foo) | ||
should.be.undefined(foo) | ||
Their negations are also available as aliases: | ||
should.not.be.defined(foo) // alias for should.be.undefined | ||
should.not.be.undefined(foo) // alias for should.be.defined | ||
## truthy | ||
@@ -89,0 +101,0 @@ |
@@ -9,9 +9,13 @@ | ||
function err(fn, msg) { | ||
var error; | ||
try { | ||
fn(); | ||
should.fail('expected an error'); | ||
} catch (err) { | ||
error = err; | ||
should.exist(err.message); | ||
err.message.should.equal(msg); | ||
} | ||
if (!error) { | ||
should.fail('expected an error'); | ||
} | ||
} | ||
@@ -56,4 +60,50 @@ | ||
}, 'test assertion message!'); | ||
err(function(){ | ||
try { | ||
foo.bar; | ||
} catch (e) { | ||
should.not.exist(e); | ||
} | ||
}, 'ReferenceError: foo is not defined'); | ||
}, | ||
'test [un]defined': function(){ | ||
should.be.defined('test'); | ||
should.be.defined(0); | ||
should.be.defined(null); | ||
should.not.be.defined(undefined); | ||
should.not.be.undefined('test'); | ||
should.not.be.undefined(false); | ||
should.not.be.undefined(''); | ||
should.be.undefined(undefined); | ||
err(function(){ | ||
should.be.defined(undefined); | ||
}, 'expected undefined to be defined'); | ||
err(function(){ | ||
should.not.be.defined(null); | ||
}, 'expected null to be undefined'); | ||
err(function(){ | ||
should.not.be.defined(false, 'test assertion message'); | ||
}, 'test assertion message'); | ||
err(function(){ | ||
should.be.undefined(null); | ||
}, 'expected null to be undefined'); | ||
err(function(){ | ||
should.not.be.undefined(undefined); | ||
}, 'expected undefined to be defined'); | ||
err(function(){ | ||
should.be.undefined({}, 'test assertion message'); | ||
}, 'test assertion message'); | ||
}, | ||
'test true': function(){ | ||
@@ -60,0 +110,0 @@ true.should.be.true(); |
{ | ||
"name": "jsonreq", | ||
"description": "JSON requests made easy.", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"author": "Aseem Kishore <aseem.kishore@gmail.com>", | ||
@@ -13,7 +13,7 @@ "keywords": ["json", "request", "http", "get", "post"], | ||
"should": "https://github.com/aseemk/should.js/tarball/master", | ||
"streamline": "0.1.*" | ||
"streamline": "0.1.x" | ||
}, | ||
"scripts": { | ||
"test": "node-streamline test" | ||
"test": "node-streamline test_" | ||
} | ||
} |
60
test_.js
var json = require('./'); | ||
var should = require('should'); | ||
var streamline = require('streamline'); | ||
var flows = streamline.flows; | ||
var SERVER = require('./test_server'); | ||
var SERVER_PORT = 9999; | ||
var SERVER_BASE = 'http://localhost:' + SERVER_PORT; | ||
var SERVER_ADDRESS = 'http://localhost:' + SERVER_PORT; | ||
@@ -27,3 +28,3 @@ var TEST_CASES = { | ||
'Empty JSON': { | ||
url: SERVER_BASE + '/', | ||
url: SERVER_ADDRESS, | ||
exp: null, | ||
@@ -60,2 +61,13 @@ }, | ||
// our test server reverses data passed to it | ||
'Post JSON': { | ||
url: SERVER_ADDRESS, | ||
post: [ 'alpha', 'beta', 'gamma', { | ||
'delta': 'epsilon', | ||
}], | ||
exp: [{ | ||
'delta': 'epsilon', | ||
}, 'gamma', 'beta', 'alpha'], | ||
}, | ||
}; | ||
@@ -71,7 +83,2 @@ | ||
// TODO this should be part of should.js (or replace should.exist) | ||
function isdef(x) { | ||
return typeof x !== "undefined"; | ||
} | ||
function test(name, data, _) { | ||
@@ -83,3 +90,7 @@ var act, err; | ||
try { | ||
act = json.get(data.url, _); | ||
if (data.post) { | ||
act = json.post(data.url, data.post, _); | ||
} else { | ||
act = json.get(data.url, _); | ||
} | ||
} catch (e) { | ||
@@ -92,15 +103,14 @@ err = e; | ||
if (data.err) { | ||
should.exist(err, name + ' expected error, received result: ' + act); | ||
err.should.match(data.err, name + ' error doesn\'t match expected: ' + err + ' vs. ' + data.err); | ||
should.not.exist(act, name + ' received error *and* result: ' + act); | ||
should.exist(err, 'expected error, received result: ' + act); | ||
err.should.match(data.err, 'error doesn\'t match expected: ' + err + ' vs. ' + data.err); | ||
should.not.exist(act, 'received error *and* result: ' + act); | ||
return; | ||
} | ||
should.not.exist(err, name + ' threw error: ' + err); | ||
should.not.exist(err); | ||
should.be.defined(act, 'received neither error not result'); | ||
// note how act can be null, but cannot be undefined | ||
// TEMP act and data.exp can be null, so we can't be totally expressive here. see comments: | ||
// equivalent to "act should be defined" (but it can be null) | ||
isdef(act).should.be.truthy(name + ' received neither error nor result'); | ||
// equivalent to "act should be of type object" | ||
@@ -110,3 +120,3 @@ // note that {...}, [...] and null are all type 'object' | ||
if (isdef(data.exp)) { | ||
if ('exp' in data) { // i.e. it's specified (but can be null) | ||
// equivalent to "act should match data.exp", but need to account for null | ||
@@ -117,13 +127,27 @@ should.deepEqual(act, data.exp, name + ' content doesn\'t match expected: ' + act + ' vs. ' + data.exp); | ||
function tryTest(name, data, _) { | ||
try { | ||
test(name, data, _); | ||
console.log('\t✓ ' + name); | ||
} catch (e) { | ||
console.log('\tx ' + name); | ||
console.error('\t ' + e.message); | ||
// don't propagate! | ||
} | ||
} | ||
console.log(); | ||
SERVER.listen(SERVER_PORT, _); // wait for it to start | ||
var testFutures = []; | ||
for (var name in TEST_CASES) { | ||
testFutures.push( | ||
test(name, TEST_CASES[name]) | ||
tryTest(name, TEST_CASES[name]) | ||
); | ||
} | ||
streamline.flows.spray(testFutures).collectAll(_); | ||
flows.spray(testFutures).collectAll(_); | ||
SERVER.close(); | ||
console.log(); |
@@ -1,2 +0,4 @@ | ||
var server = module.exports = require('http').createServer(function (req, resp) { | ||
var should = require('should'); | ||
module.exports = require('http').createServer(function (req, resp) { | ||
@@ -6,8 +8,36 @@ // this is super simplistic and not flexible or robust. | ||
switch (req.uri) { | ||
// TODO | ||
} | ||
var body = []; | ||
resp.end(); | ||
req.setEncoding('utf8'); | ||
}); | ||
req.on('data', function (chunk) { | ||
body.push(chunk); | ||
}); | ||
req.on('end', function () { | ||
var bodyStr = body.join(''); | ||
// if no data posted, just return | ||
if (!bodyStr) { | ||
return resp.end(); | ||
} | ||
var data; | ||
try { | ||
data = JSON.parse(bodyStr); | ||
data.should.be.an.instanceof(Array); | ||
} catch (e) { | ||
resp.writeHead(400, e); | ||
return resp.end(); | ||
} | ||
data.reverse(); | ||
resp.setHeader('Content-Type', 'application/json'); | ||
resp.end(JSON.stringify(data)); | ||
}); | ||
}); |
203
test.js
@@ -1,66 +0,73 @@ | ||
/*** Generated by streamline --lines-mark 0.1.11 - DO NOT EDIT ***/ | ||
/*** Generated by streamline --lines-mark 0.1.12 - DO NOT EDIT ***/ | ||
var __global = typeof global !== 'undefined' ? global : window; | ||
function __cb(_, fn) { var ctx = __global.__context; return function(err, result) { __global.__context = ctx; if (err) return _(err); return fn(null, result); } } | ||
function __future(fn, args, i) { if (!fn) throw new Error("anonymous function requires callback"); var done, err, result; var cb = function(e, r) { done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r) { cb(e, r); }; fn.apply(this, args); return function(_) { if (typeof _ !== "function") throw new Error("future requires callback"); if (done) _.call(this, err, result); else cb = _.bind(this); }.bind(this); } | ||
function __future(fn, args, i) { var done, err, result; var cb = function(e, r) { done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r) { cb(e, r); }; fn.apply(this, args); return function(_) { if (done) _.call(this, err, result); else cb = _.bind(this); }.bind(this); } | ||
function __propagate(_, err) { try { _(err); } catch (ex) { __trap(ex); } } | ||
function __trap(err) { if (err) { if (__global.__context && __global.__context.errorHandler) __global.__context.errorHandler(err); else console.error("UNCAUGHT EXCEPTION: " + err.message + "\n" + err.stack); } } | ||
(function(_) { | ||
var __ = (_ = (_ || __trap)); | ||
var __then = (_ = (_ || __trap)); | ||
/* 1 */ var json = require("./"); | ||
/* 2 */ var should = require("should"); | ||
/* 3 */ var streamline = require("streamline"); | ||
/* 5 */ var SERVER = require("./test_server"); | ||
/* 6 */ var SERVER_PORT = 9999; | ||
/* 7 */ var SERVER_BASE = ("http://localhost:" + SERVER_PORT); | ||
/* 9 */ var TEST_CASES = { | ||
/* 11 */ "Non-existent": { | ||
/* 12 */ url: "http://i.certainly.dont.exist.example.com", | ||
/* 13 */ err: /ENOTFOUND/ | ||
/* 4 */ var flows = streamline.flows; | ||
/* 6 */ var SERVER = require("./test_server"); | ||
/* 7 */ var SERVER_PORT = 9999; | ||
/* 8 */ var SERVER_ADDRESS = ("http://localhost:" + SERVER_PORT); | ||
/* 10 */ var TEST_CASES = { | ||
/* 12 */ "Non-existent": { | ||
/* 13 */ url: "http://i.certainly.dont.exist.example.com", | ||
/* 14 */ err: /ENOTFOUND/ | ||
}, | ||
/* 16 */ "Non-200": { | ||
/* 17 */ url: "http://json.org/404", | ||
/* 18 */ err: /404/ | ||
/* 17 */ "Non-200": { | ||
/* 18 */ url: "http://json.org/404", | ||
/* 19 */ err: /404/ | ||
}, | ||
/* 21 */ "Non-JSON": { | ||
/* 22 */ url: "http://google.com/", | ||
/* 23 */ err: /SyntaxError/ | ||
/* 22 */ "Non-JSON": { | ||
/* 23 */ url: "http://google.com/", | ||
/* 24 */ err: /SyntaxError/ | ||
}, | ||
/* 26 */ "Empty JSON": { | ||
/* 27 */ url: (SERVER_BASE + "/"), | ||
/* 28 */ exp: null | ||
/* 27 */ "Empty JSON": { | ||
/* 28 */ url: SERVER_ADDRESS, | ||
/* 29 */ exp: null | ||
}, | ||
/* 32 */ Twitter: { | ||
/* 33 */ url: "https://api.twitter.com/1/statuses/show/20.json" | ||
/* 33 */ Twitter: { | ||
/* 34 */ url: "https://api.twitter.com/1/statuses/show/20.json" | ||
}, | ||
/* 38 */ "Zoom.it": { | ||
/* 39 */ url: "http://api.zoom.it/v1/content/h", | ||
/* 40 */ exp: { | ||
/* 41 */ id: "h", | ||
/* 42 */ url: "http://upload.wikimedia.org/wikipedia/commons/3/36/SeattleI5Skyline.jpg", | ||
/* 43 */ ready: true, | ||
/* 44 */ failed: false, | ||
/* 45 */ progress: 1, | ||
/* 46 */ shareUrl: "http://zoom.it/h", | ||
/* 47 */ embedHtml: "<script src=\"http://zoom.it/h.js?width=auto&height=400px\"></script>", | ||
/* 48 */ dzi: { | ||
/* 49 */ url: "http://cache.zoom.it/content/h.dzi", | ||
/* 50 */ width: 4013, | ||
/* 51 */ height: 2405, | ||
/* 52 */ tileSize: 254, | ||
/* 53 */ tileOverlap: 1, | ||
/* 54 */ tileFormat: "jpg" | ||
/* 39 */ "Zoom.it": { | ||
/* 40 */ url: "http://api.zoom.it/v1/content/h", | ||
/* 41 */ exp: { | ||
/* 42 */ id: "h", | ||
/* 43 */ url: "http://upload.wikimedia.org/wikipedia/commons/3/36/SeattleI5Skyline.jpg", | ||
/* 44 */ ready: true, | ||
/* 45 */ failed: false, | ||
/* 46 */ progress: 1, | ||
/* 47 */ shareUrl: "http://zoom.it/h", | ||
/* 48 */ embedHtml: "<script src=\"http://zoom.it/h.js?width=auto&height=400px\"></script>", | ||
/* 49 */ dzi: { | ||
/* 50 */ url: "http://cache.zoom.it/content/h.dzi", | ||
/* 51 */ width: 4013, | ||
/* 52 */ height: 2405, | ||
/* 53 */ tileSize: 254, | ||
/* 54 */ tileOverlap: 1, | ||
/* 55 */ tileFormat: "jpg" | ||
} | ||
} | ||
}, | ||
/* 61 */ "Post JSON": { | ||
/* 62 */ url: SERVER_ADDRESS, | ||
/* 63 */ post: ["alpha","beta","gamma",{ | ||
/* 64 */ delta: "epsilon" | ||
},], | ||
/* 66 */ exp: [{ | ||
/* 67 */ delta: "epsilon" | ||
/* 68 */ },"gamma","beta","alpha",] | ||
} | ||
}; | ||
/* 61 */ var started = 0, finished = 0; | ||
/* 64 */ process.on("exit", function __1() { | ||
/* 65 */ var remaining = (started - finished); | ||
/* 66 */ remaining.should.equal(0, (remaining + " callbacks never fired!")); | ||
/* 73 */ var started = 0, finished = 0; | ||
/* 76 */ process.on("exit", function __1() { | ||
/* 77 */ var remaining = (started - finished); | ||
/* 78 */ remaining.should.equal(0, (remaining + " callbacks never fired!")); | ||
}); | ||
/* 70 */ function isdef(x) { | ||
/* 71 */ return (typeof x !== "undefined"); | ||
}; | ||
/* 74 */ function test(name, data, _) { | ||
/* 81 */ function test(name, data, _) { | ||
if (!_) { | ||
@@ -70,12 +77,21 @@ return __future(test, arguments, 2); | ||
; | ||
var __ = _; | ||
/* 75 */ var act, err; | ||
/* 77 */ started++; | ||
return function(__) { | ||
var __then = _; | ||
/* 82 */ var act, err; | ||
/* 84 */ started++; | ||
return function(__then) { | ||
return function(_) { | ||
try { | ||
/* 80 */ return json.get(data.url, __cb(_, function(__0, __1) { | ||
/* 80 */ act = __1; | ||
return __(); | ||
})); | ||
/* 87 */ if (data.post) { | ||
/* 88 */ return json.post(data.url, data.post, __cb(_, function(__0, __1) { | ||
/* 88 */ act = __1; | ||
return __then(); | ||
})); | ||
} | ||
else { | ||
/* 90 */ return json.get(data.url, __cb(_, function(__0, __2) { | ||
/* 90 */ act = __2; | ||
return __then(); | ||
})); | ||
} | ||
; | ||
} catch (e) { | ||
@@ -87,3 +103,3 @@ return __propagate(_, e); | ||
if (e) { | ||
/* 82 */ err = e; | ||
/* 93 */ err = e; | ||
} | ||
@@ -95,22 +111,22 @@ else return _(null, __result) | ||
}; | ||
return __(); | ||
return __then(); | ||
}); | ||
}(function() { | ||
try { | ||
/* 85 */ finished++; | ||
/* 87 */ if (data.err) { | ||
/* 88 */ should.exist(err, ((name + " expected error, received result: ") + act)); | ||
/* 89 */ err.should.match(data.err, ((((name + " error doesn't match expected: ") + err) + " vs. ") + data.err)); | ||
/* 90 */ should.not.exist(act, ((name + " received error *and* result: ") + act)); | ||
/* 96 */ finished++; | ||
/* 98 */ if (data.err) { | ||
/* 99 */ should.exist(err, ("expected error, received result: " + act)); | ||
/* 100 */ err.should.match(data.err, ((("error doesn't match expected: " + err) + " vs. ") + data.err)); | ||
/* 101 */ should.not.exist(act, ("received error *and* result: " + act)); | ||
return _(null); | ||
} | ||
; | ||
/* 94 */ should.not.exist(err, ((name + " threw error: ") + err)); | ||
/* 99 */ isdef(act).should.be.truthy((name + " received neither error nor result")); | ||
/* 103 */ ((typeof act === "object")).should.be.truthy(((name + " returned content is not an object or array: ") + act)); | ||
/* 105 */ if (isdef(data.exp)) { | ||
/* 107 */ should.deepEqual(act, data.exp, ((((name + " content doesn't match expected: ") + act) + " vs. ") + data.exp)); | ||
/* 105 */ should.not.exist(err); | ||
/* 106 */ should.be.defined(act, "received neither error not result"); | ||
/* 113 */ ((typeof act === "object")).should.be.truthy(((name + " returned content is not an object or array: ") + act)); | ||
/* 115 */ if (("exp" in data)) { | ||
/* 117 */ should.deepEqual(act, data.exp, ((((name + " content doesn't match expected: ") + act) + " vs. ") + data.exp)); | ||
} | ||
; | ||
return __(); | ||
return __then(); | ||
} catch (e) { | ||
@@ -121,12 +137,51 @@ return __propagate(_, e); | ||
}; | ||
/* 111 */ return SERVER.listen(SERVER_PORT, __cb(_, function() { | ||
/* 113 */ var testFutures = []; | ||
/* 114 */ for (var name in TEST_CASES) { | ||
/* 115 */ testFutures.push(test(name, TEST_CASES[name])); | ||
/* 121 */ function tryTest(name, data, _) { | ||
if (!_) { | ||
return __future(tryTest, arguments, 2); | ||
} | ||
; | ||
var __then = _; | ||
return function(__then) { | ||
return function(_) { | ||
try { | ||
/* 123 */ return test(name, data, __cb(_, function() { | ||
/* 124 */ console.log((" ✓ " + name)); | ||
return __then(); | ||
})); | ||
} catch (e) { | ||
return __propagate(_, e); | ||
}; | ||
}(function(e, __result) { | ||
try { | ||
if (e) { | ||
/* 126 */ console.log((" x " + name)); | ||
/* 127 */ console.error((" " + e.message)); | ||
} | ||
else return _(null, __result) | ||
; | ||
} catch (e) { | ||
return __propagate(_, e); | ||
}; | ||
return __then(); | ||
}); | ||
}(function() { | ||
try { | ||
return __then(); | ||
} catch (e) { | ||
return __propagate(_, e); | ||
}; | ||
}); | ||
}; | ||
/* 132 */ console.log(); | ||
/* 133 */ return SERVER.listen(SERVER_PORT, __cb(_, function() { | ||
/* 135 */ var testFutures = []; | ||
/* 137 */ for (var name in TEST_CASES) { | ||
/* 138 */ testFutures.push(tryTest(name, TEST_CASES[name])); | ||
}; | ||
/* 120 */ return streamline.flows.spray(testFutures).collectAll(__cb(_, function() { | ||
/* 122 */ SERVER.close(); | ||
return __(); | ||
/* 143 */ return flows.spray(testFutures).collectAll(__cb(_, function() { | ||
/* 145 */ SERVER.close(); | ||
/* 146 */ console.log(); | ||
return __then(); | ||
})); | ||
})); | ||
})(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
128154
33
2789