Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twolfson/c12a75a018ce0d1b2b12 to your computer and use it in GitHub Desktop.
Save twolfson/c12a75a018ce0d1b2b12 to your computer and use it in GitHub Desktop.
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