Skip to content

Commit 89bc6c7

Browse files
committed
Normalised quotes
1 parent fce8890 commit 89bc6c7

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

test/convenience-commit.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
var git = require( "../" );
2+
var rimraf = require("rimraf");
3+
var fs = require( "fs" );
4+
5+
// Helper functions
6+
var helper = {
7+
// Test if obj is a true function
8+
testFunction: function(test, obj, label) {
9+
// The object reports itself as a function
10+
test(typeof obj, "function", label + " reports as a function.");
11+
// This ensures the repo is actually a derivative of the Function [[Class]]
12+
test(toString.call(obj), "[object Function]", label + " [[Class]] is of type function.");
13+
},
14+
// Test code and handle exception thrown
15+
testException: function(test, fun, label) {
16+
try {
17+
fun();
18+
test(false, label);
19+
}
20+
catch (ex) {
21+
test(true, label);
22+
}
23+
}
24+
};
25+
26+
/**
27+
* Test that the commit object is present.
28+
*
29+
* @param {Object} test
30+
*/
31+
exports.method = function(test){
32+
test.expect(2);
33+
34+
helper.testFunction(test.equals, git.commit, "Commmit");
35+
36+
test.done();
37+
};
38+
39+
var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';
40+
41+
/**
42+
* Test that retreiving walking a given commit's history works as expected.
43+
*
44+
* @param {Object} test
45+
*/
46+
exports.history = function(test) {
47+
test.expect(2);
48+
git.repo('../.git', function(error, repository) {
49+
50+
repository.commit(historyCountKnownSHA, function(error, commit) {
51+
52+
test.equals(error, 0, 'Getting latest branch commit should not error');
53+
54+
var historyCount = 0;
55+
var expectedHistoryCount = 364;
56+
commit.history().on('commit', function(commit) {
57+
historyCount++;
58+
}).on('end', function(commits) {
59+
60+
test.equals(historyCount, expectedHistoryCount, 'History count does not match expected');
61+
62+
test.done();
63+
});
64+
});
65+
});
66+
};
67+
68+
/**
69+
* Test that retreiving master branch's HEAD commit works as expected.
70+
*
71+
* @param {Object} test
72+
*/
73+
exports.masterHead = function(test) {
74+
test.expect(2);
75+
git.repo('../.git', function(error, repository) {
76+
repository.branch('master', function(error, branch) {
77+
78+
test.equals(error, 0, 'Getting branch should not error');
79+
80+
repository.commit(branch.sha, function(error, commit) {
81+
82+
test.equals(error, 0, 'Getting latest branch commit should not error');
83+
84+
test.done();
85+
});
86+
});
87+
});
88+
};
89+
90+
/**
91+
* Test that retrieving and walking a commit's tree works as expected.
92+
*
93+
* @param {Object} test
94+
*/
95+
exports.tree = function(test) {
96+
test.expect(3);
97+
git.repo('../.git', function(error, repository) {
98+
99+
repository.commit(historyCountKnownSHA, function(error, commit) {
100+
101+
test.equals(error, 0, 'Getting latest branch commit should not error');
102+
103+
var commitTreeEntryCount = 0;
104+
var expectedCommitTreeEntryCount = 200;
105+
106+
commit.tree().walk().on('entry', function(commit) {
107+
commitTreeEntryCount++;
108+
}).on('end', function(commits) {
109+
110+
test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected');
111+
112+
test.done();
113+
});
114+
});
115+
});
116+
};

0 commit comments

Comments
 (0)