123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- var expect = require('expect.js');
- var path = require('path');
- var rimraf = require('rimraf');
- var Logger = require('bower-logger');
- var Manager = require('../../lib/core/Manager');
- var defaultConfig = require('../../lib/config');
- describe('Manager', function () {
- var manager;
- var packagesCacheDir =
- path.join(__dirname, '../assets/temp-resolve-cache');
- var registryCacheDir =
- path.join(__dirname, '../assets/temp-registry-cache');
- after(function () {
- rimraf.sync(registryCacheDir);
- rimraf.sync(packagesCacheDir);
- });
- beforeEach(function (next) {
- var logger = new Logger();
- var config = defaultConfig({
- storage: {
- packages: packagesCacheDir,
- registry: registryCacheDir
- }
- });
- manager = new Manager(config, logger);
- next();
- });
- describe('_areCompatible', function () {
- describe('resolved is being fetched', function() {
- it('accepts endpoints with same targets', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: 'xxx' },
- { name: 'bar', target: 'xxx' }
- )).to.be(true);
- });
- it('rejects endpoints with different targets', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: 'xxx' },
- { name: 'bar', target: 'yyy' }
- )).to.be(false);
- });
- it('accepts with version and matching range', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '0.1.2' },
- { name: 'bar', target: '~0.1.0' }
- )).to.be(true);
- });
- it('rejects with version and non-matching range', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '0.1.2' },
- { name: 'bar', target: '~0.1.3' }
- )).to.be(false);
- });
- it('accepts with matching range and version', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '~0.1.0' },
- { name: 'bar', target: '0.1.2' }
- )).to.be(true);
- });
- it('accepts with non-matching range and version', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '~0.1.3' },
- { name: 'bar', target: '0.1.2' }
- )).to.be(false);
- });
- it('accepts with matching ranges', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '~0.1.0' },
- { name: 'bar', target: '~0.1.3' }
- )).to.be(true);
- });
- it('rejects with non-matching ranges', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '~0.1.0' },
- { name: 'bar', target: '~0.2.3' }
- )).to.be(false);
- });
- it('rejects with non-matching ranges', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '~0.1.0' },
- { name: 'bar', target: 'xxx' }
- )).to.be(false);
- });
- });
- describe('resolved is already fetched', function () {
- var resolved = {
- name: 'foo',
- target: '~1.2.1',
- pkgMeta: {
- version: '1.2.3'
- }
- };
- it('accepts if the same version as resolved', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '1.2.3' },
- resolved
- )).to.be(true);
- });
- it('rejects if different version than resolved', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '1.2.4' },
- resolved
- )).to.be(false);
- });
- it('accepts if range matches resolved version', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '~1.2.1' },
- resolved
- )).to.be(true);
- });
- it('rejects if range does not match', function () {
- expect(manager._areCompatible(
- { name: 'foo', target: '~1.2.4' },
- resolved
- )).to.be(false);
- });
- });
- });
- describe('_getCap', function () {
- it('finds highest bound', function () {
- var highest = manager._getCap(
- [['2.1.1-0', '<2.2.0-0'], '<3.2.0'],
- 'highest'
- );
- expect(highest).to.eql({
- version: '3.2.0',
- comparator: '<'
- });
- });
- it('finds lowest bound', function () {
- var highest = manager._getCap(
- [['2.1.1-0', '<2.2.0-0'], '<3.2.0'],
- 'lowest'
- );
- expect(highest).to.eql({
- version: '2.1.1-0',
- comparator: ''
- });
- });
- it('defaults to highest bound', function () {
- var highest = manager._getCap(
- ['1.0.0', '2.0.0']
- );
- expect(highest).to.eql({
- version: '2.0.0',
- comparator: ''
- });
- });
- it('ignores non-semver elements', function () {
- var highest = manager._getCap(
- ['0.9', '>1.0.1', ['<1.0.0', 'lol']]
- );
- expect(highest).to.eql({
- version: '1.0.1',
- comparator: '>'
- });
- });
- it('returns empty object if cap is not found', function () {
- var highest = manager._getCap(
- ['0.9'] // Not a semver
- );
- expect(highest).to.eql({});
- });
- });
- describe('_uniquify', function () {
- it('leaves last unique element', function () {
- var unique = manager._uniquify([
- { name: 'foo', id: 1 },
- { name: 'foo', id: 2 }
- ]);
- expect(unique).to.eql([
- { name: 'foo', id: 2 }
- ]);
- });
- it('compares by name first', function () {
- var unique = manager._uniquify([
- { name: 'foo', source: 'google.com' },
- { name: 'foo', source: 'facebook.com' }
- ]);
- expect(unique).to.eql([
- { name: 'foo', source: 'facebook.com' }
- ]);
- });
- it('compares by source if name is not available', function () {
- var unique = manager._uniquify([
- { source: 'facebook.com' },
- { source: 'facebook.com' }
- ]);
- expect(unique).to.eql([
- { source: 'facebook.com' }
- ]);
- });
- it('leaves different targets intact', function() {
- var unique = manager._uniquify([
- { source: 'facebook.com', target: 'a1b2c3' },
- { source: 'facebook.com', target: 'ffffff' }
- ]);
- expect(unique).to.eql([
- { source: 'facebook.com', target: 'a1b2c3' },
- { source: 'facebook.com', target: 'ffffff' }
- ]);
- });
- it('removes if same targets', function() {
- var unique = manager._uniquify([
- { source: 'facebook.com', target: 'ffffff' },
- { source: 'facebook.com', target: 'ffffff' }
- ]);
- expect(unique).to.eql([
- { source: 'facebook.com', target: 'ffffff' }
- ]);
- });
- it('ignores other fields', function() {
- var unique = manager._uniquify([
- { source: 'facebook.com', foo: 12 },
- { source: 'facebook.com', bar: 13 }
- ]);
- expect(unique).to.eql([
- { source: 'facebook.com', bar: 13 }
- ]);
- });
- });
- });
|