Skip to content

Commit

Permalink
added tests for redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel van Rijn committed Sep 14, 2012
1 parent b0270ab commit 0b82971
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -28,7 +28,8 @@
"test": "mocha -R spec -t 10000"
},
"devDependencies": {
"mocha": "latest"
"mocha": "latest",
"nock": "latest"
},
"bin": { "bower": "bin/bower" },
"preferGlobal": true
Expand Down
37 changes: 28 additions & 9 deletions test/package.js
@@ -1,8 +1,9 @@
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var Package = require('../lib/core/package');
var assert = require('assert'),
path = require('path'),
fs = require('fs'),
nock = require('nock'),
_ = require('lodash'),
Package = require('../lib/core/package');

describe('package', function () {
it('Should resolve git URLs properly', function () {
Expand Down Expand Up @@ -31,9 +32,27 @@ describe('package', function () {
assert.equal(pkg.gitUrl, 'git@github.com:twitter/flight.git');
});

it('Should resolve paths properly', function () {
var pkg = new Package('jquery', '~/jquery');
assert.equal(pkg.path, path.resolve('~/jquery'));
it('Should resolve url when we got redirected', function() {
var redirecting_url = 'http://redirecting-url.com',
redirecting_to_url = 'http://redirected-to-url.com';

var redirect_scope = nock(redirecting_url)
.defaultReplyHeaders({'location': redirecting_to_url + '/jquery.zip'})
.get('/jquery.zip')
.reply(302);

var redirect_to_scope = nock(redirecting_to_url)
.get('/jquery.zip')
.reply(200, "jquery content");

var pkg = new Package('jquery', redirecting_url + '/jquery.zip');

pkg.on('resolve', function () {
assert(pkg.assetUrl);
assert.equal(pkg.assetUrl, redirecting_to_url + '/jquery.zip');
});

pkg.download();
});

it('Should clone git packages', function (next) {
Expand Down Expand Up @@ -113,4 +132,4 @@ describe('package', function () {

pkg.resolve();
});
});
});

0 comments on commit 0b82971

Please sign in to comment.