Skip to content

Commit e19e8ea

Browse files
tbranyenJohn Haley
authored andcommitted
Added global afterEach, standardized repo attach
I ensured that every time we work with a repository it is attached under `test.repository`. This makes our `afterEach` much more consistent and concise. I changed the `free` code to only occur under Windows, where file locking is still a thing.
1 parent 796c09f commit e19e8ea

File tree

5 files changed

+38
-50
lines changed

5 files changed

+38
-50
lines changed

test/runner.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,18 @@ beforeEach(function() {
4545
return exec("git reset --hard", {cwd: workdirPath});
4646
});
4747
});
48+
49+
afterEach(function(done) {
50+
// In Windows if you do not clean up the repository, there may become a
51+
// conflict with file locking.
52+
if (this.repository && process.platform === "win32") {
53+
this.repository.stateCleanup();
54+
this.repository.free();
55+
delete this.repository;
56+
}
57+
58+
process.nextTick(function() {
59+
global.gc();
60+
done();
61+
});
62+
});

test/tests/branch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ describe("Branch", function() {
1616

1717
return Repository.open(reposPath)
1818
.then(function(repository) {
19-
test.repo = repository;
19+
test.repository = repository;
2020
});
2121
});
2222

2323
beforeEach(function() {
2424
var test = this;
25-
var repo = test.repo;
25+
var repo = test.repository;
2626

2727
return repo.getMasterCommit()
2828
.then(function(masterCommit) {
@@ -44,7 +44,7 @@ describe("Branch", function() {
4444
});
4545

4646
it("can delete a branch", function() {
47-
var repo = this.repo;
47+
var repo = this.repository;
4848

4949
Branch.delete(this.branch);
5050

@@ -54,7 +54,7 @@ describe("Branch", function() {
5454
});
5555

5656
it("can see if the branch is pointed to by head", function() {
57-
var repo = this.repo;
57+
var repo = this.repository;
5858

5959
return repo.getBranch("master")
6060
.then(function(branch) {

test/tests/checkout.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ describe("Checkout", function() {
1414

1515
return Repository.open(reposPath)
1616
.then(function(repo) {
17-
test.repo = repo;
17+
test.repository = repo;
1818
});
1919
});
2020

2121
it("can checkout the head", function() {
2222
var test = this;
2323

24-
return Checkout.head(test.repo)
24+
return Checkout.head(test.repository)
2525
.then(function() {
26-
return test.repo.getBlob(packageJsonOid);
26+
return test.repository.getBlob(packageJsonOid);
2727
})
2828
.then(function(blob) {
2929
var packageJson = blob.toString();
@@ -35,10 +35,10 @@ describe("Checkout", function() {
3535
it("can checkout by tree", function() {
3636
var test = this;
3737

38-
return test.repo.getTagByName("annotated-tag").then(function(tag) {
39-
return Checkout.tree(test.repo, test.tag);
38+
return test.repository.getTagByName("annotated-tag").then(function(tag) {
39+
return Checkout.tree(test.repository, test.tag);
4040
}).then(function() {
41-
return test.repo.getHeadCommit();
41+
return test.repository.getHeadCommit();
4242
}).then(function(commit) {
4343
assert.equal(commit, "32789a79e71fbc9e04d3eff7425e1771eb595150");
4444
});

test/tests/clone.js

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,10 @@ describe("Clone", function() {
1818
this.timeout(30000);
1919

2020
beforeEach(function() {
21-
if (this.clonePath) {
22-
return fse.remove(this.clonePath).catch(function(err) {
23-
console.log(err);
21+
return fse.remove(clonePath).catch(function(err) {
22+
console.log(err);
2423

25-
throw err;
26-
});
27-
}
28-
});
29-
30-
afterEach(function(done) {
31-
if (this.repository) {
32-
this.repository.stateCleanup();
33-
this.repository.free();
34-
delete this.repository;
35-
}
36-
37-
process.nextTick(function() {
38-
global.gc();
39-
done();
24+
throw err;
4025
});
4126
});
4227

@@ -51,9 +36,7 @@ describe("Clone", function() {
5136
}
5237
};
5338

54-
test.clonePath = local("../repos/http");
55-
56-
return Clone.clone(url, test.clonePath, opts).then(function(repo) {
39+
return Clone.clone(url, clonePath, opts).then(function(repo) {
5740
assert.ok(repo instanceof Repository);
5841
test.repository = repo;
5942
});
@@ -70,9 +53,7 @@ describe("Clone", function() {
7053
}
7154
};
7255

73-
test.clonePath = local("../repos/https");
74-
75-
return Clone.clone(url, test.clonePath, opts).then(function(repo) {
56+
return Clone.clone(url, clonePath, opts).then(function(repo) {
7657
assert.ok(repo instanceof Repository);
7758
test.repository = repo;
7859
});
@@ -92,9 +73,7 @@ describe("Clone", function() {
9273
}
9374
};
9475

95-
test.clonePath = local("../repos/ssh");
96-
97-
return Clone.clone(url, test.clonePath, opts).then(function(repo) {
76+
return Clone.clone(url, clonePath, opts).then(function(repo) {
9877
assert.ok(repo instanceof Repository);
9978
test.repository = repo;
10079
});
@@ -118,9 +97,7 @@ describe("Clone", function() {
11897
}
11998
};
12099

121-
test.clonePath = local("../repos/sshManual");
122-
123-
return Clone.clone(url, test.clonePath, opts).then(function(repo) {
100+
return Clone.clone(url, clonePath, opts).then(function(repo) {
124101
assert.ok(repo instanceof Repository);
125102
test.repository = repo;
126103
});
@@ -137,9 +114,7 @@ describe("Clone", function() {
137114
}
138115
};
139116

140-
test.clonePath = local("../repos/git");
141-
142-
return Clone.clone(url, test.clonePath, opts).then(function(repo) {
117+
return Clone.clone(url, clonePath, opts).then(function(repo) {
143118
test.repository = repo;
144119
assert.ok(repo instanceof Repository);
145120
});
@@ -150,9 +125,7 @@ describe("Clone", function() {
150125
var prefix = process.platform === "win32" ? "" : "file://";
151126
var url = prefix + local("../repos/empty");
152127

153-
test.clonePath = local("../repos/filesystem");
154-
155-
return Clone.clone(url, test.clonePath).then(function(repo) {
128+
return Clone.clone(url, clonePath).then(function(repo) {
156129
assert.ok(repo instanceof Repository);
157130
test.repository = repo;
158131
});

test/tests/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("Index", function() {
1919

2020
return Repository.open(reposPath)
2121
.then(function(repo) {
22-
test.repo = repo;
22+
test.repository = repo;
2323
return repo.openIndex();
2424
})
2525
.then(function(index) {
@@ -38,7 +38,7 @@ describe("Index", function() {
3838
});
3939

4040
it("can add all entries to the index", function() {
41-
var repo = this.repo;
41+
var repo = this.repository;
4242
var index = this.index;
4343
var fileContent = {
4444
newFile1: "this has some content",
@@ -72,7 +72,7 @@ describe("Index", function() {
7272
});
7373

7474
it("can remove entries from the index", function() {
75-
var repo = this.repo;
75+
var repo = this.repository;
7676
var index = this.index;
7777
var fileContent = {
7878
newFile1: "this has some content",
@@ -116,7 +116,7 @@ describe("Index", function() {
116116
});
117117

118118
it("can update entries in the index", function() {
119-
var repo = this.repo;
119+
var repo = this.repository;
120120
var index = this.index;
121121
var fileContent = {
122122
newFile1: "this has some content",

0 commit comments

Comments
 (0)