Skip to content

Commit 57dba88

Browse files
committed
unit test for formatters microsoft#163, microsoft#178, microsoft#160
1 parent 967d651 commit 57dba88

4 files changed

Lines changed: 28 additions & 21 deletions

File tree

src/test/extension.format.test.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//
1+
22
// Note: This example test is leveraging the Mocha test framework.
33
// Please refer to their documentation on https://mochajs.org/ for help.
4-
//
4+
55

66
// The module 'assert' provides assertion methods from node
77
import * as assert from "assert";
@@ -14,18 +14,15 @@ import {YapfFormatter} from "../client/formatters/yapfFormatter";
1414
import * as path from "path";
1515
import * as settings from "../client/common/configSettings";
1616
import * as fs from "fs-extra";
17+
import {initialize} from "./initialize";
1718

1819
let pythonSettings = settings.PythonSettings.getInstance();
1920
let ch = vscode.window.createOutputChannel("Tests");
2021
let pythoFilesPath = path.join(__dirname, "..", "..", "src", "test", "pythonFiles", "formatting");
2122

2223
suite("Formatting", () => {
23-
setup(() => {
24-
return new Promise<any>(resolve => {
25-
setTimeout(function () {
26-
resolve();
27-
}, 1000);
28-
});
24+
setup(done => {
25+
initialize().then(() => done(), done);
2926
});
3027
teardown(() => {
3128
if (vscode.window.activeTextEditor) {
@@ -56,10 +53,7 @@ suite("Formatting", () => {
5653
}
5754
assert.equal(textEditor.document.getText(), data, "Formatted text is not the same");
5855
});
59-
}).then(done, error => {
60-
done();
61-
assert.ok(false, error);
62-
});
56+
}).then(done, done);
6357
});
6458

6559
test("Yapf", done => {
@@ -85,10 +79,7 @@ suite("Formatting", () => {
8579
}
8680
assert.equal(textEditor.document.getText(), data, "Formatted text is not the same");
8781
});
88-
}).then(done, error => {
89-
done();
90-
assert.ok(false, error);
91-
});
82+
}).then(done, done);
9283
});
9384

9485
test("Yapf autoformat on save", done => {
@@ -120,9 +111,6 @@ suite("Formatting", () => {
120111
});
121112
}).then(() => {
122113
assert.equal(textDocument.getText(), formattedFileContents, "Formatted contents are not the same");
123-
}).then(done, error => {
124-
done();
125-
assert.ok(false, error);
126-
});
114+
}).then(done, done);
127115
});
128116
});

src/test/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ let testRunner = require("vscode/lib/testrunner");
1616
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
1717
testRunner.configure({
1818
ui: "tdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
19-
useColors: true // colored output from test results
19+
useColors: true, // colored output from test results
20+
timeout: 5000
2021
});
2122

2223
module.exports = testRunner;

src/test/initialize.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 vscode from "vscode";
12+
import * as path from "path";
13+
let dummyPythonFile = path.join(__dirname, "..", "..", "src", "test", "pythonFiles", "dummy.py");
14+
15+
export function initialize(): Thenable<any> {
16+
return vscode.workspace.openTextDocument(dummyPythonFile);
17+
}

src/test/pythonFiles/dummy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#dummy file to be opened by Test VS Code instance, so that Python Configuration (workspace configuration will be initialized)

0 commit comments

Comments
 (0)