From 44729fa52695dfcefb0a8f8ea3e83e03c6691386 Mon Sep 17 00:00:00 2001 From: Jason Tremper Date: Sun, 14 Dec 2014 16:55:15 -0500 Subject: [PATCH] Adding Mocha instance for "require('mocha')" used for testrunners --- mocha/mocha-tests.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++ mocha/mocha.d.ts | 41 +++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/mocha/mocha-tests.ts b/mocha/mocha-tests.ts index 672fac1cb..750a417fe 100644 --- a/mocha/mocha-tests.ts +++ b/mocha/mocha-tests.ts @@ -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); + }); +} \ No newline at end of file diff --git a/mocha/mocha.d.ts b/mocha/mocha.d.ts index 64255a7ba..2e6fa9c58 100644 --- a/mocha/mocha.d.ts +++ b/mocha/mocha.d.ts @@ -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 , otiai10 +// Definitions by: Kazi Manzur Rashid , otiai10 , 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; +}