Skip to content

Commit

Permalink
[node]: Update assert.fail parameters (DefinitelyTyped#27622)
Browse files Browse the repository at this point in the history
[assert.fail](https://nodejs.org/api/assert.html#assert_assert_fail_message)
has an optional `message` parameter that can be either a `string` or `Error`.
  • Loading branch information
eyqs authored and Andy committed Aug 6, 2018
1 parent e53465f commit f9dcdec
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 201 deletions.
61 changes: 29 additions & 32 deletions types/node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// Lishude <https://github.com/islishude>
// Andrew Makarov <https://github.com/r3nya>
// Zane Hannan AU <https://github.com/ZaneHannanAU>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/** inspector module types */
Expand Down Expand Up @@ -6381,7 +6382,7 @@ declare module "util" {
}

declare module "assert" {
function internal(value: any, message?: string): void;
function internal(value: any, message?: string | Error): void;
namespace internal {
export class AssertionError implements Error {
name: string;
Expand All @@ -6390,46 +6391,42 @@ declare module "assert" {
expected: any;
operator: string;
generatedMessage: boolean;
code: 'ERR_ASSERTION';

constructor(options?: {
message?: string; actual?: any; expected?: any;
operator?: string; stackStartFunction?: Function
operator?: string; stackStartFn?: Function
});
}

export function fail(message: string): never;
/** @deprecated since v10.0.0 */
export function fail(actual: any, expected: any, message?: string, operator?: string): never;
export function ok(value: any, message?: string): void;
/** @deprecated use strictEqual() */
export function equal(actual: any, expected: any, message?: string): void;
/** @deprecated use notStrictEqual() */
export function notEqual(actual: any, expected: any, message?: string): void;
/** @deprecated use deepStrictEqual() */
export function deepEqual(actual: any, expected: any, message?: string): void;
/** @deprecated use notDeepStrictEqual() */
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 function deepStrictEqual(actual: any, expected: any, message?: string): void;
export function notDeepStrictEqual(actual: any, expected: any, message?: string): void;

export function throws(block: Function, message?: string): void;
export function throws(block: Function, error: Function, message?: string): void;
export function throws(block: Function, error: RegExp, message?: string): void;
export function throws(block: Function, error: (err: any) => boolean, message?: string): void;

export function doesNotThrow(block: Function, message?: string): void;
export function doesNotThrow(block: Function, error: Function, message?: string): void;
export function doesNotThrow(block: Function, error: RegExp, message?: string): void;
export function doesNotThrow(block: Function, error: (err: any) => boolean, message?: string): void;
export function fail(message?: string | Error): never;
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
export function fail(actual: any, expected: any, message?: string | Error, operator?: string, stackStartFn?: Function): never;
export function ok(value: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use strictEqual() instead. */
export function equal(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notStrictEqual() instead. */
export function notEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
export function deepEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
export function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
export function strictEqual(actual: any, expected: any, message?: string | Error): void;
export function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
export function deepStrictEqual(actual: any, expected: any, message?: string | Error): void;
export function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;

export function throws(block: Function, message?: string | Error): void;
export function throws(block: Function, error: RegExp | Function | Object | Error, message?: string | Error): void;
export function doesNotThrow(block: Function, message?: string | Error): void;
export function doesNotThrow(block: Function, error: RegExp | Function, message?: string | Error): void;

export function ifError(value: any): void;

export function rejects(block: Function | Promise<any>, message?: string): Promise<void>;
export function rejects(block: Function | Promise<any>, error: Function | RegExp | Object | Error, message?: string): Promise<void>;
export function doesNotReject(block: Function | Promise<any>, message?: string): Promise<void>;
export function doesNotReject(block: Function | Promise<any>, error: Function | RegExp | Object | Error, message?: string): Promise<void>;
export function rejects(block: Function | Promise<any>, message?: string | Error): Promise<void>;
export function rejects(block: Function | Promise<any>, error: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;
export function doesNotReject(block: Function | Promise<any>, message?: string | Error): Promise<void>;
export function doesNotReject(block: Function | Promise<any>, error: RegExp | Function, message?: string | Error): Promise<void>;

export var strict: typeof internal;
}
Expand Down
94 changes: 44 additions & 50 deletions types/node/v0/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,42 +573,42 @@ declare module "http" {
*/
export interface ClientResponse extends IncomingMessage { }

export interface AgentOptions {
/**
* Keep sockets around in a pool to be used by other requests in the future. Default = false
*/
keepAlive?: boolean;
/**
* When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
* Only relevant if keepAlive is set to true.
*/
keepAliveMsecs?: number;
/**
* Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
*/
maxSockets?: number;
/**
* Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
*/
maxFreeSockets?: number;
}
export interface AgentOptions {
/**
* Keep sockets around in a pool to be used by other requests in the future. Default = false
*/
keepAlive?: boolean;
/**
* When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
* Only relevant if keepAlive is set to true.
*/
keepAliveMsecs?: number;
/**
* Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
*/
maxSockets?: number;
/**
* Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
*/
maxFreeSockets?: number;
}

export class Agent {
maxFreeSockets: number;
maxSockets: number;
sockets: any;
requests: any;

constructor(opts?: AgentOptions);

/**
* Destroy any sockets that are currently in use by the agent.
* It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled,
* then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise,
* sockets may hang open for quite a long time before the server terminates them.
*/
destroy(): void;
}
maxFreeSockets: number;
maxSockets: number;
sockets: any;
requests: any;

constructor(opts?: AgentOptions);

/**
* Destroy any sockets that are currently in use by the agent.
* It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled,
* then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise,
* sockets may hang open for quite a long time before the server terminates them.
*/
destroy(): void;
}

export var METHODS: string[];

Expand Down Expand Up @@ -1858,7 +1858,7 @@ declare module "util" {
}

declare module "assert" {
function internal (value: any, message?: string): void;
function internal(value: any, message?: string): void;
namespace internal {
export class AssertionError implements Error {
name: string;
Expand All @@ -1868,31 +1868,25 @@ declare module "assert" {
operator: string;
generatedMessage: boolean;

constructor(options?: {message?: string; actual?: any; expected?: any;
operator?: string; stackStartFunction?: Function});
constructor(options?: {
message?: string; actual?: any; expected?: any;
operator?: string; stackStartFn?: Function
});
}

export function fail(actual?: any, expected?: any, message?: string, operator?: string): never;
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 notDeepEqual(actual: 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 throws(block: Function, message?: string): void;
export function throws(block: Function, error: RegExp | Function, message?: string): void;
export function doesNotThrow(block: Function, message?: string): void;
export function doesNotThrow(block: Function, error: RegExp | Function, message?: string): void;

export function ifError(value: any): void;
}
Expand Down
58 changes: 29 additions & 29 deletions types/node/v0/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,37 +179,37 @@ function stream_readable_pipe_test() {
var hmacResult: string = crypto.createHmac('md5', 'hello').update('world').digest('hex');

function crypto_cipher_decipher_string_test() {
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
var clearText:string = "This is the clear text.";
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
var cipherText:string = cipher.update(clearText, "utf8", "hex");
cipherText += cipher.final("hex");
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
var clearText:string = "This is the clear text.";
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
var cipherText:string = cipher.update(clearText, "utf8", "hex");
cipherText += cipher.final("hex");

var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
var clearText2:string = decipher.update(cipherText, "hex", "utf8");
clearText2 += decipher.final("utf8");
var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
var clearText2:string = decipher.update(cipherText, "hex", "utf8");
clearText2 += decipher.final("utf8");

assert.equal(clearText2, clearText);
assert.equal(clearText2, clearText);
}

function crypto_cipher_decipher_buffer_test() {
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
var clearText:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4]);
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
var cipherBuffers:Buffer[] = [];
cipherBuffers.push(cipher.update(clearText));
cipherBuffers.push(cipher.final());
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
var clearText:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4]);
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
var cipherBuffers:Buffer[] = [];
cipherBuffers.push(cipher.update(clearText));
cipherBuffers.push(cipher.final());

var cipherText:Buffer = Buffer.concat(cipherBuffers);
var cipherText:Buffer = Buffer.concat(cipherBuffers);

var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
var decipherBuffers:Buffer[] = [];
decipherBuffers.push(decipher.update(cipherText));
decipherBuffers.push(decipher.final());
var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
var decipherBuffers:Buffer[] = [];
decipherBuffers.push(decipher.update(cipherText));
decipherBuffers.push(decipher.final());

var clearText2:Buffer = Buffer.concat(decipherBuffers);
var clearText2:Buffer = Buffer.concat(decipherBuffers);

assert.deepEqual(clearText2, clearText);
assert.deepEqual(clearText2, clearText);
}

////////////////////////////////////////////////////
Expand Down Expand Up @@ -242,14 +242,14 @@ namespace http_tests {
var codeMessage = http.STATUS_CODES['400'];
var codeMessage = http.STATUS_CODES[400];

var agent: http.Agent = new http.Agent({
keepAlive: true,
keepAliveMsecs: 10000,
maxSockets: Infinity,
maxFreeSockets: 256
});
var agent: http.Agent = new http.Agent({
keepAlive: true,
keepAliveMsecs: 10000,
maxSockets: Infinity,
maxFreeSockets: 256
});

var agent: http.Agent = http.globalAgent;
var agent: http.Agent = http.globalAgent;

http.request('http://www.example.com/xyz');
}
Expand Down
19 changes: 8 additions & 11 deletions types/node/v4/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,7 @@ declare module "util" {
}

declare module "assert" {
function internal (value: any, message?: string): void;
function internal(value: any, message?: string): void;
namespace internal {
export class AssertionError implements Error {
name: string;
Expand All @@ -2450,30 +2450,27 @@ declare module "assert" {
operator: string;
generatedMessage: boolean;

constructor(options?: {message?: string; actual?: any; expected?: any;
operator?: string; stackStartFunction?: Function});
constructor(options?: {
message?: string; actual?: any; expected?: any;
operator?: string; stackStartFn?: Function
});
}

export function fail(actual: any, expected: any, message?: string, operator?: string): never;
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 notDeepEqual(actual: 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 function deepStrictEqual(actual: any, expected: any, message?: string): void;
export function notDeepStrictEqual(actual: any, expected: any, message?: string): void;

export function throws(block: Function, message?: string): void;
export function throws(block: Function, error: Function, message?: string): void;
export function throws(block: Function, error: RegExp, message?: string): void;
export function throws(block: Function, error: (err: any) => boolean, message?: string): void;

export function throws(block: Function, error: RegExp | Function, message?: string): void;
export function doesNotThrow(block: Function, message?: string): void;
export function doesNotThrow(block: Function, error: Function, message?: string): void;
export function doesNotThrow(block: Function, error: RegExp, message?: string): void;
export function doesNotThrow(block: Function, error: (err: any) => boolean, message?: string): void;
export function doesNotThrow(block: Function, error: RegExp | Function, message?: string): void;

export function ifError(value: any): void;
}
Expand Down
16 changes: 6 additions & 10 deletions types/node/v6/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3944,30 +3944,26 @@ declare module "assert" {

constructor(options?: {
message?: string; actual?: any; expected?: any;
operator?: string; stackStartFunction?: Function
operator?: string; stackStartFn?: Function
});
}

export function fail(actual: any, expected: any, message?: string, operator?: string): never;
export function fail(message?: string): never;
export function fail(actual: any, expected: any, message?: string, operator?: string, stackStartFn?: Function): never;
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 notDeepEqual(actual: 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 function deepStrictEqual(actual: any, expected: any, message?: string): void;
export function notDeepStrictEqual(actual: any, expected: any, message?: string): void;

export function throws(block: Function, message?: string): void;
export function throws(block: Function, error: Function, message?: string): void;
export function throws(block: Function, error: RegExp, message?: string): void;
export function throws(block: Function, error: (err: any) => boolean, message?: string): void;

export function throws(block: Function, error: RegExp | Function, message?: string): void;
export function doesNotThrow(block: Function, message?: string): void;
export function doesNotThrow(block: Function, error: Function, message?: string): void;
export function doesNotThrow(block: Function, error: RegExp, message?: string): void;
export function doesNotThrow(block: Function, error: (err: any) => boolean, message?: string): void;
export function doesNotThrow(block: Function, error: RegExp | Function, message?: string): void;

export function ifError(value: any): void;
}
Expand Down
Loading

0 comments on commit f9dcdec

Please sign in to comment.