@@ -436,43 +436,21 @@ class Assert {
436
436
}
437
437
438
438
/**
439
- * @param {any } actual
440
- * @param {any } expected
441
- * @param {string | Error } [message]
442
- * @param {string } [operator]
443
- * @param {Function } [stackStartFn]
439
+ * Throws an AssertionError with the given message.
440
+ * @param {any | Error } [message]
444
441
*/
445
- fail ( actual , expected , message , operator , stackStartFn ) {
446
- const argsLen = arguments . length ;
442
+ fail ( message ) {
443
+ if ( isError ( message ) ) throw message ;
447
444
448
445
let internalMessage = false ;
449
- if ( actual == null && argsLen <= 1 ) {
450
- internalMessage = true ;
446
+ if ( message === undefined ) {
451
447
message = 'Failed' ;
452
- } else if ( argsLen === 1 ) {
453
- message = actual ;
454
- actual = undefined ;
455
- } else {
456
- if ( warned === false ) {
457
- warned = true ;
458
- process . emitWarning (
459
- 'assert.fail() with more than one argument is deprecated. ' +
460
- 'Please use assert.strictEqual() instead or only pass a message.' ,
461
- 'DeprecationWarning' ,
462
- 'DEP0094' ,
463
- ) ;
464
- }
465
- if ( argsLen === 2 )
466
- operator = '!=' ;
448
+ internalMessage = true ;
467
449
}
468
450
469
- if ( message instanceof Error ) throw message ;
470
-
471
451
const errArgs = {
472
- actual,
473
- expected,
474
- operator : operator === undefined ? 'fail' : operator ,
475
- stackStartFn : stackStartFn || this . fail ,
452
+ operator : 'fail' ,
453
+ stackStartFn : this . fail ,
476
454
message,
477
455
} ;
478
456
const err = new AssertionError ( errArgs ) ;
@@ -837,292 +815,6 @@ function ok(...args) {
837
815
ObjectAssign ( assert , assertInstance ) ;
838
816
assert . ok = ok ;
839
817
840
- // All of the following functions must throw an AssertionError
841
- // when a corresponding condition is not met, with a message that
842
- // may be undefined if not provided. All assertion methods provide
843
- // both the actual and expected values to the assertion error for
844
- // display purposes.
845
-
846
- function innerFail ( obj ) {
847
- if ( obj . message instanceof Error ) throw obj . message ;
848
-
849
- throw new AssertionError ( obj ) ;
850
- }
851
-
852
- /**
853
- * Throws an AssertionError with the given message.
854
- * @param {any | Error } [message]
855
- */
856
- function fail ( message ) {
857
- if ( isError ( message ) ) throw message ;
858
-
859
- let internalMessage = false ;
860
- if ( message === undefined ) {
861
- message = 'Failed' ;
862
- internalMessage = true ;
863
- }
864
-
865
- const errArgs = {
866
- operator : 'fail' ,
867
- stackStartFn : fail ,
868
- message,
869
- } ;
870
- const err = new AssertionError ( errArgs ) ;
871
- if ( internalMessage ) {
872
- err . generatedMessage = true ;
873
- }
874
- throw err ;
875
- }
876
-
877
- assert . fail = fail ;
878
-
879
- // The AssertionError is defined in internal/error.
880
- assert . AssertionError = AssertionError ;
881
-
882
- /**
883
- * Pure assertion tests whether a value is truthy, as determined
884
- * by !!value.
885
- * @param {...any } args
886
- * @returns {void }
887
- */
888
- function ok ( ...args ) {
889
- innerOk ( ok , args . length , ...args ) ;
890
- }
891
- assert . ok = ok ;
892
-
893
- /**
894
- * The equality assertion tests shallow, coercive equality with ==.
895
- * @param {any } actual
896
- * @param {any } expected
897
- * @param {string | Error } [message]
898
- * @returns {void }
899
- */
900
- /* eslint-disable no-restricted-properties */
901
- assert . equal = function equal ( actual , expected , message ) {
902
- if ( arguments . length < 2 ) {
903
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
904
- }
905
- // eslint-disable-next-line eqeqeq
906
- if ( actual != expected && ( ! NumberIsNaN ( actual ) || ! NumberIsNaN ( expected ) ) ) {
907
- innerFail ( {
908
- actual,
909
- expected,
910
- message,
911
- operator : '==' ,
912
- stackStartFn : equal ,
913
- } ) ;
914
- }
915
- } ;
916
-
917
- /**
918
- * The non-equality assertion tests for whether two objects are not
919
- * equal with !=.
920
- * @param {any } actual
921
- * @param {any } expected
922
- * @param {string | Error } [message]
923
- * @returns {void }
924
- */
925
- assert . notEqual = function notEqual ( actual , expected , message ) {
926
- if ( arguments . length < 2 ) {
927
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
928
- }
929
- // eslint-disable-next-line eqeqeq
930
- if ( actual == expected || ( NumberIsNaN ( actual ) && NumberIsNaN ( expected ) ) ) {
931
- innerFail ( {
932
- actual,
933
- expected,
934
- message,
935
- operator : '!=' ,
936
- stackStartFn : notEqual ,
937
- } ) ;
938
- }
939
- } ;
940
-
941
- /**
942
- * The deep equivalence assertion tests a deep equality relation.
943
- * @param {any } actual
944
- * @param {any } expected
945
- * @param {string | Error } [message]
946
- * @returns {void }
947
- */
948
- assert . deepEqual = function deepEqual ( actual , expected , message ) {
949
- if ( arguments . length < 2 ) {
950
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
951
- }
952
- if ( isDeepEqual === undefined ) lazyLoadComparison ( ) ;
953
- if ( ! isDeepEqual ( actual , expected ) ) {
954
- innerFail ( {
955
- actual,
956
- expected,
957
- message,
958
- operator : 'deepEqual' ,
959
- stackStartFn : deepEqual ,
960
- } ) ;
961
- }
962
- } ;
963
-
964
- /**
965
- * The deep non-equivalence assertion tests for any deep inequality.
966
- * @param {any } actual
967
- * @param {any } expected
968
- * @param {string | Error } [message]
969
- * @returns {void }
970
- */
971
- assert . notDeepEqual = function notDeepEqual ( actual , expected , message ) {
972
- if ( arguments . length < 2 ) {
973
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
974
- }
975
- if ( isDeepEqual === undefined ) lazyLoadComparison ( ) ;
976
- if ( isDeepEqual ( actual , expected ) ) {
977
- innerFail ( {
978
- actual,
979
- expected,
980
- message,
981
- operator : 'notDeepEqual' ,
982
- stackStartFn : notDeepEqual ,
983
- } ) ;
984
- }
985
- } ;
986
- /* eslint-enable */
987
-
988
- /**
989
- * The deep strict equivalence assertion tests a deep strict equality
990
- * relation.
991
- * @param {any } actual
992
- * @param {any } expected
993
- * @param {string | Error } [message]
994
- * @returns {void }
995
- */
996
- assert . deepStrictEqual = function deepStrictEqual ( actual , expected , message ) {
997
- if ( arguments . length < 2 ) {
998
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
999
- }
1000
- if ( isDeepEqual === undefined ) lazyLoadComparison ( ) ;
1001
- if ( ! isDeepStrictEqual ( actual , expected ) ) {
1002
- innerFail ( {
1003
- actual,
1004
- expected,
1005
- message,
1006
- operator : 'deepStrictEqual' ,
1007
- stackStartFn : deepStrictEqual ,
1008
- } ) ;
1009
- }
1010
- } ;
1011
-
1012
- /**
1013
- * The deep strict non-equivalence assertion tests for any deep strict
1014
- * inequality.
1015
- * @param {any } actual
1016
- * @param {any } expected
1017
- * @param {string | Error } [message]
1018
- * @returns {void }
1019
- */
1020
- assert . notDeepStrictEqual = notDeepStrictEqual ;
1021
- function notDeepStrictEqual ( actual , expected , message ) {
1022
- if ( arguments . length < 2 ) {
1023
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
1024
- }
1025
- if ( isDeepEqual === undefined ) lazyLoadComparison ( ) ;
1026
- if ( isDeepStrictEqual ( actual , expected ) ) {
1027
- innerFail ( {
1028
- actual,
1029
- expected,
1030
- message,
1031
- operator : 'notDeepStrictEqual' ,
1032
- stackStartFn : notDeepStrictEqual ,
1033
- } ) ;
1034
- }
1035
- }
1036
-
1037
-
1038
- // assert.strictEqual = function strictEqual(actual, expected, message) {
1039
-
1040
- /**
1041
- * The strict non-equivalence assertion tests for any strict inequality.
1042
- * @param {any } actual
1043
- * @param {any } expected
1044
- * @param {string | Error } [message]
1045
- * @returns {void }
1046
- */
1047
- assert . notStrictEqual = function notStrictEqual ( actual , expected , message ) {
1048
- if ( arguments . length < 2 ) {
1049
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
1050
- }
1051
- if ( ObjectIs ( actual , expected ) ) {
1052
- innerFail ( {
1053
- actual,
1054
- expected,
1055
- message,
1056
- operator : 'notStrictEqual' ,
1057
- stackStartFn : notStrictEqual ,
1058
- } ) ;
1059
- }
1060
- } ;
1061
-
1062
- /**
1063
- * The strict equivalence assertion test between two objects
1064
- * @param {any } actual
1065
- * @param {any } expected
1066
- * @param {string | Error } [message]
1067
- * @returns {void }
1068
- */
1069
- assert . partialDeepStrictEqual = function partialDeepStrictEqual (
1070
- actual ,
1071
- expected ,
1072
- message ,
1073
- ) {
1074
- if ( arguments . length < 2 ) {
1075
- throw new ERR_MISSING_ARGS ( 'actual' , 'expected' ) ;
1076
- }
1077
- if ( isDeepEqual === undefined ) lazyLoadComparison ( ) ;
1078
- if ( ! isPartialStrictEqual ( actual , expected ) ) {
1079
- innerFail ( {
1080
- actual,
1081
- expected,
1082
- message,
1083
- operator : 'partialDeepStrictEqual' ,
1084
- stackStartFn : partialDeepStrictEqual ,
1085
- } ) ;
1086
- }
1087
- } ;
1088
-
1089
- class Comparison {
1090
- constructor ( obj , keys , actual ) {
1091
- for ( const key of keys ) {
1092
- if ( key in obj ) {
1093
- if ( actual !== undefined &&
1094
- typeof actual [ key ] === 'string' &&
1095
- isRegExp ( obj [ key ] ) &&
1096
- RegExpPrototypeExec ( obj [ key ] , actual [ key ] ) !== null ) {
1097
- this [ key ] = actual [ key ] ;
1098
- } else {
1099
- this [ key ] = obj [ key ] ;
1100
- }
1101
- }
1102
- }
1103
- }
1104
- }
1105
-
1106
- function hasMatchingError ( actual , expected ) {
1107
- if ( typeof expected !== 'function' ) {
1108
- if ( isRegExp ( expected ) ) {
1109
- const str = String ( actual ) ;
1110
- return RegExpPrototypeExec ( expected , str ) !== null ;
1111
- }
1112
- throw new ERR_INVALID_ARG_TYPE (
1113
- 'expected' , [ 'Function' , 'RegExp' ] , expected ,
1114
- ) ;
1115
- }
1116
- // Guard instanceof against arrow functions as they don't have a prototype.
1117
- if ( expected . prototype !== undefined && actual instanceof expected ) {
1118
- return true ;
1119
- }
1120
- if ( ObjectPrototypeIsPrototypeOf ( Error , expected ) ) {
1121
- return false ;
1122
- }
1123
- return ReflectApply ( expected , { } , [ actual ] ) === true ;
1124
- }
1125
-
1126
818
/**
1127
819
* Expose a strict only variant of assert.
1128
820
* @param {...any } args
0 commit comments