mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Add tests for the GitRemoveResolver.
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
describe('GitFsResolver', function () {
|
||||
describe('._resolveSelf', function () {
|
||||
it.skip('should call all the functions necessary to resolve by the correct order');
|
||||
before(function () {
|
||||
|
||||
});
|
||||
|
||||
describe('.resolve', function () {
|
||||
it.skip('should checkout correctly if resolution is a branch');
|
||||
it.skip('should checkout correctly if resolution is a tag');
|
||||
it.skip('should checkout correctly if resolution is a commit');
|
||||
it.skip('should remove any untracked files and directories');
|
||||
});
|
||||
|
||||
describe('._copy', function () {
|
||||
@@ -8,19 +15,12 @@ describe('GitFsResolver', function () {
|
||||
it.skip('should not copy over the files specified in the ignore list');
|
||||
});
|
||||
|
||||
describe('._checkout', function () {
|
||||
it.skip('should checkout correctly if resolution is a branch');
|
||||
it.skip('should checkout correctly if resolution is a tag');
|
||||
it.skip('should checkout correctly if resolution is a commit');
|
||||
it.skip('should remove any untracked files and directories');
|
||||
});
|
||||
|
||||
describe('#fetchRefs', function () {
|
||||
it('should resolve to the references of the local repository', function () {
|
||||
it.skip('should resolve to the references of the local repository', function () {
|
||||
|
||||
});
|
||||
|
||||
it('should cache the results', function () {
|
||||
it.skip('should cache the results', function () {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,163 @@
|
||||
var expect = require('expect.js');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var cmd = require('../../../lib/util/cmd');
|
||||
var GitRemoteResolver = require('../../../lib/resolve/resolvers/GitRemoteResolver');
|
||||
|
||||
describe('GitRemoteResolver', function () {
|
||||
describe('._checkout', function () {
|
||||
it.skip('should checkout correctly if resolution is a branch');
|
||||
it.skip('should checkout correctly if resolution is a tag');
|
||||
it.skip('should checkout correctly if resolution is a commit');
|
||||
var testPackage = path.resolve(__dirname, '../../assets/github-test-package');
|
||||
|
||||
function cleanInternalResolverCache() {
|
||||
delete GitRemoteResolver._versions;
|
||||
delete GitRemoteResolver._heads;
|
||||
delete GitRemoteResolver._refs;
|
||||
}
|
||||
|
||||
function fetchBranch(branch) {
|
||||
return cmd('git', ['checkout', '-b', branch, 'origin/' + branch], { cwd: testPackage })
|
||||
.then(null, function (err) {
|
||||
if (/already exists/i.test(err.details)) {
|
||||
return cmd('git', ['checkout', branch], { cwd: testPackage })
|
||||
.then(function () {
|
||||
return cmd('git', ['pull', 'origin', branch], { cwd: testPackage });
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
before(function (next) {
|
||||
// Ensure that our "fake" remote repository has all
|
||||
// the necessary branches being tracked
|
||||
return fetchBranch('some-branch')
|
||||
.then(next.bind(next, null))
|
||||
.done();
|
||||
});
|
||||
|
||||
describe('.constructor', function () {
|
||||
it('should guess the name from the path', function () {
|
||||
var resolver = new GitRemoteResolver('file://' + testPackage);
|
||||
|
||||
expect(resolver.getName()).to.equal('github-test-package');
|
||||
|
||||
resolver = new GitRemoteResolver('git://github.com/twitter/bower.git');
|
||||
expect(resolver.getName()).to.equal('bower');
|
||||
|
||||
resolver = new GitRemoteResolver('git://github.com/twitter/bower');
|
||||
expect(resolver.getName()).to.equal('bower');
|
||||
|
||||
resolver = new GitRemoteResolver('git://github.com');
|
||||
expect(resolver.getName()).to.equal('github.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.resolve', function () {
|
||||
it('should checkout correctly if resolution is a branch', function (next) {
|
||||
var resolver = new GitRemoteResolver('file://' + testPackage, { target: 'some-branch' });
|
||||
|
||||
resolver.resolve()
|
||||
.then(function (dir) {
|
||||
expect(dir).to.be.a('string');
|
||||
|
||||
var files = fs.readdirSync(dir),
|
||||
fooContents;
|
||||
|
||||
expect(files).to.contain('foo');
|
||||
expect(files).to.contain('baz');
|
||||
expect(files).to.contain('baz');
|
||||
|
||||
fooContents = fs.readFileSync(path.join(dir, 'foo')).toString();
|
||||
expect(fooContents).to.equal('foo foo');
|
||||
|
||||
next();
|
||||
})
|
||||
.done();
|
||||
});
|
||||
|
||||
it('should checkout correctly if resolution is a tag', function (next) {
|
||||
var resolver = new GitRemoteResolver('file://' + testPackage, { target: '~0.0.1' });
|
||||
|
||||
resolver.resolve()
|
||||
.then(function (dir) {
|
||||
expect(dir).to.be.a('string');
|
||||
|
||||
var files = fs.readdirSync(dir);
|
||||
|
||||
expect(files).to.contain('foo');
|
||||
expect(files).to.contain('bar');
|
||||
expect(files).to.not.contain('baz');
|
||||
|
||||
next();
|
||||
})
|
||||
.done();
|
||||
});
|
||||
|
||||
it('should checkout correctly if resolution is a commit', function (next) {
|
||||
var resolver = new GitRemoteResolver('file://' + testPackage, { target: '7339c38f5874129504b83650fbb2d850394573e9' });
|
||||
|
||||
resolver.resolve()
|
||||
.then(function (dir) {
|
||||
expect(dir).to.be.a('string');
|
||||
|
||||
var files = fs.readdirSync(dir);
|
||||
|
||||
expect(files).to.not.contain('foo');
|
||||
expect(files).to.not.contain('bar');
|
||||
expect(files).to.not.contain('baz');
|
||||
expect(files).to.contain('README.md');
|
||||
next();
|
||||
})
|
||||
.done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fetchRefs', function () {
|
||||
it('should resolve to the references of the remote repository', function () {
|
||||
afterEach(cleanInternalResolverCache);
|
||||
|
||||
it('should resolve to the references of the remote repository', function (next) {
|
||||
GitRemoteResolver.fetchRefs('file://' + testPackage)
|
||||
.then(function (refs) {
|
||||
expect(refs).to.eql([
|
||||
'b273e321ebc69381be2780668a22e28bec9e2b07\trefs/heads/master',
|
||||
'8b03dbbe20e0bc4f1fae2811ea0063121eb1b155\trefs/heads/some-branch',
|
||||
'122ac45fd22671a23cf77055a32d06d5a7baedd0\trefs/tags/0.0.1',
|
||||
'19b3a35cc7fded9a8a60d5b8fc0d18eb4940c476\trefs/tags/0.0.1^{}',
|
||||
'34dd75a11e686be862844996392e96e9457c7467\trefs/tags/0.0.2',
|
||||
'ddc6ea571c49c1ab8bb213fda18efdfe2bc8dd00\trefs/tags/0.0.2^{}',
|
||||
'92327598500f115d09ab14f16cde23718fc87658\trefs/tags/0.1.0',
|
||||
'b273e321ebc69381be2780668a22e28bec9e2b07\trefs/tags/0.1.0^{}'
|
||||
]);
|
||||
next();
|
||||
})
|
||||
.done();
|
||||
});
|
||||
|
||||
it('should cache the results', function () {
|
||||
it('should cache the results', function (next) {
|
||||
var source = 'file://' + testPackage;
|
||||
|
||||
GitRemoteResolver.fetchRefs(source)
|
||||
.then(function () {
|
||||
expect(GitRemoteResolver._refs).to.be.an('object');
|
||||
expect(GitRemoteResolver._refs[source]).to.be.an('array');
|
||||
|
||||
// Manipulate the cache and check if it resolves for the cached ones
|
||||
GitRemoteResolver._refs[source].splice(0, 1);
|
||||
|
||||
// Check if it resolver to the same array
|
||||
return GitRemoteResolver.fetchRefs('file://' + testPackage);
|
||||
})
|
||||
.then(function (refs) {
|
||||
expect(refs).to.eql([
|
||||
'8b03dbbe20e0bc4f1fae2811ea0063121eb1b155\trefs/heads/some-branch',
|
||||
'122ac45fd22671a23cf77055a32d06d5a7baedd0\trefs/tags/0.0.1',
|
||||
'19b3a35cc7fded9a8a60d5b8fc0d18eb4940c476\trefs/tags/0.0.1^{}',
|
||||
'34dd75a11e686be862844996392e96e9457c7467\trefs/tags/0.0.2',
|
||||
'ddc6ea571c49c1ab8bb213fda18efdfe2bc8dd00\trefs/tags/0.0.2^{}',
|
||||
'92327598500f115d09ab14f16cde23718fc87658\trefs/tags/0.1.0',
|
||||
'b273e321ebc69381be2780668a22e28bec9e2b07\trefs/tags/0.1.0^{}'
|
||||
]);
|
||||
next();
|
||||
})
|
||||
.done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -23,11 +23,11 @@ describe('GitResolver', function () {
|
||||
|
||||
describe('.hasNew', function () {
|
||||
beforeEach(function (next) {
|
||||
cleanInternalResolverCache();
|
||||
mkdirp(tempDir, next);
|
||||
});
|
||||
|
||||
afterEach(function (next) {
|
||||
cleanInternalResolverCache();
|
||||
rimraf(tempDir, next);
|
||||
});
|
||||
|
||||
@@ -252,7 +252,7 @@ describe('GitResolver', function () {
|
||||
});
|
||||
|
||||
describe('._resolveSelf', function () {
|
||||
beforeEach(cleanInternalResolverCache);
|
||||
afterEach(cleanInternalResolverCache);
|
||||
|
||||
it('should call the necessary functions by the correct order', function (next) {
|
||||
function DummyResolver() {
|
||||
@@ -360,7 +360,7 @@ describe('GitResolver', function () {
|
||||
});
|
||||
|
||||
describe('._findResolution', function () {
|
||||
beforeEach(cleanInternalResolverCache);
|
||||
afterEach(cleanInternalResolverCache);
|
||||
|
||||
it('should resolve to an object', function (next) {
|
||||
var resolver;
|
||||
@@ -654,7 +654,7 @@ describe('GitResolver', function () {
|
||||
it('should save the resolution to the .bower.json to be used later by .hasNew', function (next) {
|
||||
var resolver = new GitResolver('foo');
|
||||
|
||||
resolver._resolution = { type: 'tag', tag: '0.0.1' };
|
||||
resolver._resolution = { type: 'tag', version: '0.0.1', tag: '0.0.1' };
|
||||
resolver._tempDir = tempDir;
|
||||
|
||||
resolver._savePkgMeta({ name: 'foo', version: '0.0.1' })
|
||||
@@ -677,7 +677,7 @@ describe('GitResolver', function () {
|
||||
});
|
||||
|
||||
describe('#fetchHeads', function () {
|
||||
beforeEach(cleanInternalResolverCache);
|
||||
afterEach(cleanInternalResolverCache);
|
||||
|
||||
it('should resolve to an empty object if no heads are found', function (next) {
|
||||
GitResolver.fetchRefs = function () {
|
||||
@@ -777,7 +777,7 @@ describe('GitResolver', function () {
|
||||
});
|
||||
|
||||
describe('#fetchVersions', function () {
|
||||
beforeEach(cleanInternalResolverCache);
|
||||
afterEach(cleanInternalResolverCache);
|
||||
|
||||
it('should resolve to an empty array if no tags are found', function (next) {
|
||||
GitResolver.fetchRefs = function () {
|
||||
|
||||
Reference in New Issue
Block a user