Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit 27477b5

Browse files
committed
use temp directory in tests
1 parent 7da3c17 commit 27477b5

19 files changed

+243
-216
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.DS_Store
22
npm-debug.log
33
node_modules
4-
spec/git-root
54
debug.log

package-lock.json

+26-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
}
2727
},
2828
"devDependencies": {
29-
"atom-jasmine2-test-runner": "^1.0.0"
29+
"atom-jasmine2-test-runner": "^1.0.0",
30+
"temp": "^0.8.3"
3031
}
3132
}

spec/commands/commit-all-spec.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ describe("commit-all", function () {
88

99
beforeEach(async function () {
1010
await atom.packages.activatePackage("context-git");
11-
createGitRoot();
12-
this.gitRoot = getFilePath();
13-
atom.project.setPaths([this.gitRoot]);
11+
this.gitRoot = await createGitRoot();
1412

15-
this.filePaths = getFilePath([files.t1]);
13+
this.filePaths = getFilePath(this.gitRoot, [files.t1]);
1614
});
1715

18-
afterEach(function () {
19-
removeGitRoot();
16+
afterEach(async function () {
17+
await removeGitRoot(this.gitRoot);
2018
});
2119

2220
it("should call commit with project folders", async function () {

spec/commands/commit-spec.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ describe("commit", function () {
99

1010
beforeEach(async function () {
1111
await atom.packages.activatePackage("context-git");
12-
createGitRoot();
13-
this.gitRoot = getFilePath();
14-
atom.project.setPaths([this.gitRoot]);
12+
this.gitRoot = await createGitRoot();
13+
1514
this.repo = await atom.project.repositoryForDirectory(new Directory(this.gitRoot));
1615

1716
this.statuses = [fileStatus("M ", files.t1), fileStatus("M ", files.t2)];
18-
this.filePaths = getFilePath([files.t1]);
17+
this.filePaths = getFilePath(this.gitRoot, [files.t1]);
1918
this.git = mockGit({
2019
rootDir: Promise.resolve(this.gitRoot),
2120
lastCommit: Promise.resolve("last commit"),
@@ -38,8 +37,8 @@ describe("commit", function () {
3837
});
3938
});
4039

41-
afterEach(function () {
42-
removeGitRoot();
40+
afterEach(async function () {
41+
await removeGitRoot(this.gitRoot);
4342
});
4443

4544
describe("dialog", function () {

spec/commands/discard-all-changes-spec.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ describe("discard-all-changes", function () {
88

99
beforeEach(async function () {
1010
await atom.packages.activatePackage("context-git");
11-
createGitRoot();
12-
this.gitRoot = getFilePath();
13-
atom.project.setPaths([this.gitRoot]);
11+
this.gitRoot = await createGitRoot();
1412

15-
this.filePaths = getFilePath([files.t1]);
13+
this.filePaths = getFilePath(this.gitRoot, [files.t1]);
1614
});
1715

18-
afterEach(function () {
19-
removeGitRoot();
16+
afterEach(async function () {
17+
await removeGitRoot(this.gitRoot);
2018
});
2119

2220
it("should call discard changes with project folders", async function () {

spec/commands/discard-changes-spec.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ describe("discard-changes", function () {
99

1010
beforeEach(async function () {
1111
await atom.packages.activatePackage("context-git");
12-
createGitRoot();
13-
this.gitRoot = getFilePath();
14-
atom.project.setPaths([this.gitRoot]);
12+
this.gitRoot = await createGitRoot();
13+
1514
this.repo = await atom.project.repositoryForDirectory(new Directory(this.gitRoot));
1615

1716
this.statuses = [fileStatus(" M", files.t1), fileStatus("??", files.t2)];
18-
this.filePaths = getFilePath([files.t1]);
17+
this.filePaths = getFilePath(this.gitRoot, [files.t1]);
1918
this.git = mockGit({
2019
rootDir: Promise.resolve(this.gitRoot),
2120
status: _ => Promise.resolve(this.statuses),
@@ -25,8 +24,8 @@ describe("discard-changes", function () {
2524
});
2625
});
2726

28-
afterEach(function () {
29-
removeGitRoot();
27+
afterEach(async function () {
28+
await removeGitRoot(this.gitRoot);
3029
});
3130

3231
it("should call git.clean", async function () {

spec/commands/pull-spec.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ describe("pull", function () {
99

1010
beforeEach(async function () {
1111
await atom.packages.activatePackage("context-git");
12-
createGitRoot();
13-
this.gitRoot = getFilePath();
14-
atom.project.setPaths([this.gitRoot]);
12+
this.gitRoot = await createGitRoot();
1513

16-
this.filePaths = getFilePath([files.t1]);
14+
this.filePaths = getFilePath(this.gitRoot, [files.t1]);
1715
this.git = mockGit({
1816
rootDir: Promise.resolve(this.gitRoot),
1917
pull: Promise.resolve("pull result"),
2018
});
2119
});
2220

23-
afterEach(function () {
24-
removeGitRoot();
21+
afterEach(async function () {
22+
await removeGitRoot(this.gitRoot);
2523
});
2624

2725
it("should show pulling... in status bar", async function () {

spec/commands/push-spec.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ describe("push", function () {
99

1010
beforeEach(async function () {
1111
await atom.packages.activatePackage("context-git");
12-
createGitRoot();
13-
this.gitRoot = getFilePath();
14-
atom.project.setPaths([this.gitRoot]);
12+
this.gitRoot = await createGitRoot();
1513

16-
this.filePaths = getFilePath([files.t1]);
14+
this.filePaths = getFilePath(this.gitRoot, [files.t1]);
1715
this.git = mockGit({
1816
rootDir: Promise.resolve(this.gitRoot),
1917
push: Promise.resolve("push result"),
2018
});
2119
});
2220

23-
afterEach(function () {
24-
removeGitRoot();
21+
afterEach(async function () {
22+
await removeGitRoot(this.gitRoot);
2523
});
2624

2725
it("should show pushing... in status bar", async function () {

spec/commands/run-command-spec.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ describe("run-command", function () {
99

1010
beforeEach(async function () {
1111
await atom.packages.activatePackage("context-git");
12-
createGitRoot();
13-
this.gitRoot = getFilePath();
14-
atom.project.setPaths([this.gitRoot]);
12+
this.gitRoot = await createGitRoot();
13+
1514
this.repo = await atom.project.repositoryForDirectory(new Directory(this.gitRoot));
1615

1716
this.statuses = [fileStatus("M ", files.t1)];
18-
this.filePaths = getFilePath([files.t1]);
17+
this.filePaths = getFilePath(this.gitRoot, [files.t1]);
1918
this.git = mockGit({
2019
rootDir: Promise.resolve(this.gitRoot),
2120
status: Promise.resolve(this.statuses),
@@ -30,8 +29,8 @@ describe("run-command", function () {
3029
});
3130
});
3231

33-
afterEach(function () {
34-
removeGitRoot();
32+
afterEach(async function () {
33+
await removeGitRoot(this.gitRoot);
3534
});
3635

3736
describe("dialog", function () {
@@ -118,7 +117,7 @@ describe("run-command", function () {
118117
try {
119118
await runCommand.command(this.filePaths, statusBar, this.git, Notifications, this.dialog);
120119
} catch (ex) {}
121-
expect(this.git.cmd).toHaveBeenCalledWith(this.gitRoot, ["command", "arg1", getFilePath(this.dialogReturn[1][0])]);
120+
expect(this.git.cmd).toHaveBeenCalledWith(this.gitRoot, ["command", "arg1", getFilePath(this.gitRoot, this.dialogReturn[1][0])]);
122121
});
123122

124123
it("should return 'Ran {command}'", async function () {

spec/context-git-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("Context Git", function () {
4141
const dispatch = main.dispatchCommand(command, commands[command]);
4242
describe(command, function () {
4343
beforeEach(function () {
44-
this.cmdSpy = spyOn(commands[command], "command").and.returnValue(Promise.reject());
44+
this.cmdSpy = spyOn(commands[command], "command").and.callFake(_ => Promise.reject());
4545
});
4646
it("should have a command in the command pallete", function () {
4747
expect(this.allCommands).toContain(cmd);

spec/git/add-spec.js

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use babel";
22

33
import gitCmd from "../../lib/git-cmd";
4-
// import { getFilePath, removeGitRoot, createGitRoot, files } from "../mocks";
4+
import { getFilePath, removeGitRoot, createGitRoot, files } from "../mocks";
55

66
describe("git.add", function () {
77

@@ -29,28 +29,27 @@ describe("git.add", function () {
2929
.toContain("--verbose");
3030
});
3131

32-
// describe("integration tests", function () {
33-
//
34-
// beforeEach(async function () {
35-
// await atom.packages.activatePackage("context-git");
36-
// createGitRoot();
37-
// this.gitRoot = getFilePath();
38-
// atom.project.setPaths([this.gitRoot]);
39-
// await gitCmd.cmd(this.gitRoot, ["init"]);
40-
// this.gitPath = getFilePath(".git");
41-
// });
42-
//
43-
// afterEach(function () {
44-
// removeGitRoot();
45-
// });
46-
//
47-
// it("should add a file", async function () {
48-
// await gitCmd.add(this.gitRoot, getFilePath(files.t1));
49-
// const status = await gitCmd.cmd(this.gitRoot, ["status", "--short"]);
50-
//
51-
// expect(status).toContain(`A ${files.t1}`);
52-
// });
53-
//
54-
// });
32+
describe("integration tests", function () {
33+
34+
beforeEach(async function () {
35+
gitCmd.cmd.and.callThrough();
36+
await atom.packages.activatePackage("context-git");
37+
this.gitRoot = await createGitRoot();
38+
39+
this.gitPath = getFilePath(this.gitRoot, ".git");
40+
});
41+
42+
afterEach(async function () {
43+
await removeGitRoot(this.gitRoot);
44+
});
45+
46+
it("should add a file", async function () {
47+
await gitCmd.add(this.gitRoot, getFilePath(this.gitRoot, [files.t1]));
48+
const status = await gitCmd.cmd(this.gitRoot, ["status", "--short"]);
49+
50+
expect(status).toContain(`A ${files.t1}`);
51+
});
52+
53+
});
5554

5655
});

spec/git/cmd-spec.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ describe("git.cmd", function () {
77

88
beforeEach(async function () {
99
await atom.packages.activatePackage("context-git");
10-
createGitRoot();
11-
this.gitRoot = getFilePath();
12-
atom.project.setPaths([this.gitRoot]);
10+
this.gitRoot = await createGitRoot();
1311
});
1412

15-
afterEach(function () {
16-
removeGitRoot();
13+
afterEach(async function () {
14+
await removeGitRoot(this.gitRoot);
1715
});
1816

1917
it("should call git", async function () {
2018
let error;
2119
try {
22-
await gitCmd.cmd(this.getRoot);
20+
await gitCmd.cmd(this.gitRoot);
2321
} catch (ex) {
2422
error = ex;
2523
}
@@ -30,7 +28,7 @@ describe("git.cmd", function () {
3028
it("should call git with the args", async function () {
3129
let error;
3230
try {
33-
await gitCmd.cmd(this.getRoot, ["test"]);
31+
await gitCmd.cmd(this.gitRoot, ["test"]);
3432
} catch (ex) {
3533
error = ex;
3634
}
@@ -41,7 +39,7 @@ describe("git.cmd", function () {
4139
it("should reject on error", async function () {
4240
let rejected;
4341
try {
44-
await gitCmd.cmd(this.getRoot, ["test"]);
42+
await gitCmd.cmd(this.gitRoot, ["test"]);
4543
} catch (ex) {
4644
rejected = true;
4745
}
@@ -50,7 +48,7 @@ describe("git.cmd", function () {
5048
});
5149

5250
it("should resolve on non-error", async function () {
53-
await gitCmd.cmd(this.getRoot, ["init"]);
51+
await gitCmd.cmd(this.gitRoot, ["init"]);
5452
pass();
5553
});
5654

0 commit comments

Comments
 (0)