Skip to content

Commit ba4220f

Browse files
authored
Merge pull request #150 from edgardmessias/optimize_tests
Optimize tests
2 parents b869453 + 236c7c5 commit ba4220f

File tree

9 files changed

+294
-33
lines changed

9 files changed

+294
-33
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ install:
3333
- npm install
3434
#- npm run prettier
3535
- npm run vscode:prepublish
36+
# For coverage
37+
- sed -i.bak 's/"\*"//g' package.json
3638

3739
script:
3840
- npm test --silent
3941

4042
after_success:
41-
- if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$CODE_VERSION" == "" ]; then
42-
bash <(curl -s https://codecov.io/bash);
43-
fi
43+
- bash <(curl -s https://codecov.io/bash)

appveyor.yml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
environment:
2-
ELECTRON_RUN_AS_NODE: 1
2+
ELECTRON_NO_ATTACH_CONSOLE: 1
33
VSCODE_BUILD_VERBOSE: true
44

5+
# platform:
6+
# - x86
7+
# - x64
8+
59
cache:
10+
- node_modules
611
- '%LOCALAPPDATA%\Yarn\cache'
12+
- '%APPDATA%\npm-cache'
713

814
install:
9-
- ps: Install-Product node 8.9.1 x64
10-
11-
build_script:
15+
- ps: Install-Product node 8.9.1
16+
- npm install -g npm
17+
- node --version
18+
- npm --version
1219
- npm install
20+
21+
build_script:
1322
- npm run vscode:prepublish
23+
# For coverage
24+
- ps: (get-content package.json) | %{$_ -replace '"\*"',''} | set-content package.json
25+
1426

1527
test_script:
16-
- npm run test --silent
28+
- npm test --silent
29+
30+
after_test:
31+
- ps: |
32+
$env:PATH = 'C:\msys64\usr\bin;' + $env:PATH
33+
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
34+
bash codecov.sh

src/commands.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,14 @@ export class SvnCommands implements IDisposable {
170170
return result;
171171
}
172172

173+
@command("svn._getModel")
174+
getModel() {
175+
return this.model;
176+
}
177+
173178
@command("svn.fileOpen")
174-
fileOpen(resourceUri: Uri) {
175-
commands.executeCommand("vscode.open", resourceUri);
179+
async fileOpen(resourceUri: Uri) {
180+
await commands.executeCommand("vscode.open", resourceUri);
176181
}
177182

178183
@command("svn.commitWithMessage", { repository: true })

src/extension.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
async function init(context: ExtensionContext, disposables: Disposable[]) {
2020
const outputChannel = window.createOutputChannel("Svn");
2121
disposables.push(outputChannel);
22+
outputChannel.show();
2223

2324
const config = workspace.getConfiguration("svn");
2425
const enabled = config.get<boolean>("enabled") === true;
@@ -71,17 +72,15 @@ async function init(context: ExtensionContext, disposables: Disposable[]) {
7172
);
7273
}
7374

74-
function activate(context: ExtensionContext): any {
75+
export async function activate(context: ExtensionContext) {
7576
const disposables: Disposable[] = [];
7677
context.subscriptions.push(
7778
new Disposable(() => Disposable.from(...disposables).dispose())
7879
);
7980

80-
init(context, disposables).catch(err => console.error(err));
81+
await init(context, disposables).catch(err => console.error(err));
8182
}
8283

83-
exports.activate = activate;
84-
8584
// this method is called when your extension is deactivated
8685
function deactivate() {}
8786
exports.deactivate = deactivate;

src/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ export class Model implements IDisposable {
237237

238238
getRepository(hint: any) {
239239
const liveRepository = this.getOpenRepository(hint);
240-
return liveRepository && liveRepository.repository;
240+
if (liveRepository && liveRepository.repository) {
241+
return liveRepository.repository;
242+
}
241243
}
242244

243245
getOpenRepository(hint: any): OpenRepository | undefined {

src/test/commands.test.ts

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
//
2+
// Note: This example test is leveraging the Mocha test framework.
3+
// Please refer to their documentation on https://mochajs.org/ for help.
4+
//
5+
6+
// The module 'assert' provides assertion methods from node
7+
import * as assert from "assert";
8+
9+
// You can import and use all API from the 'vscode' module
10+
// as well as import your extension to test it
11+
import * as fs from "fs";
12+
import * as path from "path";
13+
import * as vscode from "vscode";
14+
import * as testUtil from "./testUtil";
15+
import {
16+
Uri,
17+
commands,
18+
workspace,
19+
window,
20+
InputBoxOptions,
21+
CancellationToken,
22+
QuickPickOptions,
23+
QuickPickItem
24+
} from "vscode";
25+
import { Svn } from "../svn";
26+
import { Model } from "../model";
27+
import { SvnFinder, ISvn } from "../svnFinder";
28+
import { Repository } from "../repository";
29+
import { timeout } from "../util";
30+
import { SvnResourceGroup } from "../resource";
31+
32+
// Defines a Mocha test suite to group tests of similar kind together
33+
suite("Commands Tests", () => {
34+
let repoUri: Uri;
35+
let checkoutDir: Uri;
36+
let model: Model;
37+
38+
suiteSetup(async () => {
39+
await testUtil.activeExtension();
40+
41+
repoUri = await testUtil.createRepoServer();
42+
await testUtil.createStandardLayout(testUtil.getSvnUrl(repoUri));
43+
checkoutDir = await testUtil.createRepoCheckout(
44+
testUtil.getSvnUrl(repoUri) + "/trunk"
45+
);
46+
47+
model = (await commands.executeCommand(
48+
"svn._getModel",
49+
checkoutDir
50+
)) as Model;
51+
52+
await model.tryOpenRepository(checkoutDir.fsPath);
53+
});
54+
55+
suiteTeardown(() => {
56+
model.openRepositories.forEach(repository => repository.dispose());
57+
testUtil.destroyAllTempPaths();
58+
});
59+
60+
test("File Open", async function() {
61+
const file = path.join(checkoutDir.fsPath, "new.txt");
62+
fs.writeFileSync(file, "test");
63+
64+
await commands.executeCommand("svn.fileOpen", Uri.file(file));
65+
});
66+
67+
test("Add File", async function() {
68+
const repository = model.getRepository(checkoutDir) as Repository;
69+
70+
await commands.executeCommand("svn.refresh");
71+
assert.equal(repository.unversioned.resourceStates.length, 1);
72+
assert.equal(repository.changes.resourceStates.length, 0);
73+
74+
const resource = repository.unversioned.resourceStates[0];
75+
76+
await commands.executeCommand("svn.add", resource);
77+
78+
assert.equal(repository.unversioned.resourceStates.length, 0);
79+
assert.equal(repository.changes.resourceStates.length, 1);
80+
});
81+
82+
test("Commit File", async function() {
83+
const repository = model.getRepository(checkoutDir) as Repository;
84+
repository.inputBox.value = "First Commit";
85+
86+
await commands.executeCommand("svn.commitWithMessage");
87+
});
88+
89+
test("Update", async function() {
90+
await commands.executeCommand("svn.update");
91+
});
92+
93+
test("Show Log", async function() {
94+
await commands.executeCommand("svn.log");
95+
});
96+
97+
test("Open Changes", async function() {
98+
const file = path.join(checkoutDir.fsPath, "new.txt");
99+
fs.writeFileSync(file, "test 2");
100+
const uri = Uri.file(file);
101+
102+
await commands.executeCommand("svn.refresh");
103+
await commands.executeCommand("svn.openChangeBase", uri);
104+
await commands.executeCommand("svn.openChangeHead", uri);
105+
});
106+
107+
test("Open File", async function() {
108+
const file = path.join(checkoutDir.fsPath, "new.txt");
109+
const uri = Uri.file(file);
110+
111+
await commands.executeCommand("svn.openFile", uri);
112+
await commands.executeCommand("svn.openHEADFile", uri);
113+
});
114+
115+
test("Open Diff (Double click o source control)", async function() {
116+
const repository = model.getRepository(checkoutDir) as Repository;
117+
118+
await commands.executeCommand("svn.refresh");
119+
assert.equal(repository.changes.resourceStates.length, 1);
120+
121+
const resource = repository.changes.resourceStates[0];
122+
123+
await commands.executeCommand("svn.openResourceBase", resource);
124+
await commands.executeCommand("svn.openResourceHead", resource);
125+
});
126+
127+
test("Add Changelist", async function() {
128+
const repository = model.getRepository(checkoutDir) as Repository;
129+
130+
await commands.executeCommand("svn.refresh");
131+
assert.equal(repository.changes.resourceStates.length, 1);
132+
133+
const resource = repository.changes.resourceStates[0];
134+
135+
testUtil.overrideNextShowQuickPick(0);
136+
testUtil.overrideNextShowInputBox("changelist-test");
137+
138+
await commands.executeCommand("svn.addChangelist", resource);
139+
assert.ok(repository.changelists.has("changelist-test"));
140+
});
141+
142+
test("Remove Changelist", async function() {
143+
const repository = model.getRepository(checkoutDir) as Repository;
144+
145+
const group = repository.changelists.get(
146+
"changelist-test"
147+
) as SvnResourceGroup;
148+
const resource = group.resourceStates[0];
149+
150+
await commands.executeCommand("svn.removeChangelist", resource);
151+
assert.equal(group.resourceStates.length, 0);
152+
});
153+
154+
test("Show Patch", async function() {
155+
await commands.executeCommand("svn.patch");
156+
});
157+
158+
test("Commit Selected File", async function() {
159+
const repository = model.getRepository(checkoutDir) as Repository;
160+
161+
await commands.executeCommand("svn.refresh");
162+
assert.equal(repository.changes.resourceStates.length, 1);
163+
164+
const resource = repository.changes.resourceStates[0];
165+
166+
testUtil.overrideNextShowInputBox("Second Commit");
167+
await commands.executeCommand("svn.commit", resource);
168+
169+
assert.equal(repository.changes.resourceStates.length, 0);
170+
});
171+
172+
test("Commit File", async function() {
173+
const repository = model.getRepository(checkoutDir) as Repository;
174+
repository.inputBox.value = "First Commit";
175+
176+
await commands.executeCommand("svn.commitWithMessage");
177+
});
178+
179+
test("New Branch", async function() {
180+
testUtil.overrideNextShowInputBox("test");
181+
await commands.executeCommand("svn.branch");
182+
183+
const repository = model.getRepository(checkoutDir) as Repository;
184+
assert.equal(await repository.getCurrentBranch(), "test");
185+
});
186+
187+
test("Switch Branch", async function() {
188+
testUtil.overrideNextShowQuickPick(1);
189+
await commands.executeCommand("svn.switchBranch");
190+
191+
const repository = model.getRepository(checkoutDir) as Repository;
192+
assert.equal(await repository.getCurrentBranch(), "trunk");
193+
});
194+
});

src/test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (!tty.getWindowSize) {
2424

2525
let mocha = new Mocha({
2626
ui: "tdd",
27-
timeout: 10000
27+
timeout: 30000
2828
});
2929

3030
mocha.useColors(true);

src/test/repository.test.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as fs from "fs";
1212
import * as path from "path";
1313
import * as vscode from "vscode";
1414
import * as testUtil from "./testUtil";
15-
import { Uri } from "vscode";
15+
import { Uri, commands, workspace, window } from "vscode";
1616
import { Svn } from "../svn";
1717
import { Model } from "../model";
1818
import { SvnFinder, ISvn } from "../svnFinder";
@@ -22,9 +22,6 @@ import { Repository } from "../repository";
2222
suite("Repository Tests", () => {
2323
let repoUri: Uri;
2424
let checkoutDir: Uri;
25-
let svnFinder: SvnFinder;
26-
let info: ISvn;
27-
let svn: Svn;
2825
let model: Model;
2926

3027
suiteSetup(async () => {
@@ -36,24 +33,23 @@ suite("Repository Tests", () => {
3633
testUtil.getSvnUrl(repoUri) + "/trunk"
3734
);
3835

39-
svnFinder = new SvnFinder();
40-
info = await svnFinder.findSvn();
41-
svn = new Svn({ svnPath: info.path, version: info.version });
42-
model = new Model(svn);
43-
await model.tryOpenRepository(checkoutDir.fsPath);
36+
model = (await commands.executeCommand(
37+
"svn._getModel",
38+
checkoutDir
39+
)) as Model;
4440
});
4541

4642
suiteTeardown(() => {
43+
model.openRepositories.forEach(repository => repository.dispose());
4744
testUtil.destroyAllTempPaths();
4845
});
4946

50-
test("Find Repository", async () => {
51-
assert.ok(info);
52-
assert.ok(info.path);
53-
assert.ok(info.version);
47+
test("Empty Open Repository", async function() {
48+
assert.equal(model.repositories.length, 0);
5449
});
5550

5651
test("Try Open Repository", async function() {
52+
await model.tryOpenRepository(checkoutDir.fsPath);
5753
assert.equal(model.repositories.length, 1);
5854
});
5955

@@ -102,13 +98,14 @@ suite("Repository Tests", () => {
10298

10399
fs.writeFileSync(file, "test");
104100

101+
const document = await workspace.openTextDocument(file);
102+
await window.showTextDocument(document);
103+
105104
await repository.addFiles([file]);
106105

107106
assert.equal(repository.changes.resourceStates.length, 1);
108107

109-
const message = await repository.commitFiles("First Commit", [
110-
file
111-
]);
108+
const message = await repository.commitFiles("First Commit", [file]);
112109
assert.ok(/Committed revision (.*)\./i.test(message));
113110

114111
assert.equal(repository.changes.resourceStates.length, 0);

0 commit comments

Comments
 (0)