From 1ad5088e0382f0fa0b7c9333dc3ef9c75fd9ad64 Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Wed, 10 Mar 2021 11:25:06 -0800 Subject: [PATCH] Add strict mode assert typedefs Summary: Closes https://github.com/facebook/flow/issues/7217 Revived https://github.com/facebook/flow/pull/7401 https://nodejs.org/api/assert.html#assert_strict_mode Pull Request resolved: https://github.com/facebook/flow/pull/7660 Reviewed By: mroch Differential Revision: D26887564 Pulled By: nmote fbshipit-source-id: f9713814b0628efba3d0d8797b64a1682be0effe --- lib/node.js | 22 +++++++++++ tests/node_tests/node_tests.exp | 66 ++++++++++++++++----------------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/lib/node.js b/lib/node.js index e516c69fc8b..22fd1f3c1ea 100644 --- a/lib/node.js +++ b/lib/node.js @@ -2648,6 +2648,27 @@ declare module "zlib" { declare module "assert" { declare class AssertionError extends Error {} + declare type AssertStrict = { + (value: any, message?: string): void; + ok(value: any, message?: string): void; + fail(message?: string | Error): void; + // deprecated since v10.15 + fail(actual: any, expected: any, message: string, operator: string): void; + equal(actual: any, expected: any, message?: string): void; + notEqual(actual: any, expected: any, message?: string): void; + deepEqual(actual: any, expected: any, message?: string): void; + notDeepEqual(actual: any, expected: any, message?: string): void; + throws( + block: Function, + error?: Function | RegExp | (err: any) => boolean, + message?: string + ): void; + doesNotThrow(block: Function, message?: string): void; + ifError(value: any): void; + AssertionError: typeof AssertionError; + strict: AssertStrict; + ... + } declare module.exports: { (value: any, message?: string): void, ok(value: any, message?: string): void, @@ -2670,6 +2691,7 @@ declare module "assert" { doesNotThrow(block: Function, message?: string): void, ifError(value: any): void, AssertionError: typeof AssertionError, + strict: AssertStrict; ... } } diff --git a/tests/node_tests/node_tests.exp b/tests/node_tests/node_tests.exp index bbabba2c840..036051c7208 100644 --- a/tests/node_tests/node_tests.exp +++ b/tests/node_tests/node_tests.exp @@ -1636,26 +1636,26 @@ References: process/emitWarning.js:10:1 10| process.emitWarning(); // error ^^^^^^^^^^^^^^^^^^^^^ [1] - /node.js:2771:24 - 2771| emitWarning(warning: string | Error): void; + /node.js:2793:24 + 2793| emitWarning(warning: string | Error): void; ^^^^^^ [2] - /node.js:2771:33 - 2771| emitWarning(warning: string | Error): void; + /node.js:2793:33 + 2793| emitWarning(warning: string | Error): void; ^^^^^ [3] - /node.js:2772:3 - 2772| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void; + /node.js:2794:3 + 2794| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [4] - /node.js:2773:3 - 2773| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void; + /node.js:2795:3 + 2795| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [5] - /node.js:2774:3 + /node.js:2796:3 v----------- - 2774| emitWarning( - 2775| warning: string, - 2776| type: string, - 2777| code: string, - 2778| ctor?: (...empty) => mixed - 2779| ): void; + 2796| emitWarning( + 2797| warning: string, + 2798| type: string, + 2799| code: string, + 2800| ctor?: (...empty) => mixed + 2801| ): void; ------^ [6] @@ -1674,14 +1674,14 @@ References: process/emitWarning.js:11:21 11| process.emitWarning(42); // error ^^ [1] - /node.js:2772:24 - 2772| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void; + /node.js:2794:24 + 2794| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void; ^^^^^^ [2] - /node.js:2773:24 - 2773| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void; + /node.js:2795:24 + 2795| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void; ^^^^^^ [3] - /node.js:2775:14 - 2775| warning: string, + /node.js:2797:14 + 2797| warning: string, ^^^^^^ [4] @@ -1699,11 +1699,11 @@ References: process/emitWarning.js:12:29 12| process.emitWarning("blah", 42); // error ^^ [1] - /node.js:2773:38 - 2773| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void; + /node.js:2795:38 + 2795| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void; ^^^^^^ [2] - /node.js:2776:11 - 2776| type: string, + /node.js:2798:11 + 2798| type: string, ^^^^^^ [3] @@ -1719,8 +1719,8 @@ References: process/emitWarning.js:13:37 13| process.emitWarning("blah", "blah", 42); // error ^^ [1] - /node.js:2777:11 - 2777| code: string, + /node.js:2799:11 + 2799| code: string, ^^^^^^ [2] @@ -1734,8 +1734,8 @@ Cannot cast `process.emitWarning(...)` to string because undefined [1] is incomp ^^^^^^^^^^^^^^^^^^^^^^^^^^^ References: - /node.js:2771:41 - 2771| emitWarning(warning: string | Error): void; + /node.js:2793:41 + 2793| emitWarning(warning: string | Error): void; ^^^^ [1] process/emitWarning.js:14:31 14| (process.emitWarning("blah"): string); // error @@ -1800,8 +1800,8 @@ References: process/nextTick.js:27:3 27| (a: string, b: number, c: boolean) => {} // Error: too few arguments ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - /node.js:2800:21 - 2800| nextTick: (cb: (...T) => mixed, ...T) => void; + /node.js:2822:21 + 2822| nextTick: (cb: (...T) => mixed, ...T) => void; ^^^^^^^^^^^^^^^ [2] @@ -1815,8 +1815,8 @@ Cannot cast `process.allowedNodeEnvironmentFlags` to string because `Set` [1] is ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ References: - /node.js:2760:32 - 2760| allowedNodeEnvironmentFlags: Set; + /node.js:2782:32 + 2782| allowedNodeEnvironmentFlags: Set; ^^^^^^^^^^^ [1] process/process.js:5:39 5| (process.allowedNodeEnvironmentFlags: string); // error