Skip to content

Commit 60d41bb

Browse files
committed
cleanup tests
1 parent de9715e commit 60d41bb

21 files changed

Lines changed: 416 additions & 357 deletions

test/tests/attr.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ var path = require("path");
33
var local = path.join.bind(path, __dirname);
44

55
describe("Attr", function() {
6-
var reposPath = local("../repos/workdir/.git");
7-
86
var Repository = require(local("../../lib/repository"));
97
var Attr = require(local("../../lib/attr"));
108
var Status = require(local("../../lib/status"));
119

10+
var reposPath = local("../repos/workdir/.git");
11+
1212
before(function() {
1313
var test = this;
1414

15-
return Repository.open(reposPath).then(function(repository) {
16-
test.repository = repository;
17-
});
15+
return Repository.open(reposPath)
16+
.then(function(repository) {
17+
test.repository = repository;
18+
});
1819
});
1920

2021
it("can add a macro definition", function() {

test/tests/blob.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ var path = require("path");
33
var local = path.join.bind(path, __dirname);
44

55
describe("Blob", function() {
6-
var reposPath = local("../repos/workdir/.git");
7-
var oid = "111dd657329797f6165f52f5085f61ac976dcf04";
8-
96
var Oid = require(local("../../lib/oid"));
107
var Repository = require(local("../../lib/repository"));
118
var FileMode = require(local("../../lib/tree_entry")).FILEMODE;
129

10+
var reposPath = local("../repos/workdir/.git");
11+
var oid = "111dd657329797f6165f52f5085f61ac976dcf04";
12+
1313
before(function() {
1414
var test = this;
1515

16-
return Repository.open(reposPath).then(function(repository) {
17-
test.repository = repository;
16+
return Repository.open(reposPath)
17+
.then(function(repository) {
18+
test.repository = repository;
1819

19-
return repository.getBlob(oid).then(function(blob) {
20+
return repository.getBlob(oid);
21+
})
22+
.then(function(blob) {
2023
test.blob = blob;
2124
});
22-
});
2325
});
2426

2527
it("can provide content as a buffer", function() {
@@ -41,8 +43,9 @@ describe("Blob", function() {
4143

4244
it("can get a blob with an Oid object", function() {
4345
var oidObject = Oid.fromString(oid);
44-
this.repository.getBlob(oidObject).then(function(blob) {
45-
assert.equal(this.blob.id().toString(), oid);
46-
});
46+
return this.repository.getBlob(oidObject)
47+
.then(function(blob) {
48+
assert.equal(blob.id().toString(), oid);
49+
});
4750
});
4851
});

test/tests/branch.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
var assert = require("assert");
22
var path = require("path");
3+
var Promise = require("nodegit-promise");
34
var local = path.join.bind(path, __dirname);
45

56
describe("Branch", function() {
6-
var reposPath = local("../repos/workdir/.git");
7-
87
var Repository = require(local("../../lib/repository"));
98
var Branch = require(local("../../lib/branch"));
109
var branchName = "test-branch";
1110
var fullBranchName = "refs/heads/" + branchName;
1211

12+
var reposPath = local("../repos/workdir/.git");
13+
1314
before(function() {
1415
var test = this;
1516

16-
return Repository.open(reposPath).then(function(repository) {
17-
test.repo = repository;
18-
});
17+
return Repository.open(reposPath)
18+
.then(function(repository) {
19+
test.repo = repository;
20+
});
1921
});
2022

2123
beforeEach(function() {
2224
var test = this;
2325
var repo = test.repo;
2426

25-
return repo.getMasterCommit().then(function(masterCommit) {
26-
test.masterCommit = masterCommit;
27+
return repo.getMasterCommit()
28+
.then(function(masterCommit) {
29+
test.masterCommit = masterCommit;
2730

28-
return repo.createBranch(branchName, masterCommit, true)
31+
return repo.createBranch(branchName, masterCommit, true);
32+
})
2933
.then(function(branch) {
3034
test.branch = branch;
3135
});
32-
});
3336
});
3437

3538
it("can create a branch", function() {
@@ -45,20 +48,17 @@ describe("Branch", function() {
4548

4649
Branch.delete(this.branch);
4750

48-
return repo.getBranch(branchName).then(function() {
49-
// branch wasn't deleted
50-
assert.ok(false);
51-
}, function() {
52-
// branch was deleted!
53-
assert.ok(true);
54-
});
51+
return repo.getBranch(branchName)
52+
// Reverse the results, since if we found it it wasn't deleted
53+
.then(Promise.reject, Promise.resolve);
5554
});
5655

5756
it("can see if the branch is pointed to by head", function() {
5857
var repo = this.repo;
5958

60-
return repo.getBranch("master").then(function(branch) {
61-
assert.ok(branch.isHead());
62-
});
59+
return repo.getBranch("master")
60+
.then(function(branch) {
61+
assert.ok(branch.isHead());
62+
});
6363
});
6464
});

test/tests/checkout.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@ var path = require("path");
33
var local = path.join.bind(path, __dirname);
44

55
describe("Checkout", function() {
6-
var packageJsonOid = "0fa56e90e096a4c24c785206b826ab914ea3de1e";
7-
var reposPath = local("../repos/workdir/.git");
8-
96
var Repository = require(local("../../lib/repository"));
107
var Checkout = require(local("../../lib/checkout"));
118

9+
var packageJsonOid = "0fa56e90e096a4c24c785206b826ab914ea3de1e";
10+
var reposPath = local("../repos/workdir/.git");
11+
1212
before(function() {
1313
var test = this;
1414

15-
return Repository.open(reposPath).then(function(repo) {
16-
test.repo = repo;
17-
});
15+
return Repository.open(reposPath)
16+
.then(function(repo) {
17+
test.repo = repo;
18+
});
1819
});
1920

2021
it("can checkout the head", function() {
21-
var repo = this.repo;
22+
var test = this;
2223

23-
return Checkout.head(repo)
24+
return Checkout.head(test.repo)
2425
.then(function() {
25-
return repo.getBlob(packageJsonOid);
26+
return test.repo.getBlob(packageJsonOid);
2627
})
2728
.then(function(blob) {
2829
var packageJson = blob.toString();

test/tests/clone.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ var fse = promisify(require("fs-extra"));
55
var local = path.join.bind(path, __dirname);
66

77
describe("Clone", function() {
8+
var Repository = require(local("../../lib/repository"));
9+
var Clone = require(local("../../lib/clone"));
10+
var NodeGit = require(local("../../"));
11+
812
var http = local("../repos/http");
913
var https = local("../repos/https");
1014
var ssh = local("../repos/ssh");
@@ -15,10 +19,6 @@ describe("Clone", function() {
1519
var sshPublicKey = local("../id_rsa.pub");
1620
var sshPrivateKey = local("../id_rsa");
1721

18-
var Repository = require(local("../../lib/repository"));
19-
var Clone = require(local("../../lib/clone"));
20-
var NodeGit = require(local("../../"));
21-
2222
// Set a reasonable timeout here now that our repository has grown.
2323
this.timeout(15000);
2424

test/tests/commit.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ var promisify = require("promisify-node");
55
var fse = promisify(require("fs-extra"));
66
var local = path.join.bind(path, __dirname);
77

8-
var NodeGit = require(local("../../"));
9-
var Repository = NodeGit.Repository;
10-
118
describe("Commit", function() {
9+
var NodeGit = require(local("../../"));
10+
var Repository = NodeGit.Repository;
11+
1212
var reposPath = local("../repos/workdir/.git");
1313
var oid = "fce88902e66c72b5b93e75bdb5ae717038b221f6";
1414

@@ -137,41 +137,7 @@ describe("Commit", function() {
137137
});
138138
});
139139

140-
describe("author", function() {
141-
before(function() {
142-
this.author = this.commit.author();
143-
});
144-
145-
it("is available", function() {
146-
assert.ok(this.author instanceof NodeGit.Signature);
147-
});
148-
149-
it("has a name", function() {
150-
assert.equal(this.author.name(), "Michael Robinson");
151-
});
152-
153-
it("has an email", function() {
154-
assert.equal(this.author.email(), "mike@panmedia.co.nz");
155-
});
156-
});
157-
158-
describe("committer", function() {
159-
before(function() {
160-
this.committer = this.commit.committer();
161-
});
162-
163-
it("is available", function() {
164-
assert.ok(this.committer instanceof NodeGit.Signature);
165-
});
166140

167-
it("has a name", function() {
168-
assert.equal(this.committer.name(), "Michael Robinson");
169-
});
170-
171-
it("has an email", function() {
172-
assert.equal(this.committer.email(), "mike@panmedia.co.nz");
173-
});
174-
});
175141

176142
it("has an owner", function() {
177143
var owner = this.commit.owner();
@@ -210,7 +176,7 @@ describe("Commit", function() {
210176
});
211177
});
212178

213-
it("can fetch all its parents", function() {
179+
it("can fetch all of its parents", function() {
214180
return this.commit.getParents().then(function(parents) {
215181
assert.equal(parents.length, 1);
216182

@@ -285,4 +251,40 @@ describe("Commit", function() {
285251
assert.equal(diff.length, 1);
286252
});
287253
});
254+
255+
describe("Commit's Author", function() {
256+
before(function() {
257+
this.author = this.commit.author();
258+
});
259+
260+
it("is available", function() {
261+
assert.ok(this.author instanceof NodeGit.Signature);
262+
});
263+
264+
it("has a name", function() {
265+
assert.equal(this.author.name(), "Michael Robinson");
266+
});
267+
268+
it("has an email", function() {
269+
assert.equal(this.author.email(), "mike@panmedia.co.nz");
270+
});
271+
});
272+
273+
describe("Commit's Committer", function() {
274+
before(function() {
275+
this.committer = this.commit.committer();
276+
});
277+
278+
it("is available", function() {
279+
assert.ok(this.committer instanceof NodeGit.Signature);
280+
});
281+
282+
it("has a name", function() {
283+
assert.equal(this.committer.name(), "Michael Robinson");
284+
});
285+
286+
it("has an email", function() {
287+
assert.equal(this.committer.email(), "mike@panmedia.co.nz");
288+
});
289+
});
288290
});

test/tests/cred.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ var local = path.join.bind(path, __dirname);
44

55
describe("Cred", function() {
66
var NodeGit = require(local("../../"));
7+
78
var sshPublicKey = local("../id_rsa.pub");
89
var sshPrivateKey = local("../id_rsa");
910

1011
it("can create default credentials", function() {
1112
var defaultCreds = NodeGit.Cred.defaultNew();
12-
assert(defaultCreds instanceof NodeGit.Cred);
13+
assert.ok(defaultCreds instanceof NodeGit.Cred);
1314
});
1415

1516
it("can create ssh credentials using passed keys", function() {
@@ -19,12 +20,12 @@ describe("Cred", function() {
1920
sshPrivateKey,
2021
"");
2122

22-
assert(cred instanceof NodeGit.Cred);
23+
assert.ok(cred instanceof NodeGit.Cred);
2324
});
2425

2526
it("can create credentials using plaintext", function() {
2627
var plaintextCreds = NodeGit.Cred.userpassPlaintextNew
2728
("username", "password");
28-
assert(plaintextCreds instanceof NodeGit.Cred);
29+
assert.ok(plaintextCreds instanceof NodeGit.Cred);
2930
});
3031
});

test/tests/diff.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,21 @@ describe("Diff", function() {
112112
it("can diff with a null tree", function() {
113113
var repo = this.repository;
114114
var tree = this.masterCommitTree;
115-
return Diff.treeToTree(repo, null, tree, null).then(function(diff) {
116-
assert.equal(diff.patches().length, 85);
117-
});
115+
return Diff.treeToTree(repo, null, tree, null)
116+
.then(function(diff) {
117+
assert.equal(diff.patches().length, 85);
118+
});
118119
});
119120

120121
it("can diff the initial commit of a repository", function() {
121122
var repo = this.repository;
122123
var oid = "99c88fd2ac9c5e385bd1fe119d89c83dce326219"; // First commit
123-
return repo.getCommit(oid).then(function(commit) {
124-
return commit.getDiff().then(function(diffs) {
124+
return repo.getCommit(oid)
125+
.then(function(commit) {
126+
return commit.getDiff();
127+
})
128+
.then(function(diffs) {
125129
assert.equal(diffs[0].patches().length, 8);
126130
});
127-
});
128131
});
129132
});

test/tests/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ var path = require("path");
33
var local = path.join.bind(path, __dirname);
44

55
describe("Index", function() {
6-
var reposPath = local("../repos/workdir/.git");
7-
86
var Repository = require(local("../../lib/repository"));
97

8+
var reposPath = local("../repos/workdir/.git");
9+
1010
before(function() {
1111
var test = this;
1212

0 commit comments

Comments
 (0)