Move --force tests from the package to the manager.

This commit is contained in:
André Cruz
2012-10-21 11:48:50 +01:00
parent f50520e04e
commit 8fe0abfc4b
3 changed files with 42 additions and 52 deletions

View File

@@ -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) {

View File

@@ -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();
});
});
});
});

View File

@@ -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();
});
});
});
});