Last active
August 29, 2015 14:13
-
-
Save twolfson/c12a75a018ce0d1b2b12 to your computer and use it in GitHub Desktop.
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
data/ | |
node_modules/ |
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
// 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'); | |
}); | |
}); |
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
{ | |
"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