Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active August 29, 2015 13:57
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/9400511 to your computer and use it in GitHub Desktop.
Save twolfson/9400511 to your computer and use it in GitHub Desktop.
Example gist for eight-track

To get example working, run the following:

git clone https://gist.github.com/9400511.git gist-eight-track-example
cd gist-eight-track-example
npm install
npm test
{
"name": "gist-eight-track-example",
"version": "0.1.0",
"description": "Example gist for eight-track",
"scripts": {
"test": "mocha test.js"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/9400511.git"
},
"author": "Todd Wolfson <todd@twolfson.com>",
"license": "MIT",
"homepage": "https://gist.github.com/9400511",
"dependencies": {
"chai": "~1.9.0",
"eight-track": "~1.5.0",
"express": "~3.4.8",
"mocha": "~1.17.1",
"request": "~2.34.0"
},
"private": true
}
// Load in test dependencies
var eightTrack = require('eight-track');
var expect = require('chai').expect;
var express = require('express');
var request = require('request');
// Start tests
describe('A request to an external', function () {
// Create temporary eight-track server (forwards requests to uber.com)
before(function startEightTrackServer () {
this.eightTrackServer = express().use(eightTrack({
url: 'http://uber.com',
fixtureDir: 'data/eight-track/uber'
})).listen(1337);
});
after(function stopEightTrackServer (done) {
this.eightTrackServer.close(done);
});
// Make request to eight-track server (could be proxied to uber.com)
before(function makeRequestToUber (done) {
var that = this;
request('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('<title>Uber</title>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment