Create a gist now

Instantly share code, notes, and snippets.

@twolfson /.gitignore
Last active Aug 29, 2015

What would you like to do?
data/
node_modules/
// Load in test dependencies
var http = require('http');
var eightTrack = require('eight-track');
var expect = require('chai').expect;
var request = require('request');
// Start tests
describe('A request to our server', function () {
// Create a temporary eight-track server (forwards requests to twolfson.com)
before(function startEightTrack () {
this.twolfsonEightTrack = http.createServer(eightTrack({
url: 'http://twolfson.com',
fixtureDir: 'data/twolfson-eight-track'
}));
this.twolfsonEightTrack.listen(1337);
});
after(function cleanup (done) {
this.twolfsonEightTrack.close(done);
delete this.twolfsonEightTrack;
});
// Make request to eight-track server (could proxy to twolfson.com)
before(function makeRequestToServer (done) {
var that = this;
request({
url: 'http://localhost:1337/'
}, function handleRes (err, res, body) {
// Save body and callback with error
that.body = body;
done(err);
});
});
// Make assertions about request
it('receives the expected content', function () {
expect(this.body).to.contain('Todd Wolfson');
});
});
{
"name": "gist-eight-track-article-1",
"version": "1.0.0",
"description": "Example from http://twolfson.com/2015-01-11-testing-with-other-services",
"main": "index.js",
"author": "Todd Wolfson <todd@twolfson.com> (http://twolfson.com/)",
"license": "UNLICENSE",
"scripts": {
"test": "mocha index.js"
},
"dependencies": {
"chai": "~1.10.0",
"eight-track": "~2.1.0",
"mocha": "~2.1.0",
"request": "~2.51.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment