mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-29 11:12:23 +08:00
Merge pull request #3313 from jt000/master
Adding basic support for expressjs multer, mockery, mocha, mongoose-mock, and proxyquire
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
/// <reference path="chai-as-promised.d.ts" />
|
||||
|
||||
import chai = require('chai');
|
||||
import chaiAsPromised = require('chai-as-promised');
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
|
||||
var promise: any;
|
||||
chai.expect(promise).to.eventually.equal(3);
|
||||
chai.expect(promise).to.become(3);
|
||||
chai.expect(promise).to.be.rejected;
|
||||
chai.expect(promise).to.be.rejectedWith(Error);
|
||||
chai.expect(promise).to.notify(() => console.log('done'));
|
||||
|
||||
chai.assert.eventually.equal(promise, 4, 'Message');
|
||||
chai.assert.isFulfilled(promise, "optional message");
|
||||
chai.assert.becomes(promise, "foo", "optional message");
|
||||
chai.assert.doesNotBecome(promise, "foo", "optional message");
|
||||
chai.assert.isRejected(promise, "optional message");
|
||||
chai.assert.isRejected(promise, Error, "optional message");
|
||||
chai.assert.isRejected(promise, /error message matcher/, "optional message");
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// Type definitions for chai-as-promised
|
||||
// Project: https://github.com/domenic/chai-as-promised/
|
||||
// Definitions by: jt000 <https://github.com/jt000>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../chai/chai.d.ts" />
|
||||
|
||||
declare module 'chai-as-promised' {
|
||||
import chai = require('chai');
|
||||
|
||||
function chaiAsPromised(chai: any, utils: any): void;
|
||||
|
||||
export = chaiAsPromised;
|
||||
}
|
||||
|
||||
declare module chai {
|
||||
|
||||
interface LanguageChains {
|
||||
become(expected: any): Expect;
|
||||
eventually: Expect;
|
||||
rejected: Expect;
|
||||
rejectedWith(expected: any): Expect;
|
||||
notify(fn: Function): Expect;
|
||||
}
|
||||
|
||||
interface Assert {
|
||||
eventually: Assert;
|
||||
isFulfilled(promise: any, message?: string): void;
|
||||
becomes(promise: any, expected: any, message?: string): void;
|
||||
doesNotBecome(promise: any, expected: any, message?: string): void;
|
||||
isRejected(promise: any, message?: string): void;
|
||||
isRejected(promise: any, expected: any, message?: string): void;
|
||||
isRejected(promise: any, match: RegExp, message?: string): void;
|
||||
}
|
||||
}
|
||||
@@ -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: number): void => {
|
||||
console.log(failures);
|
||||
});
|
||||
}
|
||||
Vendored
+40
-3
@@ -1,6 +1,6 @@
|
||||
// Type definitions for mocha 1.17.1
|
||||
// Project: http://visionmedia.github.io/mocha/
|
||||
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>
|
||||
// Type definitions for mocha 2.0.1
|
||||
// Project: http://mochajs.org/
|
||||
// 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 Mocha {
|
||||
constructor(options?: {
|
||||
grep?: RegExp;
|
||||
ui?: string;
|
||||
reporter?: string;
|
||||
timeout?: number;
|
||||
bail?: boolean;
|
||||
});
|
||||
|
||||
bail(value?: boolean): Mocha;
|
||||
addFile(file: string): Mocha;
|
||||
reporter(value: string): Mocha;
|
||||
ui(value: string): Mocha;
|
||||
grep(value: string): Mocha;
|
||||
grep(value: RegExp): Mocha;
|
||||
invert(): Mocha;
|
||||
ignoreLeaks(value: boolean): Mocha;
|
||||
checkLeaks(): Mocha;
|
||||
growl(): Mocha;
|
||||
globals(value: string): Mocha;
|
||||
globals(values: string[]): Mocha;
|
||||
useColors(value: boolean): Mocha;
|
||||
useInlineDiffs(value: boolean): Mocha;
|
||||
timeout(value: number): Mocha;
|
||||
slow(value: number): Mocha;
|
||||
enableTimeouts(value: boolean): Mocha;
|
||||
asyncOnly(value: boolean): Mocha;
|
||||
noHighlighting(value: boolean): Mocha;
|
||||
|
||||
run(onComplete?: (failures: number) => void): void;
|
||||
}
|
||||
|
||||
export = Mocha;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/// <reference path="mockery.d.ts" />
|
||||
|
||||
import mockery = require('mockery');
|
||||
|
||||
mockery.enable();
|
||||
mockery.enable({});
|
||||
mockery.enable({
|
||||
useCleanCache: true,
|
||||
warnOnReplace: true,
|
||||
warnOnUnregistered: true
|
||||
});
|
||||
|
||||
mockery.disable();
|
||||
|
||||
var fsMock = {
|
||||
stat: (path: any, cb: any) => { /* your mock code */ }
|
||||
};
|
||||
mockery.registerMock('fs', fsMock);
|
||||
|
||||
mockery.deregisterMock('fs');
|
||||
|
||||
mockery.registerSubstitute('fs', 'fs-mock');
|
||||
|
||||
mockery.deregisterSubstitute('fs');
|
||||
|
||||
mockery.registerAllowable('./my-source-under-test');
|
||||
mockery.registerAllowable('./my-source-under-test', true);
|
||||
|
||||
mockery.deregisterAllowable('./my-source-under-test');
|
||||
|
||||
mockery.registerAllowables(['async', 'path', 'util']);
|
||||
|
||||
mockery.deregisterAllowables(['async', 'path', 'util']);
|
||||
|
||||
mockery.deregisterAll();
|
||||
|
||||
mockery.resetCache();
|
||||
|
||||
mockery.warnOnUnregistered(false);
|
||||
|
||||
mockery.warnOnReplace(false);
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// Type definitions for mockery 1.4.0
|
||||
// Project: https://github.com/mfncooper/mockery
|
||||
// Definitions by: jt000 <https://github.com/jt000>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "mockery" {
|
||||
|
||||
interface MockeryEnableArgs {
|
||||
useCleanCache?: boolean;
|
||||
warnOnReplace?: boolean;
|
||||
warnOnUnregistered?: boolean;
|
||||
}
|
||||
|
||||
export function enable(args?: MockeryEnableArgs): void;
|
||||
export function disable(): void;
|
||||
|
||||
export function registerMock(name: string, mock: any): void;
|
||||
export function deregisterMock(name: string): void;
|
||||
|
||||
export function registerSubstitute(name: string, substitute: string): void;
|
||||
export function deregisterSubstitute(name: string): void;
|
||||
|
||||
export function registerAllowable(name: string, unhook?: boolean): void;
|
||||
export function deregisterAllowable(name: string): void;
|
||||
|
||||
export function registerAllowables(names: string[]): void;
|
||||
export function deregisterAllowables(names: string[]): void;
|
||||
|
||||
export function deregisterAll(): void;
|
||||
export function resetCache(): void;
|
||||
export function warnOnUnregistered(value: boolean): void;
|
||||
export function warnOnReplace(value: boolean): void;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/// <reference path="../mongoose/mongoose.d.ts" />
|
||||
/// <reference path="mongoose-mock.d.ts" />
|
||||
|
||||
import mongooseMock = require('mongoose-mock');
|
||||
|
||||
// returns a mongoose object
|
||||
mongooseMock.connect('url');
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// Type definitions for mongoose-mock 0.4.0
|
||||
// Project: https://github.com/JohanObrink/mongoose-mock
|
||||
// Definitions by: jt000 <https://github.com/jt000>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../mongoose/mongoose.d.ts" />
|
||||
|
||||
declare module "mongoose-mock" {
|
||||
import mongoose = require('mongoose');
|
||||
|
||||
var mock: mongoose.Mongoose;
|
||||
export = mock;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
/// <reference path="multer.d.ts" />
|
||||
|
||||
import express = require('express');
|
||||
import multer = require('multer');
|
||||
|
||||
var app: express.Express = express();
|
||||
app.use(multer());
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// Type definitions for multer
|
||||
// Project: https://github.com/expressjs/multer
|
||||
// Definitions by: jt000 <https://github.com/jt000>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
|
||||
declare module "multer" {
|
||||
import express = require('express');
|
||||
|
||||
function multer(options?: any): express.RequestHandler;
|
||||
|
||||
export = multer;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path="./proxyquire.d.ts" />
|
||||
|
||||
import proxyquire = require('proxyquire');
|
||||
|
||||
class Foo {}
|
||||
var mock = {};
|
||||
|
||||
var myModule = proxyquire('myModule', mock);
|
||||
var fooModule: Foo = proxyquire<Foo>('foo', mock);
|
||||
|
||||
myModule = proxyquire.noCallThru()
|
||||
.load('myModule', mock);
|
||||
|
||||
fooModule = proxyquire.callThru()
|
||||
.load<Foo>('foo', mock);
|
||||
|
||||
proxyquire.preserveCache();
|
||||
|
||||
proxyquire.noPreserveCache();
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// Type definitions for Proxyquire 1.3.0
|
||||
// Project: https://github.com/thlorenz/proxyquire
|
||||
// Definitions by: jt000 <https://github.com/jt000/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface Proxyquire {
|
||||
|
||||
(request: string, stubs: any): any;
|
||||
<T>(request: string, stubs: any): T;
|
||||
|
||||
load(request: string, stubs: any): any;
|
||||
load<T>(request: string, stubs: any): T;
|
||||
|
||||
noCallThru(): Proxyquire;
|
||||
callThru(): Proxyquire;
|
||||
|
||||
noPreserveCache(): void;
|
||||
preserveCache(): void;
|
||||
}
|
||||
|
||||
declare module 'proxyquire' {
|
||||
|
||||
var p: Proxyquire;
|
||||
export = p;
|
||||
}
|
||||
Reference in New Issue
Block a user