mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Add more tests/improve existent ones.
This commit is contained in:
@@ -4,6 +4,7 @@ var path = require('path');
|
||||
var mout = require('mout');
|
||||
var Q = require('q');
|
||||
var rimraf = require('rimraf');
|
||||
var config = require('../../lib/config');
|
||||
var resolverFactory = require('../../lib/resolve/resolverFactory');
|
||||
var FsResolver = require('../../lib/resolve/resolvers/FsResolver');
|
||||
var GitFsResolver = require('../../lib/resolve/resolvers/GitFsResolver');
|
||||
@@ -27,72 +28,87 @@ describe('resolverFactory', function () {
|
||||
endpoints;
|
||||
|
||||
endpoints = {
|
||||
'git://github.com/user/project.git': {
|
||||
source: 'git://github.com/user/project.git',
|
||||
target: '*'
|
||||
},
|
||||
'git://github.com/user/project.git#commit-ish': {
|
||||
source: 'git://github.com/user/project.git',
|
||||
target: 'commit-ish'
|
||||
},
|
||||
'git+ssh://user@hostname:project.git': {
|
||||
source: 'ssh://user@hostname:project.git',
|
||||
target: '*'
|
||||
},
|
||||
'git+ssh://user@hostname:project.git#commit-ish': {
|
||||
source: 'ssh://user@hostname:project.git',
|
||||
target: 'commit-ish'
|
||||
},
|
||||
'git+ssh://user@hostname/project.git': {
|
||||
source: 'ssh://user@hostname/project.git',
|
||||
target: '*'
|
||||
},
|
||||
'git+ssh://user@hostname/project.git#commit-ish': {
|
||||
source: 'ssh://user@hostname/project.git',
|
||||
target: 'commit-ish'
|
||||
},
|
||||
'user@hostname:project.git': {
|
||||
source: 'user@hostname:project.git',
|
||||
target: '*'
|
||||
},
|
||||
'user@hostname:project.git#commit-ish': {
|
||||
source: 'user@hostname:project.git',
|
||||
target: 'commit-ish'
|
||||
},
|
||||
'git+http://user@hostname/project/blah.git': {
|
||||
source: 'http://user@hostname/project/blah.git',
|
||||
target: '*'
|
||||
},
|
||||
'git+http://user@hostname/project/blah.git#commit-ish': {
|
||||
source: 'http://user@hostname/project/blah.git',
|
||||
target: 'commit-ish'
|
||||
},
|
||||
'git+https://user@hostname/project/blah.git': {
|
||||
source: 'https://user@hostname/project/blah.git',
|
||||
target: '*'
|
||||
},
|
||||
'git+https://user@hostname/project/blah.git#commit-ish': {
|
||||
source: 'https://user@hostname/project/blah.git',
|
||||
target: 'commit-ish'
|
||||
},
|
||||
'bower/bower': {
|
||||
source: 'git://github.com/bower/bower.git',
|
||||
target: '*'
|
||||
},
|
||||
'bower/bower#commit-ish': {
|
||||
source: 'git://github.com/bower/bower.git',
|
||||
target: 'commit-ish'
|
||||
},
|
||||
// git:
|
||||
'git://github.com/user/project.git': 'git://github.com/user/project.git',
|
||||
'git://github.com/user/project.git/': 'git://github.com/user/project.git',
|
||||
|
||||
// git+ssh:
|
||||
'git+ssh://user@hostname:project': 'ssh://user@hostname:project.git',
|
||||
'git+ssh://user@hostname:project/': 'ssh://user@hostname:project.git',
|
||||
'git+ssh://user@hostname:project.git': 'ssh://user@hostname:project.git',
|
||||
'git+ssh://user@hostname:project.git/': 'ssh://user@hostname:project.git',
|
||||
'git+ssh://user@hostname/project': 'ssh://user@hostname/project.git',
|
||||
'git+ssh://user@hostname/project/': 'ssh://user@hostname/project.git',
|
||||
'git+ssh://user@hostname/project.git': 'ssh://user@hostname/project.git',
|
||||
'git+ssh://user@hostname/project.git/': 'ssh://user@hostname/project.git',
|
||||
|
||||
// git+http
|
||||
'git+http://user@hostname/project/blah': 'http://user@hostname/project/blah.git',
|
||||
'git+http://user@hostname/project/blah/': 'http://user@hostname/project/blah.git',
|
||||
'git+http://user@hostname/project/blah.git': 'http://user@hostname/project/blah.git',
|
||||
'git+http://user@hostname/project/blah.git/': 'http://user@hostname/project/blah.git',
|
||||
|
||||
// git+https
|
||||
'git+https://user@hostname/project/blah': 'https://user@hostname/project/blah.git',
|
||||
'git+https://user@hostname/project/blah/': 'https://user@hostname/project/blah.git',
|
||||
'git+https://user@hostname/project/blah.git': 'https://user@hostname/project/blah.git',
|
||||
'git+https://user@hostname/project/blah.git/': 'https://user@hostname/project/blah.git',
|
||||
|
||||
// ssh .git$
|
||||
'ssh://user@hostname:project.git': 'ssh://user@hostname:project.git',
|
||||
'ssh://user@hostname:project.git/': 'ssh://user@hostname:project.git',
|
||||
'ssh://user@hostname/project.git': 'ssh://user@hostname/project.git',
|
||||
'ssh://user@hostname/project.git/': 'ssh://user@hostname/project.git',
|
||||
|
||||
// http .git&
|
||||
'http://user@hostname/project.git': 'http://user@hostname/project.git',
|
||||
'http://user@hostname/project.git/': 'http://user@hostname/project.git',
|
||||
|
||||
// https
|
||||
'https://user@hostname/project.git': 'https://user@hostname/project.git',
|
||||
'https://user@hostname/project.git/': 'https://user@hostname/project.git',
|
||||
|
||||
// shorthand
|
||||
'bower/bower': 'git://github.com/bower/bower.git'
|
||||
};
|
||||
|
||||
mout.object.forOwn(endpoints, function (value, key) {
|
||||
// Test without name and target
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory(key);
|
||||
return resolverFactory({
|
||||
source: key
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(GitRemoteResolver);
|
||||
expect(resolver.getSource()).to.equal(value.source);
|
||||
expect(resolver.getTarget()).to.equal(value.target);
|
||||
expect(resolver.getSource()).to.equal(value);
|
||||
expect(resolver.getTarget()).to.equal('*');
|
||||
});
|
||||
|
||||
// Test with target
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory({
|
||||
source: key,
|
||||
target: 'commit-ish'
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(GitRemoteResolver);
|
||||
expect(resolver.getSource()).to.equal(value);
|
||||
expect(resolver.getTarget()).to.equal('commit-ish');
|
||||
});
|
||||
|
||||
// Test with name
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory({
|
||||
name: 'foo',
|
||||
source: key
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(GitRemoteResolver);
|
||||
expect(resolver.getSource()).to.equal(value);
|
||||
expect(resolver.getName()).to.equal('foo');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,20 +119,40 @@ describe('resolverFactory', function () {
|
||||
|
||||
it('should recognize local fs git endpoints correctly', function (next) {
|
||||
var promise = Q.resolve(),
|
||||
endpoints;
|
||||
endpoints,
|
||||
tmp;
|
||||
|
||||
endpoints = [
|
||||
path.resolve(__dirname, '../assets/github-test-package'),
|
||||
__dirname + '/../assets/github-test-package'
|
||||
];
|
||||
endpoints = {};
|
||||
|
||||
endpoints.forEach(function (source) {
|
||||
// Absolute path
|
||||
tmp = path.resolve(__dirname, '../assets/github-test-package');
|
||||
endpoints[tmp] = tmp;
|
||||
|
||||
// Relative path
|
||||
endpoints[__dirname + '/../assets/github-test-package'] = tmp;
|
||||
|
||||
mout.object.forOwn(endpoints, function (value, key) {
|
||||
// Test without name
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory(source);
|
||||
return resolverFactory({
|
||||
source: key
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(GitFsResolver);
|
||||
});
|
||||
|
||||
// Test with name
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory({
|
||||
name: 'foo',
|
||||
source: key
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(GitFsResolver);
|
||||
expect(resolver.getName()).to.equal('foo');
|
||||
});
|
||||
});
|
||||
|
||||
promise
|
||||
@@ -130,28 +166,67 @@ describe('resolverFactory', function () {
|
||||
fs.writeFileSync(path.join(tempSource, '.git'), 'foo');
|
||||
|
||||
var promise = Q.resolve(),
|
||||
endpoints;
|
||||
endpoints,
|
||||
tmp;
|
||||
|
||||
endpoints = [
|
||||
tempSource, // folder with .git file (not folder!)
|
||||
path.resolve(__dirname, '../assets/test-temp-dir'), // folder
|
||||
path.resolve(__dirname, '../assets/package-zip.zip'), // file
|
||||
];
|
||||
endpoints = {};
|
||||
|
||||
endpoints.forEach(function (source) {
|
||||
// Absolute path to folder with .git file
|
||||
endpoints[tempSource] = tempSource;
|
||||
// Relative path to folder with .git file
|
||||
endpoints[__dirname + '/../assets/tmp'] = tempSource;
|
||||
|
||||
// Absolute path to folder
|
||||
tmp = path.resolve(__dirname, '../assets/test-temp-dir');
|
||||
endpoints[tmp] = tmp;
|
||||
// Relative path to folder
|
||||
endpoints[__dirname + '/../assets/test-temp-dir'] = tmp;
|
||||
|
||||
// Absolute path to file
|
||||
tmp = path.resolve(__dirname, '../assets/package-zip.zip');
|
||||
endpoints[tmp] = tmp;
|
||||
// Relative path to file
|
||||
endpoints[__dirname + '/../assets/package-zip.zip'] = tmp;
|
||||
|
||||
// Relative with just one slash, to test fs resolution
|
||||
// priority against shorthands
|
||||
endpoints['test/assets'] = path.resolve(process.cwd() + '/test/assets');
|
||||
|
||||
mout.object.forOwn(endpoints, function (value, key) {
|
||||
// Test without name
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory(source);
|
||||
return resolverFactory({
|
||||
source: key
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(FsResolver);
|
||||
});
|
||||
|
||||
// Test with name
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory({
|
||||
name: 'foo',
|
||||
source: key
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(FsResolver);
|
||||
expect(resolver.getName()).to.equal('foo');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
promise
|
||||
.then(next.bind(next, null))
|
||||
.done();
|
||||
});
|
||||
|
||||
it.skip('should use config.cwd when resolving relative paths', function () {
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('should recognize URL endpoints correctly', function (next) {
|
||||
var promise = Q.resolve(),
|
||||
endpoints;
|
||||
@@ -162,8 +237,22 @@ describe('resolverFactory', function () {
|
||||
];
|
||||
|
||||
endpoints.forEach(function (source) {
|
||||
// Test without name
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory(source);
|
||||
return resolverFactory({
|
||||
source: source
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(UrlResolver);
|
||||
});
|
||||
|
||||
// Test with name
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory({
|
||||
name: 'foo',
|
||||
source: source
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver).to.be.a(UrlResolver);
|
||||
@@ -178,14 +267,18 @@ describe('resolverFactory', function () {
|
||||
it.skip('should recognize registry endpoints correctly');
|
||||
|
||||
it('should use the configured shorthand resolver', function (next) {
|
||||
resolverFactory('bower/bower')
|
||||
resolverFactory({
|
||||
source: 'bower/bower'
|
||||
})
|
||||
.then(function (resolver) {
|
||||
expect(resolver.getSource()).to.equal('git://github.com/bower/bower.git');
|
||||
|
||||
return resolverFactory('IndigoUnited/promptly', {
|
||||
config: {
|
||||
return resolverFactory({
|
||||
source: 'IndigoUnited/promptly'
|
||||
}, {
|
||||
config: mout.object.fillIn({
|
||||
shorthandResolver: 'git://bower.io/{{owner}}/{{package}}/{{shorthand}}'
|
||||
}
|
||||
}, config)
|
||||
});
|
||||
})
|
||||
.then(function (resolver) {
|
||||
@@ -194,4 +287,34 @@ describe('resolverFactory', function () {
|
||||
})
|
||||
.done();
|
||||
});
|
||||
|
||||
it('should not swallow constructor errors when instantiating resolvers', function (next) {
|
||||
var promise = Q.resolve(),
|
||||
endpoints;
|
||||
|
||||
endpoints = [
|
||||
'http://bower.io/foo.js',
|
||||
path.resolve(__dirname, '../assets/test-temp-dir')
|
||||
];
|
||||
|
||||
endpoints.forEach(function (source) {
|
||||
promise = promise.then(function () {
|
||||
return resolverFactory({
|
||||
source: source,
|
||||
target: 'bleh'
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
throw new Error('Should have failed');
|
||||
}, function (err) {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.message).to.match(/can't resolve targets/i);
|
||||
expect(err.code).to.equal('ENORESTARGET');
|
||||
});
|
||||
});
|
||||
|
||||
promise
|
||||
.then(next.bind(next, null))
|
||||
.done();
|
||||
});
|
||||
});
|
||||
@@ -45,6 +45,9 @@ describe('FsResolver', function () {
|
||||
expect(resolver.getSource()).to.equal(testPackage);
|
||||
});
|
||||
|
||||
it.skip('should use config.cwd for resolving relative paths', function () {
|
||||
});
|
||||
|
||||
it('should error out if a target was specified', function (next) {
|
||||
var resolver;
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@ describe('GitFsResolver', function () {
|
||||
resolver = new GitFsResolver(testPackage + '/something/..');
|
||||
expect(resolver.getSource()).to.equal(testPackage);
|
||||
});
|
||||
|
||||
it.skip('should use config.cwd for resolving relative paths', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.resolve', function () {
|
||||
|
||||
@@ -37,6 +37,9 @@ describe('GitRemoteResolver', function () {
|
||||
resolver = new GitRemoteResolver('git://github.com/twitter/bower.git');
|
||||
expect(resolver.getSource()).to.equal('git://github.com/twitter/bower.git');
|
||||
|
||||
resolver = new GitRemoteResolver('git://github.com/twitter/bower.git/');
|
||||
expect(resolver.getSource()).to.equal('git://github.com/twitter/bower.git');
|
||||
|
||||
resolver = new GitRemoteResolver('file://' + testPackage);
|
||||
expect(resolver.getSource()).to.equal('file://' + testPackage);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user