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

Commit e1c4085

Browse files
committed
add basic mocha test setup
1 parent 896f4c7 commit e1c4085

4 files changed

Lines changed: 141 additions & 4 deletions

File tree

.vscode/launch.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "0.1.0",
33
"configurations": [
44
{
5-
"name": "node-debug extension",
5+
"name": "Run Extension",
66
"type": "extensionHost",
77
"request": "launch",
88
"runtimeExecutable": "${execPath}",
@@ -14,7 +14,7 @@
1414
"outDir": "out"
1515
},
1616
{
17-
"name": "node-debug server",
17+
"name": "Run Server",
1818
"type": "node",
1919
"request": "launch",
2020
//"runtimeExecutable": "/usr/local/bin/iojs",
@@ -24,6 +24,19 @@
2424
"args": [ "--server=4711" ],
2525
"sourceMaps": true,
2626
"outDir": "out"
27+
},
28+
{
29+
"name": "Run Tests",
30+
"type": "node",
31+
"request": "launch",
32+
"program": "node_modules/mocha/bin/_mocha",
33+
"args": [
34+
"./out/tests",
35+
"--timeout", "999999",
36+
"--colors"
37+
],
38+
"sourceMaps": true,
39+
"outDir": "./out"
2740
}
2841
]
2942
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"private": true,
1010
"scripts": {
11-
"prepublish": "gulp build"
11+
"prepublish": "gulp build",
12+
"test": "mocha ./out/tests"
1213
},
1314
"engines": {
1415
"node": ">= 0.12.0",
@@ -32,7 +33,8 @@
3233
"git-rev-sync": "*",
3334
"del": "*",
3435
"run-sequence": "*",
35-
"gulp-vinyl-zip": "*"
36+
"gulp-vinyl-zip": "*",
37+
"mocha": "*"
3638
},
3739
"contributes": {
3840
"debuggers": [

src/tests/test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
import assert = require('assert');
4+
5+
describe('Array', () => {
6+
describe('#indexOf()', () => {
7+
it('should return -1 when the value is not present', function () {
8+
assert.equal(-1, [1,2,3].indexOf(5));
9+
assert.equal(-1, [1,2,3].indexOf(0));
10+
});
11+
});
12+
});

typings/mocha/mocha.d.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Type definitions for mocha 1.17.1
2+
// Project: http://visionmedia.github.io/mocha/
3+
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
interface Mocha {
7+
// Setup mocha with the given setting options.
8+
setup(options: MochaSetupOptions): Mocha;
9+
10+
//Run tests and invoke `fn()` when complete.
11+
run(callback?: () => void): void;
12+
13+
// Set reporter as function
14+
reporter(reporter: () => void): Mocha;
15+
16+
// Set reporter, defaults to "dot"
17+
reporter(reporter: string): Mocha;
18+
19+
// Enable growl support.
20+
growl(): Mocha
21+
}
22+
23+
interface MochaSetupOptions {
24+
//milliseconds to wait before considering a test slow
25+
slow?: number;
26+
27+
// timeout in milliseconds
28+
timeout?: number;
29+
30+
// ui name "bdd", "tdd", "exports" etc
31+
ui?: string;
32+
33+
//array of accepted globals
34+
globals?: any[];
35+
36+
// reporter instance (function or string), defaults to `mocha.reporters.Dot`
37+
reporter?: any;
38+
39+
// bail on the first test failure
40+
bail?: Boolean;
41+
42+
// ignore global leaks
43+
ignoreLeaks?: Boolean;
44+
45+
// grep string or regexp to filter tests with
46+
grep?: any;
47+
}
48+
49+
interface MochaDone {
50+
(error?: Error): void;
51+
}
52+
53+
declare var mocha: Mocha;
54+
55+
declare var describe : {
56+
(description: string, spec: () => void): void;
57+
only(description: string, spec: () => void): void;
58+
skip(description: string, spec: () => void): void;
59+
timeout(ms: number): void;
60+
}
61+
62+
// alias for `describe`
63+
declare var context : {
64+
(contextTitle: string, spec: () => void): void;
65+
only(contextTitle: string, spec: () => void): void;
66+
skip(contextTitle: string, spec: () => void): void;
67+
timeout(ms: number): void;
68+
}
69+
70+
declare var it: {
71+
(expectation: string, assertion?: () => void): void;
72+
(expectation: string, assertion?: (done: MochaDone) => void): void;
73+
only(expectation: string, assertion?: () => void): void;
74+
only(expectation: string, assertion?: (done: MochaDone) => void): void;
75+
skip(expectation: string, assertion?: () => void): void;
76+
skip(expectation: string, assertion?: (done: MochaDone) => void): void;
77+
timeout(ms: number): void;
78+
};
79+
80+
declare function before(action: () => void): void;
81+
82+
declare function before(action: (done: MochaDone) => void): void;
83+
84+
declare function setup(action: () => void): void;
85+
86+
declare function setup(action: (done: MochaDone) => void): void;
87+
88+
declare function after(action: () => void): void;
89+
90+
declare function after(action: (done: MochaDone) => void): void;
91+
92+
declare function teardown(action: () => void): void;
93+
94+
declare function teardown(action: (done: MochaDone) => void): void;
95+
96+
declare function beforeEach(action: () => void): void;
97+
98+
declare function beforeEach(action: (done: MochaDone) => void): void;
99+
100+
declare function suiteSetup(action: () => void): void;
101+
102+
declare function suiteSetup(action: (done: MochaDone) => void): void;
103+
104+
declare function afterEach(action: () => void): void;
105+
106+
declare function afterEach(action: (done: MochaDone) => void): void;
107+
108+
declare function suiteTeardown(action: () => void): void;
109+
110+
declare function suiteTeardown(action: (done: MochaDone) => void): void;

0 commit comments

Comments
 (0)