Skip to content

Commit a31f989

Browse files
authored
Merge pull request fabric8-analytics#3 from invincibleJai/vscode-test-setup
initial setup to run test on VScode extension
2 parents 23ee6e9 + f77c4cd commit a31f989

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ The purpose of the extension is to show stack analysis report. To play with the
1717
* `npm install`
1818
* `npm run compile` to start the compiler in watch mode
1919
* open this folder in VS Code and press `F5`
20+
21+
22+
# Run tests
23+
* open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests`
24+
* press `F5` to run the tests in a new window with your extension loaded
25+
* see the output of the test result in the debug console
26+
* make changes to `test/extension.test.ts` or create new test files inside the `test` folder
27+
* by convention, the test runner will only consider files matching the name pattern `**.test.ts`
28+
* you can create folders inside the `test` folder to structure your tests any way you want

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@
8383
"scripts": {
8484
"vscode:prepublish": "tsc -p ./",
8585
"compile": "tsc -watch -p ./",
86-
"postinstall": "node ./node_modules/vscode/bin/install"
86+
"postinstall": "node ./node_modules/vscode/bin/install",
87+
"test": "node ./node_modules/vscode/bin/test"
8788
},
8889
"devDependencies": {
8990
"@types/mocha": "^2.2.33",
9091
"@types/node": "^6.0.52",
9192
"typescript": "^2.1.5",
92-
"vscode": "^1.0.3"
93+
"vscode": "^1.0.3",
94+
"mocha": "^2.3.3"
9395
},
9496
"dependencies": {
9597
"request": "2.79.0",

test/extension.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 myExtension from '../src/extension';
13+
14+
// Defines a Mocha test suite to group tests of similar kind together
15+
suite("Extension Tests", () => {
16+
17+
// Defines a Mocha unit test
18+
test("Something 1", () => {
19+
assert.equal(-1, [1, 2, 3].indexOf(5));
20+
assert.equal(-1, [1, 2, 3].indexOf(0));
21+
});
22+
});

test/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
3+
//
4+
// This file is providing the test runner to use when running extension tests.
5+
// By default the test runner in use is Mocha based.
6+
//
7+
// You can provide your own test runner if you want to override it by exporting
8+
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
9+
// host can call to run the tests. The test runner is expected to use console.log
10+
// to report the results back to the caller. When the tests are finished, return
11+
// a possible error to the callback or null if none.
12+
13+
var testRunner = require('vscode/lib/testrunner');
14+
15+
// You can directly control Mocha options by uncommenting the following lines
16+
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
17+
testRunner.configure({
18+
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
19+
useColors: true // colored output from test results
20+
});
21+
22+
module.exports = testRunner;

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"rootDir": "src"
1111
},
1212
"exclude": [
13-
"node_modules"
13+
"node_modules",
14+
".vscode-test"
1415
]
1516
}

0 commit comments

Comments
 (0)