-
-
Save jergason/1628063 to your computer and use it in GitHub Desktop.
Asynchronous Vows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
var vows = require('vows') | |
, suite | |
, batch | |
, helloWorld = require('./index') | |
, assert = require('assert') | |
, request = require('ahr2') | |
, createJoin = require('join') | |
, forEachAsync = require('forEachAsync') | |
; | |
batch = { | |
'foo context': { | |
topic: function () { | |
return helloWorld(); | |
} | |
, 'helloWorld output test': function (msg) { | |
assert.strictEqual(msg, 'Hello World!'); | |
} | |
} | |
, 'test foobar3000': { | |
topic: function () { | |
request('http://foobar3000.com/echo/bar.json').when(this.callback); | |
} | |
, 'foobar3000 pathname test': function (err, ahr, body) { | |
assert.strictEqual(body.pathname, '/echo/bar.json'); | |
} | |
} | |
, 'test join foobar3000': { | |
topic: function () { | |
var join = createJoin() | |
; | |
request('http://foobar3000.com/echo/baz.json').when(join.add()); | |
request('http://foobar3000.com/echo/quux.json').when(join.add()); | |
join.when(this.callback); | |
} | |
, 'foobar3000 pathname test': function (res1, res2) { | |
//var args = Array.prototype.slice(arguments); | |
var body1 = res1[2] | |
, body2 = res2[2] | |
; | |
assert.strictEqual(body1.pathname, '/echo/baz.json'); | |
assert.strictEqual(body2.pathname, '/echo/quux.json'); | |
} | |
, 'teardown': function (topic) { | |
console.log('in teardown function'); | |
} | |
} | |
, 'test forEachAsync foobar3000': { | |
topic: function () { | |
var urls | |
, self = this | |
; | |
urls =[ | |
'/echo/qux.json' | |
, '/echo/hurp.json' | |
]; | |
forEachAsync(urls, function (next, url) { | |
request('http://foobar3000.com' + url).when(next); | |
}).then(function () { | |
self.callback(true); | |
}); | |
} | |
, 'foobar3000 pathname test': function (finished) { | |
// at least we got here | |
assert.ok(finished); | |
} | |
} | |
}; | |
suite = vows.describe('my-test'); | |
suite.addBatch(batch); | |
suite.export(module); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added a teardown function. See http://stackoverflow.com/questions/7065035/how-to-run-cleanup-with-vows-js and vowsjs/vows#14 for discussion on it, but it runs after the vows in the context finish.