Adding Mocha instance for "require('mocha')" used for testrunners

This commit is contained in:
Jason Tremper
2014-12-14 16:55:15 -05:00
parent 53941f20d2
commit 44729fa526
2 changed files with 94 additions and 2 deletions
+55
View File
@@ -167,3 +167,58 @@ function test_chaining(){
.reporter('html')
.reporter(function(){});
}
import MochaDef = require('mocha');
function test_require_constructor_empty() {
var instance = new MochaDef();
}
function test_require_constructor_noOptions() {
var instance = new MochaDef({});
}
function test_require_constructor_allOptions() {
var instance = new MochaDef({
grep: /[a-z]*/,
ui: 'tdd',
reporter: 'dot',
timeout: 500,
bail: true
});
}
function test_require_fluentParams() {
var instance = new MochaDef();
instance.bail(true)
.bail()
.addFile('foo.js')
.reporter('bdd')
.ui('dot')
.grep('[a-z]*')
.grep(/[a-z]*/)
.invert()
.ignoreLeaks(true)
.checkLeaks()
.growl()
.globals('foo')
.globals(['bar', 'zap'])
.useColors(true)
.useInlineDiffs(true)
.timeout(500)
.slow(100)
.enableTimeouts(true)
.asyncOnly(false)
.noHighlighting(true)
.run();
}
function test_run_withOnComplete() {
var instance = new MochaDef();
instance.run((failures: any[]): void => {
console.log(failures);
});
}
+39 -2
View File
@@ -1,6 +1,6 @@
// Type definitions for mocha 1.17.1
// Type definitions for mocha 2.0.1
// Project: http://visionmedia.github.io/mocha/
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>, jt000 <https://github.com/jt000>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface Mocha {
@@ -108,3 +108,40 @@ declare function afterEach(action: (done: MochaDone) => void): void;
declare function suiteTeardown(action: () => void): void;
declare function suiteTeardown(action: (done: MochaDone) => void): void;
declare module "mocha" {
class MochaInstance {
constructor(options?: {
grep?: RegExp;
ui?: string;
reporter?: string;
timeout?: number;
bail?: boolean;
});
bail(value?: boolean): MochaInstance;
addFile(file: string): MochaInstance;
reporter(value: string): MochaInstance;
ui(value: string): MochaInstance;
grep(value: string): MochaInstance;
grep(value: RegExp): MochaInstance;
invert(): MochaInstance;
ignoreLeaks(value: boolean): MochaInstance;
checkLeaks(): MochaInstance;
growl(): MochaInstance;
globals(value: string): MochaInstance;
globals(values: string[]): MochaInstance;
useColors(value: boolean): MochaInstance;
useInlineDiffs(value: boolean): MochaInstance;
timeout(value: number): MochaInstance;
slow(value: number): MochaInstance;
enableTimeouts(value: boolean): MochaInstance;
asyncOnly(value: boolean): MochaInstance;
noHighlighting(value: boolean): MochaInstance;
run(onComplete?: (failures: any[]) => void): void;
}
export = MochaInstance;
}