@@ -37,7 +37,7 @@ export function pass(message = "") {
3737}
3838
3939export function fail ( message = "" ) {
40- return new Response ( message , { status : 500 } ) ;
40+ throw new Response ( message , { status : 500 } ) ;
4141}
4242
4343function prettyPrintSymbol ( a ) {
@@ -48,17 +48,27 @@ function prettyPrintSymbol(a) {
4848}
4949export function assert ( actual , expected , code ) {
5050 if ( ! deepEqual ( actual , expected ) ) {
51- return fail (
51+ fail (
5252 `Expected \`${ code } \` to equal \`${ JSON . stringify ( prettyPrintSymbol ( expected ) ) } \` - Found \`${ JSON . stringify ( prettyPrintSymbol ( actual ) ) } \`` ,
5353 ) ;
5454 }
5555}
5656
57+ export { assert as strictEqual }
58+
59+ export function ok ( truthy , code ) {
60+ if ( ! truthy ) {
61+ fail (
62+ `Expected ${ code ? ' ' + code : '' } to be truthy - Found \`${ JSON . stringify ( prettyPrintSymbol ( truthy ) ) } \`` ,
63+ ) ;
64+ }
65+ }
66+
5767export async function assertResolves ( func ) {
5868 try {
5969 await func ( ) ;
6070 } catch ( error ) {
61- return fail (
71+ fail (
6272 `Expected \`${ func . toString ( ) } \` to resolve - Found it rejected: ${ error . name } : ${ error . message } ` ,
6373 ) ;
6474 }
@@ -67,63 +77,65 @@ export async function assertResolves(func) {
6777export async function assertRejects ( func , errorClass , errorMessage ) {
6878 try {
6979 await func ( ) ;
70- return fail (
71- `Expected \`${ func . toString ( ) } \` to reject - Found it did not reject` ,
72- ) ;
7380 } catch ( error ) {
7481 if ( errorClass ) {
7582 if ( error instanceof errorClass === false ) {
76- return fail (
83+ fail (
7784 `Expected \`${ func . toString ( ) } \` to reject instance of \`${ errorClass . name } \` - Found instance of \`${ error . name } \`` ,
7885 ) ;
7986 }
8087 }
8188
8289 if ( errorMessage ) {
8390 if ( error . message !== errorMessage ) {
84- return fail (
91+ fail (
8592 `Expected \`${ func . toString ( ) } \` to reject error message of \`${ errorMessage } \` - Found \`${ error . message } \`` ,
8693 ) ;
8794 }
8895 }
96+
97+ return ;
8998 }
99+ fail ( `Expected \`${ func . toString ( ) } \` to reject - Found it did not reject` ) ;
90100}
91101
92102export function assertThrows ( func , errorClass , errorMessage ) {
93103 try {
94104 func ( ) ;
95- return fail (
96- `Expected \`${ func . toString ( ) } \` to throw - Found it did not throw` ,
97- ) ;
98105 } catch ( error ) {
99106 if ( errorClass ) {
100107 if ( error instanceof errorClass === false ) {
101- return fail (
108+ fail (
102109 `Expected \`${ func . toString ( ) } \` to throw instance of \`${ errorClass . name } \` - Found instance of \`${ error . name } \`: ${ error . message } \n${ error . stack } ` ,
103110 ) ;
104111 }
105112 }
106113
107114 if ( errorMessage ) {
108115 if ( error . message !== errorMessage ) {
109- return fail (
116+ fail (
110117 `Expected \`${ func . toString ( ) } \` to throw error message of \`${ errorMessage } \` - Found \`${ error . message } \`` ,
111118 ) ;
112119 }
113120 }
121+
122+ return ;
114123 }
124+ fail ( `Expected \`${ func . toString ( ) } \` to throw - Found it did not throw` ) ;
115125}
116126
117127export function assertDoesNotThrow ( func ) {
118128 try {
119129 func ( ) ;
120130 } catch ( error ) {
121- return fail (
131+ fail (
122132 `Expected \`${ func . toString ( ) } \` to not throw - Found it did throw: ${ error . name } : ${ error . message } ` ,
123133 ) ;
124134 }
125135}
126136
137+ export { deepEqual as deepStrictEqual }
138+
127139export function deepEqual ( a , b ) {
128140 var aKeys ;
129141 var bKeys ;
0 commit comments