11class EyeJS {
2- constructor ( ) {
3- this . data = {
4- "tested" : 0 ,
5- "failed" : 0 ,
6- "warn" : 0 ,
7- "result" : 0
8- } ;
9- }
10- checkout ( ) {
11- this . data . result = this . data . failed == 0 ? 1 : 0 ;
12- this . data . result = this . data . warn == 0 ? this . data . result : 3 ;
13- const request = new XMLHttpRequest ( ) ;
14- request . open ( "GET" , `/post/?result=${ this . data . result } &failed=${ this . data . failed } ` , true ) ;
15- request . setRequestHeader ( "Content-Type" , "application/x-www-form-urlencoded; charset=UTF-8" ) ;
16- request . onload = ( ) => {
17- if ( request . status >= 200 && request . status < 400 ) {
18- const data = request . responseText ;
19- if ( data == 'sucess' ) {
20- window . open ( '' , '_self' ) . close ( ) ;
21- }
22- } else {
23- console . error ( "EyeJS error: The ajax request loaded, but returned an error." ) ;
24- }
25- } ;
26- request . onerror = ( ) => {
27- // There was a connection error of some sort
28- console . error ( "EyeJS error: The ajax request returned an error." ) ;
29- } ;
30- request . send ( ) ;
31- }
32- test ( ) {
33- const $ = $ => {
34- class expect {
35- constructor ( val ) {
36- this . val = val
37- }
38- Equal ( val , not ) {
39- if ( ( JSON . stringify ( val ) == JSON . stringify ( this . val ) && not != false ) || ( not == false && JSON . stringify ( val ) != JSON . stringify ( this . val ) ) ) {
40- return true ;
41- } else {
42- return `${ this . val } isn't equal to ${ val } `
43- }
44- }
45- hasProperty ( name , not ) {
46- if ( ( this . val . hasOwnProperty ( name ) && not != false ) || ( not == false && ! this . val . hasOwnProperty ( name ) ) ) {
47- return true ;
48- } else {
49- return `${ this . val } doesn't have '${ name } ' as property`
50- }
51- }
52- includes ( val , not ) {
53- if ( ( this . val . includes ( val ) && not != false ) || ( not == false && ! this . val . includes ( val ) ) ) {
54- return true ;
55- } else {
56- return `${ this . val } doesn't includes ${ val } `
57- }
58- }
59- is ( type , not ) {
60- if ( ( typeof this . val == type && not != false ) || ( not == false && typeof this . val != type ) ) {
61- return true ;
62- } else {
63- return `${ this . val } isn't a ${ type } `
64- }
65- }
66- isCloseTo ( actual , precision = 2 , not ) {
67- if ( ( Math . abs ( this . val - actual ) < Math . pow ( 10 , - precision ) / 2 && not != false ) || ( not == false && ! ( Math . abs ( this . val - actual ) < Math . pow ( 10 , - precision ) / 2 ) ) ) {
68- return true ;
69- } else {
70- return `${ this . val } isn't close to ${ actual } , with a precision of ${ precision } `
71- }
72- }
73- isLarger ( val , not ) {
74- if ( ( this . val > val && not != false ) || ( not == false && ! ( this . val > val ) ) ) {
75- return true ;
76- } else {
77- return `${ this . val } isn't larger than ${ actual } `
78- }
79- }
80- isSmaller ( val , not ) {
81- if ( ( this . val < val && not != false ) || ( not == false && ! ( this . val < val ) ) ) {
82- return true ;
83- } else {
84- return `${ this . val } isn't smaller than ${ actual } `
85- }
86- }
87- isTrueFor ( callback , not ) {
88- if ( ( callback ( this . val ) && not != false ) || ( not == false && ! callback ( this . val ) ) ) {
89- return true ;
90- } else {
91- return `${ this . val } isn't true for ${ callback } `
92- }
93- }
94- length ( val , not ) {
95- if ( ( this . val . length == val && not != false ) || ( not == false && this . val . length != val ) ) {
96- return true ;
97- } else {
98- return `${ this . val } doesn't have for length ${ val } `
99- }
100- }
101- Match ( val , not ) {
102- if ( ( val . test ( this . val ) && not != false ) || ( not == false && ! val . test ( this . val ) ) ) {
103- return true ;
104- } else {
105- return `${ this . val } doesn't match ${ val } `
106- }
107- }
108- toRun ( not ) {
109- try {
110- this . val ( )
111- } catch ( e ) {
112- return not == false ? true : false
113- }
114- return not == false ? false : true
115- }
116- visual ( not ) {
117- this . val instanceof Element ? this . val . scrollIntoView ( ) : null
118- return not == false ? ! window . confirm ( "EyeJS - Is everything alright?" ) : window . confirm ( "EyeJS - Is everything alright?" )
119- }
120- }
121- return new expect ( $ )
122- }
123- let result = ! 0 ;
124- let failed = [ ] ;
125- let tothrow = [ ] ;
126- for ( var i = 0 ; i < arguments . length ; i ++ ) {
127- const callback = arguments [ i ] ;
128- const temp = callback ( $ )
129- if ( temp == ! 1 || typeof temp == 'string' ) {
130- result = false ;
131- tothrow . push ( temp )
132- failed . push ( i + 1 )
133- } else if ( temp != ! 1 && temp != ! 0 ) {
134- result = temp
135- }
136- }
137- if ( result == ! 1 ) {
138- spinner . fail ( ) ;
139- this . data . failed += failed . length ;
140- for ( i = 0 ; i < failed . length ; i ++ ) {
141- console . log ( `\nTest ${ failed [ i ] } failed: ${ tothrow [ i ] } \n` . red )
142- }
143- }
144- else if ( result == ! 0 ) {
145- this . data . tested += 1 ;
146- }
147- else {
148- this . data . warn += 1 ;
149- }
150- }
2+ constructor ( ) {
3+ this . data = {
4+ tested : 0 ,
5+ failed : 0 ,
6+ warn : 0 ,
7+ result : 0
8+ } ;
9+ }
10+ checkout ( ) {
11+ this . data . result = this . data . failed == 0 ? 1 : 0 ;
12+ this . data . result = this . data . warn == 0 ? this . data . result : 3 ;
13+ const request = new XMLHttpRequest ( ) ;
14+ request . open (
15+ "GET" ,
16+ `/post/?result=${ this . data . result } &failed=${ this . data . failed } ` ,
17+ true
18+ ) ;
19+ request . setRequestHeader (
20+ "Content-Type" ,
21+ "application/x-www-form-urlencoded; charset=UTF-8"
22+ ) ;
23+ request . onload = ( ) => {
24+ if ( request . status >= 200 && request . status < 400 ) {
25+ const data = request . responseText ;
26+ if ( data == "sucess" ) {
27+ window . open ( "" , "_self" ) . close ( ) ;
28+ }
29+ } else {
30+ console . error (
31+ "EyeJS error: The ajax request loaded, but returned an error."
32+ ) ;
33+ }
34+ } ;
35+ request . onerror = ( ) => {
36+ // There was a connection error of some sort
37+ console . error ( "EyeJS error: The ajax request returned an error." ) ;
38+ } ;
39+ request . send ( ) ;
40+ }
41+ test ( ) {
42+ const $ = $ => {
43+ class expect {
44+ constructor ( val ) {
45+ this . val = val ;
46+ }
47+ Equal ( val , not ) {
48+ if (
49+ ( JSON . stringify ( val ) == JSON . stringify ( this . val ) && not != false ) ||
50+ ( not == false && JSON . stringify ( val ) != JSON . stringify ( this . val ) )
51+ ) {
52+ return true ;
53+ } else {
54+ return `${ this . val } isn't equal to ${ val } ` ;
55+ }
56+ }
57+ hasProperty ( name , not ) {
58+ if (
59+ ( this . val . hasOwnProperty ( name ) && not != false ) ||
60+ ( not == false && ! this . val . hasOwnProperty ( name ) )
61+ ) {
62+ return true ;
63+ } else {
64+ return `${ this . val } doesn't have '${ name } ' as property` ;
65+ }
66+ }
67+ includes ( val , not ) {
68+ if (
69+ ( this . val . includes ( val ) && not != false ) ||
70+ ( not == false && ! this . val . includes ( val ) )
71+ ) {
72+ return true ;
73+ } else {
74+ return `${ this . val } doesn't includes ${ val } ` ;
75+ }
76+ }
77+ is ( type , not ) {
78+ if (
79+ ( typeof this . val == type && not != false ) ||
80+ ( not == false && typeof this . val != type )
81+ ) {
82+ return true ;
83+ } else {
84+ return `${ this . val } isn't a ${ type } ` ;
85+ }
86+ }
87+ isCloseTo ( actual , precision = 2 , not ) {
88+ if (
89+ ( Math . abs ( this . val - actual ) < Math . pow ( 10 , - precision ) / 2 &&
90+ not != false ) ||
91+ ( not == false &&
92+ ! ( Math . abs ( this . val - actual ) < Math . pow ( 10 , - precision ) / 2 ) )
93+ ) {
94+ return true ;
95+ } else {
96+ return `${ this
97+ . val } isn't close to ${ actual } , with a precision of ${ precision } `;
98+ }
99+ }
100+ isLarger ( val , not ) {
101+ if (
102+ ( this . val > val && not != false ) ||
103+ ( not == false && ! ( this . val > val ) )
104+ ) {
105+ return true ;
106+ } else {
107+ return `${ this . val } isn't larger than ${ val } ` ;
108+ }
109+ }
110+ isSmaller ( val , not ) {
111+ if (
112+ ( this . val < val && not != false ) ||
113+ ( not == false && ! ( this . val < val ) )
114+ ) {
115+ return true ;
116+ } else {
117+ return `${ this . val } isn't smaller than ${ val } ` ;
118+ }
119+ }
120+ isTrueFor ( callback , not ) {
121+ if (
122+ ( callback ( this . val ) && not != false ) ||
123+ ( not == false && ! callback ( this . val ) )
124+ ) {
125+ return true ;
126+ } else {
127+ return `${ this . val } isn't true for ${ callback } ` ;
128+ }
129+ }
130+ length ( val , not ) {
131+ if (
132+ ( this . val . length == val && not != false ) ||
133+ ( not == false && this . val . length != val )
134+ ) {
135+ return true ;
136+ } else {
137+ return `${ this . val } doesn't have for length ${ val } ` ;
138+ }
139+ }
140+ Match ( val , not ) {
141+ if (
142+ ( val . test ( this . val ) && not != false ) ||
143+ ( not == false && ! val . test ( this . val ) )
144+ ) {
145+ return true ;
146+ } else {
147+ return `${ this . val } doesn't match ${ val } ` ;
148+ }
149+ }
150+ toRun ( not ) {
151+ try {
152+ this . val ( ) ;
153+ } catch ( e ) {
154+ return not == false ? true : false ;
155+ }
156+ return not == false ? false : true ;
157+ }
158+ visual ( not ) {
159+ this . val instanceof Element ? this . val . scrollIntoView ( ) : null ;
160+ return not == false
161+ ? ! window . confirm ( "EyeJS - Is everything alright?" )
162+ : window . confirm ( "EyeJS - Is everything alright?" ) ;
163+ }
164+ }
165+ return new expect ( $ ) ;
166+ } ;
167+ let result = ! 0 ;
168+ let failed = [ ] ;
169+ let tothrow = [ ] ;
170+ for ( var i = 0 ; i < arguments . length ; i ++ ) {
171+ const callback = arguments [ i ] ;
172+ const temp = callback ( $ ) ;
173+ if ( temp == ! 1 || typeof temp == "string" ) {
174+ result = false ;
175+ tothrow . push ( temp ) ;
176+ failed . push ( i + 1 ) ;
177+ } else if ( temp != ! 1 && temp != ! 0 ) {
178+ result = temp ;
179+ }
180+ }
181+ if ( result == ! 1 ) {
182+ spinner . fail ( ) ;
183+ this . data . failed += failed . length ;
184+ for ( i = 0 ; i < failed . length ; i ++ ) {
185+ console . log ( `\nTest ${ failed [ i ] } failed: ${ tothrow [ i ] } \n` . red ) ;
186+ }
187+ } else if ( result == ! 0 ) {
188+ this . data . tested += 1 ;
189+ } else {
190+ this . data . warn += 1 ;
191+ }
192+ }
151193}
152- const eye = new EyeJS ( ) ;
194+ const eye = new EyeJS ( ) ;
0 commit comments