diff options
author | James Lal <james@lightsofapollo.com> | 2012-06-27 21:45:58 +0200 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2012-06-27 21:45:58 +0200 |
commit | c351e9975cee59131839bc6823e0a3e8c2a3d6cf (patch) | |
tree | dc4eb9c6861dba52daa162d5dd448e1757b2c22b /test/helper.js | |
parent | f80561373584abd8b5c8a12adfa6872efc324d60 (diff) | |
download | jsCalDAV-c351e9975cee59131839bc6823e0a3e8c2a3d6cf.tar.gz |
Implemented test-agent, all tests pass node/browser
Diffstat (limited to 'test/helper.js')
-rw-r--r-- | test/helper.js | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/test/helper.js b/test/helper.js index 5b7f178..fd66817 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,5 +1,6 @@ (function() { + var requireBak; var specialRequires = { 'chai': requireChai }; @@ -8,6 +9,21 @@ isNode: (typeof(window) === 'undefined') }; + + /* stream hack for SAX */ + + if (!testSupport.isNode) { + requireBak = require; + + require = function require_shim(type) { + if (type === 'stream') { + throw new Error('this is not node'); + } + + requireBak.apply(this, arguments); + } + } + /* cross require */ testSupport.require = function cross_require(file, callback) { @@ -15,6 +31,10 @@ return specialRequires[file](file, callback); } + if (!(/\.js$/.test(file))) { + file += '.js'; + } + if (typeof(window) === 'undefined') { var lib = require(__dirname + '/../' + file); if (typeof(callback) !== 'undefined') { @@ -43,6 +63,10 @@ testSupport.require('chai'); + if (!testSupport.isNode) { + testSupport.require('/vendor/sax'); + } + testSupport.loadSample = function(file, cb) { if (testSupport.isNode) { var root = __dirname + '/../samples/'; @@ -50,7 +74,18 @@ cb(err, contents); }); } else { - //xhr samples + var xhr = new XMLHttpRequest(); + xhr.open('GET', '/samples/' + file, true); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + if (xhr.status !== 200) { + cb(new Error('file not found or other error', xhr)); + } else { + cb(null, xhr.responseText); + } + } + } + xhr.send(null); } }; @@ -90,10 +125,15 @@ } requireRequest = function(callback) { + testSupport.lib('responder'); testSupport.lib('xhr'); testSupport.lib('sax'); + testSupport.lib('sax/base'); + testSupport.lib('sax/dav_response'); testSupport.lib('request/abstract'); testSupport.lib('template'); + testSupport.lib('templates/calendar_data'); + testSupport.lib('templates/calendar_filter'); testSupport.helper('fake_xhr'); //in the future we need a callback for browser support. |