@@ -18,74 +18,52 @@ function Test() {
1818 }
1919 for ( let i = 0 ; i < cases . length ; i ++ ) {
2020 const testCase = cases [ i ] ;
21+ var sub0 = String ( testCase . fn ) ;
22+ var sub1 = sub0 . indexOf ( 'assert(' ) ;
23+ var sub = sub0 . substring ( sub1 , sub0 . lastIndexOf ( ')' ) + 1 ) ;
2124 const describeText = testCase . description . split ( " - " ) [ 0 ] ;
22- const itText = testCase . description . split ( " - " ) [ 1 ] ;
2325 if ( currentDescribe !== describeText ) {
2426 currentDescribe = describeText ;
2527 const groupHeader = document . createElement ( "h2" ) ;
26- setTextContent ( groupHeader , currentDescribe ) ;
28+ setTextContent ( groupHeader , currentDescription ) ;
2729 resultsContainer . appendChild ( groupHeader ) ;
2830 }
2931 const resultElement = document . createElement ( "p" ) ;
3032 try {
3133 testCase . fn ( ) ;
32- setTextContent ( resultElement , getPassSymbol ( ) + ` ${ itText } ` ) ;
34+ setTextContent ( resultElement , ` ${ sub } ` ) ;
3335 resultElement . style . color = "green" ;
3436 } catch ( error ) {
35- setTextContent ( resultElement , getFailSymbol ( ) + ` ${ itText } - ${ error . message } ` ) ;
37+ setTextContent ( resultElement , ` ${ sub } - ${ error . message } ` ) ;
3638 resultElement . style . color = "red" ;
3739 }
3840 resultsContainer . appendChild ( resultElement ) ;
3941 }
4042 return ;
4143 } else {
44+ console . group ( currentDescription )
4245 for ( let i = 0 ; i < cases . length ; i ++ ) {
4346 var testCase = cases [ i ] ;
44- if ( currentDescribe !== testCase . description . split ( " - " ) [ 0 ] ) {
45- if ( currentDescribe !== null && typeof console !== 'undefined' ) {
46- console . groupEnd ( ) ;
47- }
48- currentDescribe = testCase . description . split ( " - " ) [ 0 ] ;
49- if ( typeof console !== 'undefined' ) {
50- console . group ( currentDescribe ) ;
51- }
52- }
47+ var sub0 = String ( testCase . fn ) ;
48+ var sub1 = sub0 . indexOf ( 'assert(' ) ;
49+ var sub = sub0 . substring ( sub1 , sub0 . lastIndexOf ( ')' ) + 1 ) ;
5350 try {
5451 testCase . fn ( ) ;
55- if ( typeof console !== 'undefined' ) {
56- console . log ( '\x1b[32m' + getPassSymbol ( ) + ' ' + testCase . description + '\x1b[0m' ) ;
57- }
52+ console . log ( '\x1b[32m' + sub + '\x1b[0m' ) ;
5853 } catch ( error ) {
59- if ( typeof console !== 'undefined' ) {
60- console . error (
61- '\x1b[31m' + getFailSymbol ( ) + ' ' + testCase . description + ' - ' + error . message + '\x1b[0m'
62- ) ;
63- }
54+ console . error ( '\x1b[31m' + sub + ' - ' + error . message + '\x1b[0m' ) ;
6455 }
6556 }
66- if ( currentDescribe !== null && typeof console !== 'undefined' ) {
67- console . groupEnd ( ) ;
68- }
57+ console . groupEnd ( )
6958 }
7059 }
71-
72- // Helper function to set text content
7360 function setTextContent ( element , text ) {
7461 if ( typeof element . textContent !== 'undefined' ) {
7562 element . textContent = text ;
7663 } else {
7764 element . innerText = text ;
7865 }
7966 }
80-
81- function getPassSymbol ( ) {
82- return '>' ;
83- }
84-
85- function getFailSymbol ( ) {
86- return '!' ;
87- }
88-
8967 function deepCompare ( obj1 , obj2 ) {
9068 if (
9169 typeof obj1 !== "object" ||
@@ -95,32 +73,27 @@ function Test() {
9573 ) {
9674 return obj1 === obj2 ;
9775 }
98-
9976 var keys1 = [ ] ;
10077 for ( var key in obj1 ) {
10178 if ( Object . prototype . hasOwnProperty . call ( obj1 , key ) ) {
10279 keys1 . push ( key ) ;
10380 }
10481 }
105-
10682 var keys2 = [ ] ;
10783 for ( var key in obj2 ) {
10884 if ( Object . prototype . hasOwnProperty . call ( obj2 , key ) ) {
10985 keys2 . push ( key ) ;
11086 }
11187 }
112-
11388 if ( keys1 . length !== keys2 . length ) {
11489 return false ;
11590 }
116-
11791 for ( var i = 0 ; i < keys1 . length ; i ++ ) {
11892 var key = keys1 [ i ] ;
11993 if ( ! Object . prototype . hasOwnProperty . call ( obj2 , key ) || ! deepCompare ( obj1 [ key ] , obj2 [ key ] ) ) {
12094 return false ;
12195 }
12296 }
123-
12497 return true ;
12598 }
12699 function describe ( description , fn ) {
@@ -130,17 +103,21 @@ function Test() {
130103 run ( ) ;
131104 }
132105 function it ( description , fn ) {
133- cases . push ( { description : currentDescription + " - " + description , fn } ) ;
106+ if ( arguments . length === 1 ) {
107+ fn = arguments [ 0 ] ;
108+ }
109+ cases . push ( { description : '' , fn } ) ;
134110 }
135111 function assert ( condition , message ) {
112+ message = 'Fail: ' ;
136113 if ( typeof window !== "undefined" ) {
137114 if ( typeof condition === 'object' && condition !== null && typeof condition . length === 'number' && condition . length === 2 ) {
138115 if ( ! deepCompare ( condition [ 0 ] , condition [ 1 ] ) ) {
139116 throw new Error (
140117 message +
141- ' Expected ' + JSON . stringify (
142- condition [ 0 ]
143- ) + ' equals ' + JSON . stringify ( condition [ 1 ] )
118+ ' Expected ' + JSON . stringify (
119+ condition [ 0 ]
120+ ) + ' equals ' + JSON . stringify ( condition [ 1 ] )
144121 ) ;
145122 }
146123 } else {
@@ -153,9 +130,9 @@ function Test() {
153130 if ( ! deepCompare ( condition [ 0 ] , condition [ 1 ] ) ) {
154131 throw new Error (
155132 message +
156- ' Expected ' + JSON . stringify (
157- condition [ 0 ]
158- ) + ' equals ' + JSON . stringify ( condition [ 1 ] )
133+ ' Expected ' + JSON . stringify (
134+ condition [ 0 ]
135+ ) + ' equals ' + JSON . stringify ( condition [ 1 ] )
159136 ) ;
160137 }
161138 } else {
@@ -165,9 +142,7 @@ function Test() {
165142 }
166143 }
167144 }
168-
169145 return { describe, it, assert } ;
170146}
171147
172-
173148module . exports = Test
0 commit comments