Fossil SCM
JS code test cleanups to account for the fact that the ajax-thrown assertions/exceptions get swallowed by the ajax layer.
Commit
9e98a9bd9efb0f2f28be122af4e10d0f11758ee7
Parent
ec76ee16fdb07df…
2 files changed
+29
-14
+13
-1
+29
-14
| --- ajax/i-test/rhino-test.js | ||
| +++ ajax/i-test/rhino-test.js | ||
| @@ -3,11 +3,11 @@ | ||
| 3 | 3 | 'http://localhost:8080' |
| 4 | 4 | //'http://fjson/cgi-bin/fossil-json.cgi' |
| 5 | 5 | //'http://192.168.1.62:8080' |
| 6 | 6 | //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi' |
| 7 | 7 | , |
| 8 | - verbose:true, | |
| 8 | + verbose:false, | |
| 9 | 9 | wiki:{} |
| 10 | 10 | }; |
| 11 | 11 | (function bootstrap() { |
| 12 | 12 | var srcdir = '../js/'; |
| 13 | 13 | var includes = [srcdir+'json2.js', |
| @@ -49,11 +49,15 @@ | ||
| 49 | 49 | Throws an exception of cond is a falsy value. |
| 50 | 50 | */ |
| 51 | 51 | function assert(cond, descr){ |
| 52 | 52 | descr = descr || "Undescribed condition."; |
| 53 | 53 | if(!cond){ |
| 54 | + print("Assertion FAILED: "+descr); | |
| 54 | 55 | throw new Error("Assertion failed: "+descr); |
| 56 | + // aarrgghh. Exceptions are of course swallowed by | |
| 57 | + // the AJAX layer, to keep from killing a browser's | |
| 58 | + // script environment. | |
| 55 | 59 | }else{ |
| 56 | 60 | print("Assertion OK: "+descr); |
| 57 | 61 | } |
| 58 | 62 | } |
| 59 | 63 | |
| @@ -88,33 +92,35 @@ | ||
| 88 | 92 | !resp.resultCode. |
| 89 | 93 | */ |
| 90 | 94 | function assertResponseOK(resp){ |
| 91 | 95 | assert('object' === typeof resp,'Response is-a object.'); |
| 92 | 96 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 93 | - assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode); | |
| 97 | + assert( undefined === resp.resultCode, 'resp.resultCode is not set'); | |
| 94 | 98 | } |
| 95 | 99 | /** |
| 96 | 100 | Asserts that resp is-a Object, resp.fossil is-a string, and |
| 97 | 101 | resp.resultCode is a truthy value. If expectCode is set then |
| 98 | 102 | it also asserts that (resp.resultCode=='FOSSIL-'+expectCode). |
| 99 | 103 | */ |
| 100 | 104 | function assertResponseError(resp,expectCode){ |
| 101 | 105 | assert('object' === typeof resp,'Response is-a object.'); |
| 102 | 106 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 103 | - assert( resp.resultCode, 'resp.resultCode='+resp.resultCode); | |
| 107 | + assert( !!resp.resultCode, 'resp.resultCode='+resp.resultCode); | |
| 104 | 108 | if(expectCode){ |
| 105 | 109 | assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode ); |
| 106 | 110 | } |
| 107 | 111 | } |
| 108 | 112 | |
| 109 | 113 | function testHAI(){ |
| 114 | + var rs; | |
| 110 | 115 | TestApp.fossil.HAI({ |
| 111 | 116 | onResponse:function(resp,req){ |
| 112 | - assertResponseOK(resp); | |
| 113 | - TestApp.serverVersion = resp.fossil; | |
| 117 | + rs = resp; | |
| 114 | 118 | } |
| 115 | 119 | }); |
| 120 | + assertResponseOK(rs); | |
| 121 | + TestApp.serverVersion = rs.fossil; | |
| 116 | 122 | assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion); |
| 117 | 123 | } |
| 118 | 124 | testHAI.description = 'Get server version info.'; |
| 119 | 125 | |
| 120 | 126 | function testIAmNobody(){ |
| @@ -135,44 +141,53 @@ | ||
| 135 | 141 | assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name); |
| 136 | 142 | } |
| 137 | 143 | testAnonymousLogin.description = 'Perform anonymous login.'; |
| 138 | 144 | |
| 139 | 145 | function testAnonWiki(){ |
| 146 | + var rs; | |
| 140 | 147 | TestApp.fossil.sendCommand('/json/wiki/list',undefined,{ |
| 141 | 148 | beforeSend:function(req,opt){ |
| 142 | 149 | assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' ); |
| 143 | 150 | }, |
| 144 | 151 | onResponse:function(resp,req){ |
| 145 | - assertResponseOK(resp); | |
| 146 | - assert( (typeof [] === typeof resp.payload) && resp.payload.length, | |
| 147 | - "Wiki list seems to be okay."); | |
| 148 | - TestApp.wiki.list = resp.payload; | |
| 152 | + rs = resp; | |
| 149 | 153 | } |
| 150 | 154 | }); |
| 155 | + assertResponseOK(rs); | |
| 156 | + assert( (typeof [] === typeof rs.payload) && rs.payload.length, | |
| 157 | + "Wiki list seems to be okay."); | |
| 158 | + TestApp.wiki.list = rs.payload; | |
| 159 | + | |
| 151 | 160 | TestApp.fossil.sendCommand('/json/wiki/get',{ |
| 152 | 161 | name:TestApp.wiki.list[0] |
| 153 | 162 | },{ |
| 154 | 163 | onResponse:function(resp,req){ |
| 155 | - assertResponseOK(resp); | |
| 156 | - assert(resp.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations."); | |
| 157 | - print("Got first wiki page: "+WhAjaj.stringify(resp.payload)); | |
| 164 | + rs = resp; | |
| 158 | 165 | } |
| 159 | 166 | }); |
| 167 | + assertResponseOK(rs); | |
| 168 | + assert(rs.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations."); | |
| 169 | + print("Got first wiki page: "+WhAjaj.stringify(rs.payload)); | |
| 170 | + | |
| 160 | 171 | } |
| 161 | 172 | testAnonWiki.description = 'Fetch wiki list as anonymous user.'; |
| 162 | 173 | |
| 163 | 174 | function testAnonLogout(){ |
| 175 | + var rs; | |
| 164 | 176 | TestApp.fossil.logout({ |
| 165 | 177 | onResponse:function(resp,req){ |
| 166 | - assertResponseOK(resp); | |
| 178 | + rs = resp; | |
| 167 | 179 | } |
| 168 | 180 | }); |
| 181 | + assertResponseOK(rs); | |
| 182 | + print("Ensure that second logout attempt fails..."); | |
| 169 | 183 | TestApp.fossil.logout({ |
| 170 | 184 | onResponse:function(resp,req){ |
| 171 | - assertResponseError(resp); | |
| 185 | + rs = resp; | |
| 172 | 186 | } |
| 173 | 187 | }); |
| 188 | + assertResponseError(rs); | |
| 174 | 189 | } |
| 175 | 190 | testAnonLogout.description = 'Log out anonymous user.'; |
| 176 | 191 | |
| 177 | 192 | (function runAllTests(){ |
| 178 | 193 | var testList = [ |
| 179 | 194 |
| --- ajax/i-test/rhino-test.js | |
| +++ ajax/i-test/rhino-test.js | |
| @@ -3,11 +3,11 @@ | |
| 3 | 'http://localhost:8080' |
| 4 | //'http://fjson/cgi-bin/fossil-json.cgi' |
| 5 | //'http://192.168.1.62:8080' |
| 6 | //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi' |
| 7 | , |
| 8 | verbose:true, |
| 9 | wiki:{} |
| 10 | }; |
| 11 | (function bootstrap() { |
| 12 | var srcdir = '../js/'; |
| 13 | var includes = [srcdir+'json2.js', |
| @@ -49,11 +49,15 @@ | |
| 49 | Throws an exception of cond is a falsy value. |
| 50 | */ |
| 51 | function assert(cond, descr){ |
| 52 | descr = descr || "Undescribed condition."; |
| 53 | if(!cond){ |
| 54 | throw new Error("Assertion failed: "+descr); |
| 55 | }else{ |
| 56 | print("Assertion OK: "+descr); |
| 57 | } |
| 58 | } |
| 59 | |
| @@ -88,33 +92,35 @@ | |
| 88 | !resp.resultCode. |
| 89 | */ |
| 90 | function assertResponseOK(resp){ |
| 91 | assert('object' === typeof resp,'Response is-a object.'); |
| 92 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 93 | assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode); |
| 94 | } |
| 95 | /** |
| 96 | Asserts that resp is-a Object, resp.fossil is-a string, and |
| 97 | resp.resultCode is a truthy value. If expectCode is set then |
| 98 | it also asserts that (resp.resultCode=='FOSSIL-'+expectCode). |
| 99 | */ |
| 100 | function assertResponseError(resp,expectCode){ |
| 101 | assert('object' === typeof resp,'Response is-a object.'); |
| 102 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 103 | assert( resp.resultCode, 'resp.resultCode='+resp.resultCode); |
| 104 | if(expectCode){ |
| 105 | assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode ); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | function testHAI(){ |
| 110 | TestApp.fossil.HAI({ |
| 111 | onResponse:function(resp,req){ |
| 112 | assertResponseOK(resp); |
| 113 | TestApp.serverVersion = resp.fossil; |
| 114 | } |
| 115 | }); |
| 116 | assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion); |
| 117 | } |
| 118 | testHAI.description = 'Get server version info.'; |
| 119 | |
| 120 | function testIAmNobody(){ |
| @@ -135,44 +141,53 @@ | |
| 135 | assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name); |
| 136 | } |
| 137 | testAnonymousLogin.description = 'Perform anonymous login.'; |
| 138 | |
| 139 | function testAnonWiki(){ |
| 140 | TestApp.fossil.sendCommand('/json/wiki/list',undefined,{ |
| 141 | beforeSend:function(req,opt){ |
| 142 | assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' ); |
| 143 | }, |
| 144 | onResponse:function(resp,req){ |
| 145 | assertResponseOK(resp); |
| 146 | assert( (typeof [] === typeof resp.payload) && resp.payload.length, |
| 147 | "Wiki list seems to be okay."); |
| 148 | TestApp.wiki.list = resp.payload; |
| 149 | } |
| 150 | }); |
| 151 | TestApp.fossil.sendCommand('/json/wiki/get',{ |
| 152 | name:TestApp.wiki.list[0] |
| 153 | },{ |
| 154 | onResponse:function(resp,req){ |
| 155 | assertResponseOK(resp); |
| 156 | assert(resp.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations."); |
| 157 | print("Got first wiki page: "+WhAjaj.stringify(resp.payload)); |
| 158 | } |
| 159 | }); |
| 160 | } |
| 161 | testAnonWiki.description = 'Fetch wiki list as anonymous user.'; |
| 162 | |
| 163 | function testAnonLogout(){ |
| 164 | TestApp.fossil.logout({ |
| 165 | onResponse:function(resp,req){ |
| 166 | assertResponseOK(resp); |
| 167 | } |
| 168 | }); |
| 169 | TestApp.fossil.logout({ |
| 170 | onResponse:function(resp,req){ |
| 171 | assertResponseError(resp); |
| 172 | } |
| 173 | }); |
| 174 | } |
| 175 | testAnonLogout.description = 'Log out anonymous user.'; |
| 176 | |
| 177 | (function runAllTests(){ |
| 178 | var testList = [ |
| 179 |
| --- ajax/i-test/rhino-test.js | |
| +++ ajax/i-test/rhino-test.js | |
| @@ -3,11 +3,11 @@ | |
| 3 | 'http://localhost:8080' |
| 4 | //'http://fjson/cgi-bin/fossil-json.cgi' |
| 5 | //'http://192.168.1.62:8080' |
| 6 | //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi' |
| 7 | , |
| 8 | verbose:false, |
| 9 | wiki:{} |
| 10 | }; |
| 11 | (function bootstrap() { |
| 12 | var srcdir = '../js/'; |
| 13 | var includes = [srcdir+'json2.js', |
| @@ -49,11 +49,15 @@ | |
| 49 | Throws an exception of cond is a falsy value. |
| 50 | */ |
| 51 | function assert(cond, descr){ |
| 52 | descr = descr || "Undescribed condition."; |
| 53 | if(!cond){ |
| 54 | print("Assertion FAILED: "+descr); |
| 55 | throw new Error("Assertion failed: "+descr); |
| 56 | // aarrgghh. Exceptions are of course swallowed by |
| 57 | // the AJAX layer, to keep from killing a browser's |
| 58 | // script environment. |
| 59 | }else{ |
| 60 | print("Assertion OK: "+descr); |
| 61 | } |
| 62 | } |
| 63 | |
| @@ -88,33 +92,35 @@ | |
| 92 | !resp.resultCode. |
| 93 | */ |
| 94 | function assertResponseOK(resp){ |
| 95 | assert('object' === typeof resp,'Response is-a object.'); |
| 96 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 97 | assert( undefined === resp.resultCode, 'resp.resultCode is not set'); |
| 98 | } |
| 99 | /** |
| 100 | Asserts that resp is-a Object, resp.fossil is-a string, and |
| 101 | resp.resultCode is a truthy value. If expectCode is set then |
| 102 | it also asserts that (resp.resultCode=='FOSSIL-'+expectCode). |
| 103 | */ |
| 104 | function assertResponseError(resp,expectCode){ |
| 105 | assert('object' === typeof resp,'Response is-a object.'); |
| 106 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 107 | assert( !!resp.resultCode, 'resp.resultCode='+resp.resultCode); |
| 108 | if(expectCode){ |
| 109 | assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | function testHAI(){ |
| 114 | var rs; |
| 115 | TestApp.fossil.HAI({ |
| 116 | onResponse:function(resp,req){ |
| 117 | rs = resp; |
| 118 | } |
| 119 | }); |
| 120 | assertResponseOK(rs); |
| 121 | TestApp.serverVersion = rs.fossil; |
| 122 | assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion); |
| 123 | } |
| 124 | testHAI.description = 'Get server version info.'; |
| 125 | |
| 126 | function testIAmNobody(){ |
| @@ -135,44 +141,53 @@ | |
| 141 | assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name); |
| 142 | } |
| 143 | testAnonymousLogin.description = 'Perform anonymous login.'; |
| 144 | |
| 145 | function testAnonWiki(){ |
| 146 | var rs; |
| 147 | TestApp.fossil.sendCommand('/json/wiki/list',undefined,{ |
| 148 | beforeSend:function(req,opt){ |
| 149 | assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' ); |
| 150 | }, |
| 151 | onResponse:function(resp,req){ |
| 152 | rs = resp; |
| 153 | } |
| 154 | }); |
| 155 | assertResponseOK(rs); |
| 156 | assert( (typeof [] === typeof rs.payload) && rs.payload.length, |
| 157 | "Wiki list seems to be okay."); |
| 158 | TestApp.wiki.list = rs.payload; |
| 159 | |
| 160 | TestApp.fossil.sendCommand('/json/wiki/get',{ |
| 161 | name:TestApp.wiki.list[0] |
| 162 | },{ |
| 163 | onResponse:function(resp,req){ |
| 164 | rs = resp; |
| 165 | } |
| 166 | }); |
| 167 | assertResponseOK(rs); |
| 168 | assert(rs.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations."); |
| 169 | print("Got first wiki page: "+WhAjaj.stringify(rs.payload)); |
| 170 | |
| 171 | } |
| 172 | testAnonWiki.description = 'Fetch wiki list as anonymous user.'; |
| 173 | |
| 174 | function testAnonLogout(){ |
| 175 | var rs; |
| 176 | TestApp.fossil.logout({ |
| 177 | onResponse:function(resp,req){ |
| 178 | rs = resp; |
| 179 | } |
| 180 | }); |
| 181 | assertResponseOK(rs); |
| 182 | print("Ensure that second logout attempt fails..."); |
| 183 | TestApp.fossil.logout({ |
| 184 | onResponse:function(resp,req){ |
| 185 | rs = resp; |
| 186 | } |
| 187 | }); |
| 188 | assertResponseError(rs); |
| 189 | } |
| 190 | testAnonLogout.description = 'Log out anonymous user.'; |
| 191 | |
| 192 | (function runAllTests(){ |
| 193 | var testList = [ |
| 194 |
+13
-1
| --- ajax/js/whajaj.js | ||
| +++ ajax/js/whajaj.js | ||
| @@ -405,11 +405,15 @@ | ||
| 405 | 405 | handling code ASSUMES that the response contains a JSONP-style |
| 406 | 406 | construct and eval()s it after afterSend() but before onResponse(). |
| 407 | 407 | In this case, onResponse() will get a string value for the response |
| 408 | 408 | instead of a response object parsed from JSON. |
| 409 | 409 | */ |
| 410 | - jsonp:undefined | |
| 410 | + jsonp:undefined, | |
| 411 | + /** | |
| 412 | + Don't use yet. Planned future option. | |
| 413 | + */ | |
| 414 | + propagateExceptions:false | |
| 411 | 415 | } |
| 412 | 416 | }; |
| 413 | 417 | |
| 414 | 418 | |
| 415 | 419 | /** |
| @@ -947,10 +951,18 @@ | ||
| 947 | 951 | - timeouts are not supported. |
| 948 | 952 | |
| 949 | 953 | - asynchronous mode is not supported because implementing it |
| 950 | 954 | requires the ability to kill a running thread (which is deprecated |
| 951 | 955 | in the Java API). |
| 956 | + | |
| 957 | + TODOs: | |
| 958 | + | |
| 959 | + - add socket timeouts. | |
| 960 | + | |
| 961 | + - support HTTP proxy. | |
| 962 | + | |
| 963 | + The Java APIs support this, it just hasn't been added here yet. | |
| 952 | 964 | */ |
| 953 | 965 | rhino:function(request,args) |
| 954 | 966 | { |
| 955 | 967 | var self = this; |
| 956 | 968 | var data = request || undefined; |
| 957 | 969 |
| --- ajax/js/whajaj.js | |
| +++ ajax/js/whajaj.js | |
| @@ -405,11 +405,15 @@ | |
| 405 | handling code ASSUMES that the response contains a JSONP-style |
| 406 | construct and eval()s it after afterSend() but before onResponse(). |
| 407 | In this case, onResponse() will get a string value for the response |
| 408 | instead of a response object parsed from JSON. |
| 409 | */ |
| 410 | jsonp:undefined |
| 411 | } |
| 412 | }; |
| 413 | |
| 414 | |
| 415 | /** |
| @@ -947,10 +951,18 @@ | |
| 947 | - timeouts are not supported. |
| 948 | |
| 949 | - asynchronous mode is not supported because implementing it |
| 950 | requires the ability to kill a running thread (which is deprecated |
| 951 | in the Java API). |
| 952 | */ |
| 953 | rhino:function(request,args) |
| 954 | { |
| 955 | var self = this; |
| 956 | var data = request || undefined; |
| 957 |
| --- ajax/js/whajaj.js | |
| +++ ajax/js/whajaj.js | |
| @@ -405,11 +405,15 @@ | |
| 405 | handling code ASSUMES that the response contains a JSONP-style |
| 406 | construct and eval()s it after afterSend() but before onResponse(). |
| 407 | In this case, onResponse() will get a string value for the response |
| 408 | instead of a response object parsed from JSON. |
| 409 | */ |
| 410 | jsonp:undefined, |
| 411 | /** |
| 412 | Don't use yet. Planned future option. |
| 413 | */ |
| 414 | propagateExceptions:false |
| 415 | } |
| 416 | }; |
| 417 | |
| 418 | |
| 419 | /** |
| @@ -947,10 +951,18 @@ | |
| 951 | - timeouts are not supported. |
| 952 | |
| 953 | - asynchronous mode is not supported because implementing it |
| 954 | requires the ability to kill a running thread (which is deprecated |
| 955 | in the Java API). |
| 956 | |
| 957 | TODOs: |
| 958 | |
| 959 | - add socket timeouts. |
| 960 | |
| 961 | - support HTTP proxy. |
| 962 | |
| 963 | The Java APIs support this, it just hasn't been added here yet. |
| 964 | */ |
| 965 | rhino:function(request,args) |
| 966 | { |
| 967 | var self = this; |
| 968 | var data = request || undefined; |
| 969 |