Skip to content

Commit

Permalink
Merge cdb9fbe into 2c9d847
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkc committed Jul 12, 2015
2 parents 2c9d847 + cdb9fbe commit 88054c2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -47,7 +47,7 @@
"request-progress": "0.3.1",
"retry": "0.6.1",
"rimraf": "^2.2.8",
"semver": "^2.3.0",
"semver": "^5.0.0",
"shell-quote": "^1.4.2",
"stringify-object": "^1.0.0",
"tar-fs": "^1.4.1",
Expand All @@ -73,6 +73,7 @@
"nock": "^0.56.0",
"node-uuid": "^1.4.2",
"proxyquire": "^1.3.0",
"semver": "^5.0.0",
"spawn-sync": "^1.0.5"
},
"scripts": {
Expand Down
32 changes: 31 additions & 1 deletion test/core/resolveCache.js
Expand Up @@ -513,7 +513,7 @@ describe('ResolveCache', function () {
fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.2'));
fs.writeFileSync(path.join(sourceDir, '0.1.0-rc.2', '.bower.json'), JSON.stringify(json, null, ' '));

resolveCache.retrieve(source, '~0.1.0')
resolveCache.retrieve(source, '~0.1.0 || ~0.1.0-rc.0')
.spread(function (canonicalDir, pkgMeta) {
expect(pkgMeta).to.be.an('object');
expect(pkgMeta.version).to.equal('0.1.0-rc.2');
Expand All @@ -524,6 +524,36 @@ describe('ResolveCache', function () {
.done();
});

it('should resolve to the highest package that matches an x-range target, ignoring pre-releases versions', function (next) {
var source = String(Math.random());
var sourceId = md5(source);
var sourceDir = path.join(cacheDir, sourceId);
var json = { name: 'foo' };

// Create some versions
fs.mkdirSync(sourceDir);

// fix #1817 : >=1.2.x <=1.4.x which resolved to 1.3.16

json.version = '1.3.16-rc.1';
fs.mkdirSync(path.join(sourceDir, json.version));
fs.writeFileSync(path.join(sourceDir, json.version, '.bower.json'), JSON.stringify(json, null, ' '));

json.version = '1.3.16';
fs.mkdirSync(path.join(sourceDir, json.version));
fs.writeFileSync(path.join(sourceDir, json.version, '.bower.json'), JSON.stringify(json, null, ' '));

resolveCache.retrieve(source, '>=1.2.x <=1.4.x')
.spread(function (canonicalDir, pkgMeta) {
expect(pkgMeta).to.be.an('object');
expect(pkgMeta.version).to.equal('1.3.16');
expect(canonicalDir).to.equal(path.join(sourceDir, '1.3.16'));

next();
})
.done();
});

it('should resolve to exact match (including build metadata) if available', function (next) {
var source = String(Math.random());
var sourceId = md5(source);
Expand Down
31 changes: 28 additions & 3 deletions test/core/resolvers/gitResolver.js
Expand Up @@ -506,7 +506,7 @@ describe('GitResolver', function () {
.done();
});

it('should resolve "*" to the latest version if a repository has valid semver tags, not ignoring pre-releases if they are the only versions', function (next) {
it('should fail to resolve "*" if a repository has valid semver tags, ignoring pre-releases if they are the only versions', function (next) {
var resolver;

GitResolver.refs = function () {
Expand All @@ -519,6 +519,31 @@ describe('GitResolver', function () {

resolver = create('foo');
resolver._findResolution('*')
.then(function () {
next(new Error('Should have failed'));
}, function (err) {
expect(err).to.be.an(Error);
expect(err.message).to.match(/no tag found that was able to satisfy/i);
expect(err.details).to.match(/0.1.0-rc/i);
expect(err.code).to.equal('ENORESTARGET');
next();
})
.done();
});

it('should resolve "* || >=0.1.0-rc.0" to the latest version if a repository has valid semver tags, not ignoring pre-releases if they are the only versions', function (next) {
var resolver;

GitResolver.refs = function () {
return Q.resolve([
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/master',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb refs/tags/0.1.0-rc.1',
'cccccccccccccccccccccccccccccccccccccccc refs/tags/0.1.0-rc.2'
]);
};

resolver = create('foo');
resolver._findResolution('* || >=0.1.0-rc.0')
.then(function (resolution) {
expect(resolution).to.eql({
type: 'version',
Expand All @@ -542,7 +567,7 @@ describe('GitResolver', function () {
};

resolver = create('foo');
resolver._findResolution('0.1.*')
resolver._findResolution('0.1.* || >=0.1.0-rc.1')
.then(function (resolution) {
expect(resolution).to.eql({
type: 'version',
Expand Down Expand Up @@ -642,7 +667,7 @@ describe('GitResolver', function () {
};

resolver = create('foo');
resolver._findResolution('~0.2.1')
resolver._findResolution('~0.2.1-rc.0')
.then(function (resolution) {
expect(resolution).to.eql({
type: 'version',
Expand Down
28 changes: 26 additions & 2 deletions test/core/resolvers/svnResolver.js
Expand Up @@ -362,7 +362,7 @@ else describe('SvnResolver', function () {
.done();
});

it('should resolve "*" to the latest version if a repository has valid semver tags, not ignoring pre-releases if they are the only versions', function (next) {
it('should fail to resolve "*" if a repository has valid semver tags, ignoring pre-releases if they are the only versions', function (next) {
var resolver;

SvnResolver.tags = function () {
Expand All @@ -374,6 +374,30 @@ else describe('SvnResolver', function () {

resolver = create('foo');
resolver._findResolution('*')
.then(function () {
next(new Error('Should have failed'));
}, function (err) {
expect(err).to.be.an(Error);
expect(err.message).to.match(/no tag found that was able to satisfy/i);
expect(err.details).to.match(/0.1.0-rc/i);
expect(err.code).to.equal('ENORESTARGET');
next();
})
.done();
});

it('should resolve "*" to the latest version if a repository has valid semver tags, not ignoring pre-releases if they are the only versions', function (next) {
var resolver;

SvnResolver.tags = function () {
return Q.resolve({
'0.1.0-rc.1': 1,
'0.1.0-rc.2': 2
});
};

resolver = create('foo');
resolver._findResolution('* || >=0.1.0-rc.0')
.then(function (resolution) {
expect(resolution).to.eql({
type: 'version',
Expand Down Expand Up @@ -445,7 +469,7 @@ else describe('SvnResolver', function () {
};

resolver = create('foo');
resolver._findResolution('~0.2.1')
resolver._findResolution('~0.2.1 || ~0.2.1-rc.0')
.then(function (resolution) {
expect(resolution).to.eql({
type: 'version',
Expand Down

0 comments on commit 88054c2

Please sign in to comment.