Permalink
Browse files

added tests for redirection

  • Loading branch information...
1 parent b0270ab commit 0b8297138a8fb3f9644dc843441186e99a18b0c0 Manuel van Rijn committed Sep 14, 2012
Showing with 30 additions and 10 deletions.
  1. +2 −1 package.json
  2. +28 −9 test/package.js
View
@@ -28,7 +28,8 @@
"test": "mocha -R spec -t 10000"
},
"devDependencies": {
- "mocha": "latest"
+ "mocha": "latest",
+ "nock": "latest"
},
"bin": { "bower": "bin/bower" },
"preferGlobal": true
View
@@ -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 () {
@@ -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) {
@@ -113,4 +132,4 @@ describe('package', function () {
pkg.resolve();
});
-});
+});

0 comments on commit 0b82971

Please sign in to comment.