From 098def61bc44ee29dae7e7a5c719873195086ac2 Mon Sep 17 00:00:00 2001 From: vvakame Date: Tue, 23 Jun 2015 21:38:32 +0900 Subject: [PATCH] separate mocha node.js definition --- mocha/mocha-node-tests.ts | 37 +++++++++++++++++++++++++++++++++++++ mocha/mocha-node.d.ts | 16 ++++++++++++++++ mocha/mocha-tests.ts | 34 ---------------------------------- mocha/mocha.d.ts | 18 ++++++++---------- 4 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 mocha/mocha-node-tests.ts create mode 100644 mocha/mocha-node.d.ts diff --git a/mocha/mocha-node-tests.ts b/mocha/mocha-node-tests.ts new file mode 100644 index 0000000000..e27ec8e6d9 --- /dev/null +++ b/mocha/mocha-node-tests.ts @@ -0,0 +1,37 @@ +/// + +import MochaDef = require('mocha'); + +class CustomSpecReporter extends MochaDef.reporters.Spec { + constructor(runner: Mocha.IRunner) { + super(runner); + + runner.on('test', (test: Mocha.ITest) => { + console.log(test.parent.title + '/' + test.title); + }); + } +} + +class MyReporter extends MochaDef.reporters.Base { + passes: number = 0; + failures: number = 0; + + constructor(runner: Mocha.IRunner) { + super(runner); + + runner.on('pass', (test: Mocha.ITest) => { + this.passes++; + console.log('pass: %s', test.fullTitle()); + }); + + runner.on('fail', (test: Mocha.ITest, err: Error) => { + this.failures++; + console.log('fail: %s -- error: %s', test.fullTitle(), err.message); + }); + + runner.on('end', () => { + console.log('end: %d/%d', this.passes, this.passes + this.failures); + process.exit(this.failures); + }); + } +} diff --git a/mocha/mocha-node.d.ts b/mocha/mocha-node.d.ts new file mode 100644 index 0000000000..b0fa0a6ac7 --- /dev/null +++ b/mocha/mocha-node.d.ts @@ -0,0 +1,16 @@ +// Type definitions for mocha 2.2.5 +// Project: http://mochajs.org/ +// Definitions by: Vadim Macagon , vvakame +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +declare module Mocha { + interface IRunnable extends NodeJS.EventEmitter { + } + interface ISuite extends NodeJS.EventEmitter { + } + interface IRunner extends NodeJS.EventEmitter { + } +} diff --git a/mocha/mocha-tests.ts b/mocha/mocha-tests.ts index a2e2b07961..f90fefaf96 100644 --- a/mocha/mocha-tests.ts +++ b/mocha/mocha-tests.ts @@ -249,37 +249,3 @@ function test_run_withOnComplete() { console.log(failures); }); } - -class CustomSpecReporter extends MochaDef.reporters.Spec { - constructor(runner: Mocha.IRunner) { - super(runner); - - runner.on('test', (test: Mocha.ITest) => { - console.log(test.parent.title + '/' + test.title); - }); - } -} - -class MyReporter extends MochaDef.reporters.Base { - passes: number = 0; - failures: number = 0; - - constructor(runner: Mocha.IRunner) { - super(runner); - - runner.on('pass', (test: Mocha.ITest) => { - this.passes++; - console.log('pass: %s', test.fullTitle()); - }); - - runner.on('fail', (test: Mocha.ITest, err: Error) => { - this.failures++; - console.log('fail: %s -- error: %s', test.fullTitle(), err.message); - }); - - runner.on('end', () => { - console.log('end: %d/%d', this.passes, this.passes + this.failures); - process.exit(this.failures); - }); - } -} diff --git a/mocha/mocha.d.ts b/mocha/mocha.d.ts index fefd919466..e3484bd72c 100644 --- a/mocha/mocha.d.ts +++ b/mocha/mocha.d.ts @@ -3,8 +3,6 @@ // Definitions by: Kazi Manzur Rashid , otiai10 , jt000 , Vadim Macagon // Definitions: https://github.com/borisyankov/DefinitelyTyped -/// - interface MochaSetupOptions { //milliseconds to wait before considering a test slow slow?: number; @@ -30,7 +28,7 @@ interface MochaSetupOptions { // grep string or regexp to filter tests with grep?: any; } - + interface MochaDone { (error?: Error): void; } @@ -118,7 +116,7 @@ declare class Mocha { // merge the Mocha class declaration with a module declare module Mocha { /** Partial interface for Mocha's `Runnable` class. */ - interface IRunnable extends NodeJS.EventEmitter { + interface IRunnable { title: string; fn: Function; async: boolean; @@ -127,10 +125,10 @@ declare module Mocha { } /** Partial interface for Mocha's `Suite` class. */ - interface ISuite extends NodeJS.EventEmitter { + interface ISuite { parent: ISuite; title: string; - + fullTitle(): string; } @@ -138,12 +136,12 @@ declare module Mocha { interface ITest extends IRunnable { parent: ISuite; pending: boolean; - + fullTitle(): string; } /** Partial interface for Mocha's `Runner` class. */ - interface IRunner extends NodeJS.EventEmitter {} + interface IRunner {} interface IContextDefinition { (description: string, spec: () => void): ISuite; @@ -151,7 +149,7 @@ declare module Mocha { skip(description: string, spec: () => void): void; timeout(ms: number): void; } - + interface ITestDefinition { (expectation: string, assertion?: () => void): ITest; (expectation: string, assertion?: (done: MochaDone) => void): ITest; @@ -174,7 +172,7 @@ declare module Mocha { constructor(runner: IRunner); } - + export class Doc extends Base {} export class Dot extends Base {} export class HTML extends Base {}