diff options
author | Paul Joseph Davis <davisp@apache.org> | 2009-11-26 19:32:08 +0000 |
---|---|---|
committer | Paul Joseph Davis <davisp@apache.org> | 2009-11-26 19:32:08 +0000 |
commit | 627b7d2d90c7cfcec2c8bb6e5b5e2b53ea60d217 (patch) | |
tree | c8b09655791ba3e5bc8a34344709ded81f8dc73e /test/javascript/couch_http.js | |
parent | 95ee619df135a4c8b3ecefe65503c6d1cc7c36da (diff) |
Setup JavaScript command line runner.
All JS tests can now be run from the command line using the cURL
adapter. In the future I would like to rework this and provide better
TAP output. For now, each test is a single TAP assert.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@884675 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/javascript/couch_http.js')
-rw-r--r-- | test/javascript/couch_http.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/javascript/couch_http.js b/test/javascript/couch_http.js new file mode 100644 index 00000000..f92cf119 --- /dev/null +++ b/test/javascript/couch_http.js @@ -0,0 +1,57 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +(function() { + CouchHTTP.prototype.base_url = "http://127.0.0.1:5984" + + if(typeof(CouchHTTP) != "undefined") { + CouchHTTP.prototype.open = function(method, url, async) { + if(/^\s*http:\/\//.test(url)) { + return this._open(method, url, async); + } else { + return this._open(method, this.base_url + url, async); + } + }; + + CouchHTTP.prototype.setRequestHeader = function(name, value) { + // Drop content-length headers because cURL will set it for us + // based on body length + if(name.toLowerCase().replace(/^\s+|\s+$/g, '') != "content-length") { + this._setRequestHeader(name, value); + } + } + + CouchHTTP.prototype.send = function(body) { + this._send(body || ""); + var headers = {}; + this._headers.forEach(function(hdr) { + var pair = hdr.split(":"); + var name = pair.shift(); + headers[name] = pair.join(":").replace(/^\s+|\s+$/g, ""); + }); + this.headers = headers; + }; + + CouchHTTP.prototype.getResponseHeader = function(name) { + for(var hdr in this.headers) { + if(hdr.toLowerCase() == name.toLowerCase()) { + return this.headers[hdr]; + } + } + return null; + }; + } +})(); + +CouchDB.newXhr = function() { + return new CouchHTTP(); +}; |