mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-01 18:24:28 +02:00
Add tests for currently supported log arguments
This commit is contained in:
parent
f178f6c118
commit
6e5d6a64e9
3 changed files with 69 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
|||
var Q = require('q');
|
||||
|
||||
var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
|
||||
var TreeCompare = require('../src/js/graph/treeCompare.js');
|
||||
|
||||
|
@ -95,6 +97,27 @@ var expectLevelSolved = function(levelBlob) {
|
|||
expectLevelAsync(headless, levelBlob);
|
||||
};
|
||||
|
||||
var runCommand = function(command, resultHandler) {
|
||||
var headless = new HeadlessGit();
|
||||
var deferred = Q.defer();
|
||||
var msg = null;
|
||||
|
||||
deferred.promise.then(function(commands) {
|
||||
msg = commands[commands.length - 1].get('error').get('msg');
|
||||
});
|
||||
|
||||
runs(function() {
|
||||
headless.sendCommand(command, deferred);
|
||||
});
|
||||
waitsFor(function() {
|
||||
if(null == msg) {
|
||||
return false;
|
||||
}
|
||||
resultHandler(msg);
|
||||
return true;
|
||||
}, 'commands should be finished', 500);
|
||||
};
|
||||
|
||||
var TIME = 150;
|
||||
// useful for throwing garbage and then expecting one commit
|
||||
var ONE_COMMIT_TREE = '{"branches":{"master":{"target":"C2","id":"master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}';
|
||||
|
@ -105,6 +128,7 @@ module.exports = {
|
|||
TIME: TIME,
|
||||
expectTreeAsync: expectTreeAsync,
|
||||
expectLevelSolved: expectLevelSolved,
|
||||
ONE_COMMIT_TREE: ONE_COMMIT_TREE
|
||||
ONE_COMMIT_TREE: ONE_COMMIT_TREE,
|
||||
runCommand: runCommand
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var base = require('./base');
|
||||
var expectTreeAsync = base.expectTreeAsync;
|
||||
var runCommand = base.runCommand;
|
||||
|
||||
describe('Git', function() {
|
||||
it('Commits', function() {
|
||||
|
@ -275,4 +276,43 @@ describe('Git', function() {
|
|||
);
|
||||
});
|
||||
|
||||
describe('Log supports', function() {
|
||||
var SETUP = 'git co -b left C0; gc; git merge master; git co -b right C0; gc; git merge master; git co -b all left; git merge right; ';
|
||||
|
||||
it('implied HEAD', function() {
|
||||
runCommand(SETUP + '; git co right; git log', function(commandMsg) {
|
||||
expect(commandMsg).toContain('Commit: C0\n');
|
||||
expect(commandMsg).toContain('Commit: C1\n');
|
||||
expect(commandMsg).not.toContain('Commit: C2\n');
|
||||
expect(commandMsg).not.toContain('Commit: C3\n');
|
||||
expect(commandMsg).toContain('Commit: C4\n');
|
||||
expect(commandMsg).toContain('Commit: C5\n');
|
||||
expect(commandMsg).not.toContain('Commit: C6\n');
|
||||
});
|
||||
});
|
||||
|
||||
it('single included revision', function() {
|
||||
runCommand(SETUP + 'git log right', function(commandMsg) {
|
||||
expect(commandMsg).toContain('Commit: C0\n');
|
||||
expect(commandMsg).toContain('Commit: C1\n');
|
||||
expect(commandMsg).not.toContain('Commit: C2\n');
|
||||
expect(commandMsg).not.toContain('Commit: C3\n');
|
||||
expect(commandMsg).toContain('Commit: C4\n');
|
||||
expect(commandMsg).toContain('Commit: C5\n');
|
||||
expect(commandMsg).not.toContain('Commit: C6\n');
|
||||
});
|
||||
});
|
||||
|
||||
it('single excluded revision', function() {
|
||||
runCommand(SETUP + 'git log all ^right', function(commandMsg) {
|
||||
expect(commandMsg).not.toContain('Commit: C0\n');
|
||||
expect(commandMsg).not.toContain('Commit: C1\n');
|
||||
expect(commandMsg).toContain('Commit: C2\n');
|
||||
expect(commandMsg).toContain('Commit: C3\n');
|
||||
expect(commandMsg).not.toContain('Commit: C4\n');
|
||||
expect(commandMsg).not.toContain('Commit: C5\n');
|
||||
expect(commandMsg).toContain('Commit: C6\n');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -109,6 +109,8 @@ HeadlessGit.prototype.sendCommand = function(value, entireCommandPromise) {
|
|||
var chain = deferred.promise;
|
||||
var startTime = new Date().getTime();
|
||||
|
||||
var commands = [];
|
||||
|
||||
util.splitTextCommand(value, function(commandStr) {
|
||||
chain = chain.then(function() {
|
||||
var commandObj = new Command({
|
||||
|
@ -117,6 +119,7 @@ HeadlessGit.prototype.sendCommand = function(value, entireCommandPromise) {
|
|||
|
||||
var thisDeferred = Q.defer();
|
||||
this.gitEngine.dispatch(commandObj, thisDeferred);
|
||||
commands.push(commandObj);
|
||||
return thisDeferred.promise;
|
||||
}.bind(this));
|
||||
}, this);
|
||||
|
@ -124,7 +127,7 @@ HeadlessGit.prototype.sendCommand = function(value, entireCommandPromise) {
|
|||
chain.then(function() {
|
||||
var nowTime = new Date().getTime();
|
||||
if (entireCommandPromise) {
|
||||
entireCommandPromise.resolve();
|
||||
entireCommandPromise.resolve(commands);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue