mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-26 11:12:19 +08:00
Merge pull request #3138 from borisyankov/power-assert
add power-assert
This commit is contained in:
Vendored
+1
@@ -57,6 +57,7 @@ declare module assert {
|
||||
// export = assert;
|
||||
// }
|
||||
|
||||
// move to power-assert.d.ts. do not use this definition file.
|
||||
declare module "power-assert" {
|
||||
export = assert;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path="./empower.d.ts" />
|
||||
|
||||
var baseAssert:any;
|
||||
var fakeFormatter:any;
|
||||
|
||||
()=> {
|
||||
var assert = empower(baseAssert, fakeFormatter);
|
||||
};
|
||||
|
||||
var option:empower.Options = {
|
||||
modifyMessageOnRethrow: false,
|
||||
saveContextOnRethrow: false
|
||||
};
|
||||
|
||||
()=> {
|
||||
var assert = empower(baseAssert, fakeFormatter, option);
|
||||
};
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// Type definitions for empower
|
||||
// Project: https://github.com/twada/empower
|
||||
// Definitions by: vvakame <https://github.com/vvakame>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare function empower(originalAssert:any, formatter:any, options?:empower.Options):any;
|
||||
|
||||
declare module empower {
|
||||
export interface Options {
|
||||
destructive?: boolean;
|
||||
modifyMessageOnRethrow?: boolean;
|
||||
saveContextOnRethrow?: boolean;
|
||||
patterns?: string[];
|
||||
}
|
||||
}
|
||||
|
||||
declare module "empower" {
|
||||
export = empower;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/// <reference path="./power-assert-formatter.d.ts" />
|
||||
|
||||
powerAssertFormatter();
|
||||
|
||||
powerAssertFormatter({lineSeparator: '\n'});
|
||||
@@ -0,0 +1,29 @@
|
||||
// Type definitions for power-assert-formatter
|
||||
// Project: https://github.com/twada/power-assert-formatter
|
||||
// Definitions by: vvakame <https://github.com/vvakame>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare function powerAssertFormatter(options?:powerAssertFormatter.Options):powerAssertFormatter.Formatter;
|
||||
|
||||
declare module powerAssertFormatter {
|
||||
export interface Options {
|
||||
lineDiffThreshold?: number;
|
||||
maxDepth?: number;
|
||||
outputOffset?: number;
|
||||
anonymous?: string;
|
||||
circular?: string;
|
||||
lineSeparator?: string;
|
||||
ambiguousEastAsianCharWidth?: number;
|
||||
widthOf?: Function;
|
||||
stringify?: Function;
|
||||
diff?: Function;
|
||||
writerClass?: {new (): any;};
|
||||
renderers?: any[]; // { string | Function }[]
|
||||
}
|
||||
|
||||
export interface Formatter {
|
||||
(powerAssertContext:any): string;
|
||||
}
|
||||
|
||||
export function defaultOptions():Options;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/// <reference path="./power-assert.d.ts" />
|
||||
|
||||
import assert = require("power-assert");
|
||||
|
||||
assert(1 + 1 - 2 === 0, "The universe isn't how it should.");
|
||||
|
||||
assert.deepEqual({x: {y: 3}}, {x: {y: 3}}, "DEEP WENT DERP");
|
||||
|
||||
assert.equal(3, "3", "uses == comparator");
|
||||
|
||||
assert.notStrictEqual(2, "2", "uses === comparator");
|
||||
|
||||
assert.throws(() => {
|
||||
throw "a hammer at your face";
|
||||
}, undefined, "DODGED IT");
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
if (false) {
|
||||
throw "a hammer at your face";
|
||||
}
|
||||
}, undefined, "What the...*crunch*");
|
||||
|
||||
|
||||
var customizedAssert1 = assert.customize({
|
||||
output: {
|
||||
maxDepth: 2
|
||||
}
|
||||
});
|
||||
|
||||
customizedAssert1(1 + 1 - 2 === 0, "The universe isn't how it should.");
|
||||
|
||||
customizedAssert1.deepEqual({x: {y: 3}}, {x: {y: 3}}, "DEEP WENT DERP");
|
||||
|
||||
customizedAssert1.equal(3, "3", "uses == comparator");
|
||||
|
||||
customizedAssert1.notStrictEqual(2, "2", "uses === comparator");
|
||||
|
||||
customizedAssert1.throws(() => {
|
||||
throw "a hammer at your face";
|
||||
}, undefined, "DODGED IT");
|
||||
|
||||
customizedAssert1.doesNotThrow(() => {
|
||||
if (false) {
|
||||
throw "a hammer at your face";
|
||||
}
|
||||
}, undefined, "What the...*crunch*");
|
||||
|
||||
|
||||
var customizedAssert2 = assert.customize({
|
||||
assertion: {
|
||||
destructive: false,
|
||||
modifyMessageOnRethrow: true,
|
||||
saveContextOnRethrow: true,
|
||||
patterns: [
|
||||
'assert(value, [message])',
|
||||
'assert.ok(value, [message])',
|
||||
'assert.equal(actual, expected, [message])',
|
||||
'assert.notEqual(actual, expected, [message])',
|
||||
'assert.strictEqual(actual, expected, [message])',
|
||||
'assert.notStrictEqual(actual, expected, [message])',
|
||||
'assert.deepEqual(actual, expected, [message])',
|
||||
'assert.notDeepEqual(actual, expected, [message])'
|
||||
]
|
||||
},
|
||||
output: {
|
||||
lineDiffThreshold: 5,
|
||||
maxDepth: 1,
|
||||
anonymous: 'Object',
|
||||
circular: '#@Circular#',
|
||||
lineSeparator: '\n',
|
||||
ambiguousEastAsianCharWidth: 2,
|
||||
widthOf: () => null,
|
||||
stringify: () => null,
|
||||
diff: () => null,
|
||||
writerClass: null,
|
||||
renderers: [
|
||||
'./built-in/file',
|
||||
'./built-in/assertion',
|
||||
'./built-in/diagram',
|
||||
'./built-in/binary-expression'
|
||||
]
|
||||
}
|
||||
});
|
||||
Vendored
+66
@@ -0,0 +1,66 @@
|
||||
// Type definitions for power-assert
|
||||
// Project: https://github.com/twada/power-assert
|
||||
// Definitions by: vvakame <https://github.com/vvakame>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
// copy from assert external module in node.d.ts
|
||||
|
||||
/// <reference path="../empower/empower.d.ts" />
|
||||
/// <reference path="../power-assert-formatter/power-assert-formatter.d.ts" />
|
||||
|
||||
declare function assert(value:any, message?:string):void;
|
||||
declare module assert {
|
||||
export class AssertionError implements Error {
|
||||
name:string;
|
||||
message:string;
|
||||
actual:any;
|
||||
expected:any;
|
||||
operator:string;
|
||||
generatedMessage:boolean;
|
||||
|
||||
constructor(options?:{message?: string; actual?: any; expected?: any; operator?: string; stackStartFunction?: Function});
|
||||
}
|
||||
|
||||
export function fail(actual?:any, expected?:any, message?:string, operator?:string):void;
|
||||
|
||||
export function ok(value:any, message?:string):void;
|
||||
|
||||
export function equal(actual:any, expected:any, message?:string):void;
|
||||
|
||||
export function notEqual(actual:any, expected:any, message?:string):void;
|
||||
|
||||
export function deepEqual(actual:any, expected:any, message?:string):void;
|
||||
|
||||
export function notDeepEqual(acutal:any, expected:any, message?:string):void;
|
||||
|
||||
export function strictEqual(actual:any, expected:any, message?:string):void;
|
||||
|
||||
export function notStrictEqual(actual:any, expected:any, message?:string):void;
|
||||
|
||||
export var throws:{
|
||||
(block:Function, message?:string): void;
|
||||
(block:Function, error:Function, message?:string): void;
|
||||
(block:Function, error:RegExp, message?:string): void;
|
||||
(block:Function, error:(err:any) => boolean, message?:string): void;
|
||||
};
|
||||
|
||||
export var doesNotThrow:{
|
||||
(block:Function, message?:string): void;
|
||||
(block:Function, error:Function, message?:string): void;
|
||||
(block:Function, error:RegExp, message?:string): void;
|
||||
(block:Function, error:(err:any) => boolean, message?:string): void;
|
||||
};
|
||||
|
||||
export function ifError(value:any):void;
|
||||
|
||||
export interface Options {
|
||||
assertion?: empower.Options;
|
||||
output?: powerAssertFormatter.Options;
|
||||
}
|
||||
|
||||
export function customize(options:Options):typeof assert;
|
||||
}
|
||||
|
||||
declare module "power-assert" {
|
||||
export = assert;
|
||||
}
|
||||
Reference in New Issue
Block a user