2016-06-12 14:46:59 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-test");
|
2016-11-22 20:49:40 +00:00
|
|
|
let shelljs = require('shelljs');
|
2016-11-21 18:34:59 +00:00
|
|
|
const path = require("path");
|
2016-11-22 20:49:40 +00:00
|
|
|
const should = require("should");
|
2016-11-21 18:34:59 +00:00
|
|
|
const smartgit = require("../dist/index");
|
|
|
|
let paths = {
|
2016-11-22 21:22:24 +00:00
|
|
|
temp1: path.resolve('./test/temp/'),
|
2016-11-22 20:49:40 +00:00
|
|
|
temp2: path.resolve('./test/temp2/'),
|
|
|
|
temp3: path.resolve('./test/temp3'),
|
|
|
|
temp4: path.resolve('./test/temp4'),
|
|
|
|
noGit: path.resolve('./test/')
|
2016-07-03 22:00:04 +00:00
|
|
|
};
|
2016-11-22 20:49:40 +00:00
|
|
|
describe('smartgit', function () {
|
|
|
|
let testGitRepo;
|
|
|
|
let testGitRepoCloned;
|
|
|
|
let testGitRepoInit;
|
|
|
|
describe('instance', function () {
|
2016-11-22 21:22:24 +00:00
|
|
|
it('should error for invalid path', function (done) {
|
|
|
|
try {
|
|
|
|
testGitRepo = new smartgit.GitRepo(paths.temp1);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
should(testGitRepo).not.be.instanceOf(smartgit.GitRepo);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
it('should init a new repo', function (done) {
|
|
|
|
this.timeout(40000);
|
|
|
|
smartgit.createRepoFromInit(paths.temp1)
|
|
|
|
.then((gitRepo) => {
|
|
|
|
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
|
|
|
done();
|
|
|
|
}).catch(err => {
|
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should create am instance for an existing repo', function () {
|
|
|
|
testGitRepo = new smartgit.GitRepo(paths.temp1);
|
2016-11-22 20:49:40 +00:00
|
|
|
should(testGitRepo).be.instanceOf(smartgit.GitRepo);
|
|
|
|
});
|
|
|
|
it('should clone a repository using ssh and sshkey', function (done) {
|
2016-07-04 01:49:24 +00:00
|
|
|
this.timeout(40000);
|
2016-11-22 21:22:24 +00:00
|
|
|
smartgit.createRepoFromClone('git@gitlab.com:sandboxzone/sandbox-testrepo.git', paths.temp2)
|
2016-11-22 20:49:40 +00:00
|
|
|
.then((gitRepo) => {
|
|
|
|
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
2016-03-30 23:59:45 +00:00
|
|
|
done();
|
2016-11-22 20:49:40 +00:00
|
|
|
}).catch(err => {
|
|
|
|
throw err;
|
2016-03-30 23:59:45 +00:00
|
|
|
});
|
|
|
|
});
|
2016-11-22 20:49:40 +00:00
|
|
|
it('should clone a repository using https', function (done) {
|
2016-07-04 01:49:24 +00:00
|
|
|
this.timeout(40000);
|
2016-11-22 21:22:24 +00:00
|
|
|
smartgit.createRepoFromClone('https://gitlab.com/sandboxzone/sandbox-testrepo.git', paths.temp3)
|
2016-11-22 20:49:40 +00:00
|
|
|
.then((gitRepo) => {
|
|
|
|
should(gitRepo).be.instanceOf(smartgit.GitRepo);
|
2016-06-12 14:46:59 +00:00
|
|
|
done();
|
2016-11-22 20:49:40 +00:00
|
|
|
}).catch(err => {
|
|
|
|
throw err;
|
2016-06-12 14:46:59 +00:00
|
|
|
});
|
|
|
|
});
|
2016-03-30 23:59:45 +00:00
|
|
|
});
|
2016-11-22 20:49:40 +00:00
|
|
|
describe('.add', function () {
|
|
|
|
it('should add a file to an existing repository', function () {
|
2016-11-22 21:22:24 +00:00
|
|
|
shelljs.exec(`(cd ${paths.temp1} && cp ../test.js .)`);
|
2016-12-31 22:17:03 +00:00
|
|
|
testGitRepo.addAll();
|
2016-11-22 21:22:24 +00:00
|
|
|
});
|
|
|
|
});
|
2016-12-31 22:17:03 +00:00
|
|
|
describe('.check()', function () {
|
2016-11-22 21:22:24 +00:00
|
|
|
it('should check a git repo', function () {
|
|
|
|
let checkResult = testGitRepo.check();
|
|
|
|
should(checkResult).be.true();
|
2016-07-03 22:00:04 +00:00
|
|
|
});
|
2016-03-30 23:59:45 +00:00
|
|
|
});
|
2016-11-22 20:49:40 +00:00
|
|
|
describe('commit', function () {
|
|
|
|
it('should commit a new file to an existing repository', function () {
|
|
|
|
testGitRepo.commit('added a new file');
|
2016-07-03 22:00:04 +00:00
|
|
|
});
|
2016-03-30 23:59:45 +00:00
|
|
|
});
|
2016-11-22 20:49:40 +00:00
|
|
|
describe('pull', function () {
|
2016-07-04 01:49:24 +00:00
|
|
|
this.timeout(40000);
|
2016-11-22 20:49:40 +00:00
|
|
|
it('should pull from origin', function (done) {
|
|
|
|
testGitRepo.pull()
|
|
|
|
.then(() => {
|
|
|
|
done();
|
|
|
|
});
|
2016-07-03 22:00:04 +00:00
|
|
|
});
|
2016-03-30 23:59:45 +00:00
|
|
|
});
|
2016-11-22 20:49:40 +00:00
|
|
|
describe('push', function () {
|
2016-07-05 01:47:38 +00:00
|
|
|
this.timeout(40000);
|
2016-11-22 20:49:40 +00:00
|
|
|
it('should push to origin', function (done) {
|
|
|
|
testGitRepo.push('origin', 'master')
|
|
|
|
.then(() => {
|
|
|
|
done();
|
|
|
|
});
|
2016-07-05 01:47:38 +00:00
|
|
|
});
|
|
|
|
});
|
2016-11-22 20:49:40 +00:00
|
|
|
describe('remote', function () {
|
|
|
|
it('should add a remote', function () {
|
|
|
|
testGitRepo.remoteAdd('origin2', 'https://github.com/pushrocks/somerepo');
|
2016-07-04 01:49:24 +00:00
|
|
|
});
|
2016-11-22 21:22:24 +00:00
|
|
|
it('should', function (done) {
|
|
|
|
testGitRepo.remoteList()
|
|
|
|
.then(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-07-04 01:49:24 +00:00
|
|
|
});
|
2016-03-30 23:59:45 +00:00
|
|
|
});
|
2016-12-31 22:17:03 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY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