diff options
author | James Lal <james@lightsofapollo.com> | 2012-06-25 16:44:39 +0200 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2012-06-25 16:44:39 +0200 |
commit | 96683161e43fc0101c74f0875d1a2d445afe7e8d (patch) | |
tree | 64fca9e7e146a79b433d975de521331b7f21a2ad /test/helper.js | |
parent | 536f0c2b8391b95750de370b0f851d8a83d28598 (diff) | |
download | jsCalDAV-96683161e43fc0101c74f0875d1a2d445afe7e8d.tar.gz |
test/helper add xhr tests
Diffstat (limited to 'test/helper.js')
-rw-r--r-- | test/helper.js | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/test/helper.js b/test/helper.js index d5ac7a0..436f8d2 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,30 +1,52 @@ -var chai = require('chai'), - fs = require('fs'); - -chai.Assertion.includeStack = true; -assert = chai.assert; - -loadSample = function(file, cb) { - var root = __dirname + '/../samples/'; - fs.readFile(root + file, 'utf8', function(err, contents) { - cb(err, contents); - }); -}; - -defineSample = function(file, cb) { - suiteSetup(function(done) { - loadSample(file, function(err, data) { - if (err) { - done(err); - } - cb(data); - done(); +(function() { + var chai = require('chai'), + fs = require('fs'), + path = require('path'); + + chai.Assertion.includeStack = true; + assert = chai.assert; + + loadSample = function(file, cb) { + var root = __dirname + '/../samples/'; + fs.readFile(root + file, 'utf8', function(err, contents) { + cb(err, contents); }); - }); -}; + }; + + defineSample = function(file, cb) { + suiteSetup(function(done) { + loadSample(file, function(err, data) { + if (err) { + done(err); + } + cb(data); + done(); + }); + }); + }; + + requireLib = function(lib) { + return require(__dirname + '/../lib/webcals/' + lib); + }; + + requireSupport = function(lib) { + return require(__dirname + '/support/' + lib); + } + + Webcals = require('../lib/webcals/webcals.js'); + + if (typeof(window) === 'undefined') { + //in node we need to hack Webcals to do the right thing. + var oldRequire = Webcals.require; + + Webcals.require = function exportRequireDev(path) { + if (path.indexOf('support') === 0) { + path = __dirname + '/' + path; + return require(path); + } + return oldRequire(path); + } + } -requireLib = function(lib) { - return require(__dirname + '/../lib/webcals/' + lib); -}; +}()); -Webcals = require('../lib/webcals/webcals.js'); |