mirror of
https://github.com/bower/bower.git
synced 2026-01-15 01:08:07 -05:00
Move --force tests from the package to the manager.
This commit is contained in:
@@ -34,21 +34,12 @@ var readJSON = require('../util/read-json');
|
||||
var UnitWork = require('./unit_work');
|
||||
|
||||
var Package = function (name, endpoint, manager) {
|
||||
this.dependencies = {};
|
||||
this.json = {};
|
||||
this.name = name;
|
||||
|
||||
// The third argument can be a manager or an options object
|
||||
// If its a manager, the opts & unit of work are grabbed from it
|
||||
// We can't use the instanceof because of a circular reference between the two packages
|
||||
if (manager && manager.unitWork) {
|
||||
this.manager = manager;
|
||||
this.unitWork = manager.unitWork;
|
||||
this.opts = manager.opts;
|
||||
} else {
|
||||
this.unitWork = new UnitWork;
|
||||
this.opts = _.extend({ force: false }, manager);
|
||||
}
|
||||
this.dependencies = {};
|
||||
this.json = {};
|
||||
this.name = name;
|
||||
this.manager = manager;
|
||||
this.unitWork = manager ? manager.unitWork : new UnitWork;
|
||||
this.opts = manager ? manager.opts : {};
|
||||
|
||||
if (endpoint) {
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ describe('manager', function () {
|
||||
});
|
||||
|
||||
manager.resolve();
|
||||
|
||||
});
|
||||
|
||||
it('Should resolve nested JSON dependencies', function (next) {
|
||||
@@ -95,4 +94,40 @@ describe('manager', function () {
|
||||
manager.resolve();
|
||||
});
|
||||
|
||||
it('Should fetch remote sources if the force option is passed', function (next) {
|
||||
this.timeout(40000); // Increase the timeout because this one takes longer
|
||||
|
||||
function resolve() {
|
||||
var manager = new Manager([], { force: true });
|
||||
manager.cwd = __dirname + '/assets/project';
|
||||
|
||||
manager.on('error', function (err) {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
manager.resolve();
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
// We install the same package two times
|
||||
var pkg = resolve();
|
||||
var nrCached = 0;
|
||||
pkg.on('resolve', function () {
|
||||
// We got the cache filled in at this time
|
||||
// This project has only a shared dependency (jquery) so it will be erased the first time
|
||||
// but cached the second time
|
||||
pkg = resolve();
|
||||
|
||||
pkg.on('data', function (data) {
|
||||
if (/cached/.test(data)) nrCached++;
|
||||
});
|
||||
|
||||
pkg.on('resolve', function () {
|
||||
if (nrCached > 1) throw new Error('Cached versions are being used.');
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -234,40 +234,4 @@ describe('package', function () {
|
||||
pkg.clone();
|
||||
});
|
||||
|
||||
it('Should fetch remote source if the force option is passed', function (next) {
|
||||
function install() {
|
||||
var pkg = new Package('jquery', 'git://github.com/maccman/package-jquery.git', { force: true });
|
||||
|
||||
pkg.on('error', function (err) {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
pkg.on('resolve', function () {
|
||||
pkg.install();
|
||||
});
|
||||
|
||||
pkg.clone();
|
||||
|
||||
return pkg;
|
||||
}
|
||||
|
||||
// We install the same package two times
|
||||
// If there is a cached message, then throw an error..
|
||||
var pkg = install();
|
||||
var ok = true;
|
||||
|
||||
pkg.on('install', function () {
|
||||
pkg = install();
|
||||
|
||||
pkg.on('data', function (data) {
|
||||
if (/cached/.test(data)) ok = false;
|
||||
});
|
||||
|
||||
pkg.on('install', function () {
|
||||
if (!ok) throw new Error('Package is using a cached version.');
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user