From d76e26ac16c16ca30a9c177fa292f5cdf184955e Mon Sep 17 00:00:00 2001 From: James Lal Date: Wed, 27 Jun 2012 19:28:37 +0200 Subject: initial move to support web js --- test/helper.js | 85 +++++++++++++++++++------- test/webcals/ical_test.js | 12 ++-- test/webcals/request/calendar_query_test.js | 6 +- test/webcals/request/propfind_test.js | 2 +- test/webcals/sax/base_test.js | 6 +- test/webcals/sax/dav_response_test.js | 10 +-- test/webcals/sax_test.js | 6 +- test/webcals/template_test.js | 2 +- test/webcals/templates/calendar_data_test.js | 2 +- test/webcals/templates/calendar_filter_test.js | 4 +- test/webcals/xhr_test.js | 4 +- 11 files changed, 92 insertions(+), 47 deletions(-) (limited to 'test') diff --git a/test/helper.js b/test/helper.js index f568bf8..12f21a6 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,21 +1,62 @@ (function() { - var chai = require('chai'), - fs = require('fs'), - path = require('path'); - chai.Assertion.includeStack = true; - assert = chai.assert; + var specialRequires = { + 'chai': requireChai + }; - loadSample = function(file, cb) { - var root = __dirname + '/../samples/'; - fs.readFile(root + file, 'utf8', function(err, contents) { - cb(err, contents); - }); + testSupport = { + isNode: (typeof(window) === 'undefined') + }; + + /* cross require */ + + testSupport.require = function cross_require(file, callback) { + if (file in specialRequires) { + return specialRequires[file](file, callback); + } + + if (typeof(window) === 'undefined') { + var lib = require(__dirname + '/../' + file); + if (typeof(callback) !== 'undefined') { + callback(lib); + } + } else { + window.require(file, callback); + } + } + + function setupChai(chai) { + chai.Assertion.includeStack = true; + assert = chai.assert; + } + + function requireChai(file, callback) { + var path; + if (testSupport.isNode) { + setupChai(require('chai')); + } else { + require('/vendor/chai.js', function() { + setupChai(chai); + }); + } + } + + testSupport.require('chai'); + + testSupport.loadSample = function(file, cb) { + if (testSupport.isNode) { + var root = __dirname + '/../samples/'; + require('fs').readFile(root + file, 'utf8', function(err, contents) { + cb(err, contents); + }); + } else { + //xhr samples + } }; - defineSample = function(file, cb) { + testSupport.defineSample = function(file, cb) { suiteSetup(function(done) { - loadSample(file, function(err, data) { + testSupport.loadSample(file, function(err, data) { if (err) { done(err); } @@ -25,12 +66,12 @@ }); }; - requireLib = function(lib) { - return require(__dirname + '/../lib/webcals/' + lib); + testSupport.requireLib = function(lib, callback) { + testSupport.require('/lib/webcals/' + lib, callback); }; - requireSupport = function(lib) { - return require(__dirname + '/support/' + lib); + testSupport.requireSupport = function(lib) { + testSupport.require('/test/support/' + lib); } Webcals = require('../lib/webcals/webcals.js'); @@ -49,12 +90,11 @@ } requireRequest = function(callback) { - requireLib('xhr'); - requireLib('sax'); - requireLib('request/abstract'); - requireLib('template'); - requireSupport('fake_xhr'); - + testSupport.requireLib('xhr'); + testSupport.requireLib('sax'); + testSupport.requireLib('request/abstract'); + testSupport.requireLib('template'); + testSupport.requireSupport('fake_xhr'); //in the future we need a callback for browser support. if (typeof(callback) !== 'undefined') { @@ -64,3 +104,4 @@ }()); + diff --git a/test/webcals/ical_test.js b/test/webcals/ical_test.js index ed9af4a..ff589b6 100644 --- a/test/webcals/ical_test.js +++ b/test/webcals/ical_test.js @@ -1,11 +1,15 @@ -var fs = require('fs'), - ics = requireLib('ical'), - data = fs.readFileSync(__dirname + '/../../data/test.data', 'utf8'); +testSupport.requireLib('ical'), suite('webcals/ics', function() { + var ical; + + suiteSetup(function() { + ical = Webcals.require('ical'); + }); + test('intiailizer', function() { - assert.ok(ics); + assert.ok(ical); }); }); diff --git a/test/webcals/request/calendar_query_test.js b/test/webcals/request/calendar_query_test.js index b1a167d..d896b43 100644 --- a/test/webcals/request/calendar_query_test.js +++ b/test/webcals/request/calendar_query_test.js @@ -1,6 +1,6 @@ requireRequest(); -requireLib('request/propfind'); -requireLib('request/calendar_query'); +testSupport.requireLib('request/propfind'); +testSupport.requireLib('request/calendar_query'); suite('webcals/request/calendar_query', function() { var Propfind, @@ -91,7 +91,7 @@ suite('webcals/request/calendar_query', function() { xhr, calledWith; - defineSample('xml/propget.xml', function(data) { + testSupport.defineSample('xml/propget.xml', function(data) { xml = data; }); diff --git a/test/webcals/request/propfind_test.js b/test/webcals/request/propfind_test.js index 1f152b0..609cc82 100644 --- a/test/webcals/request/propfind_test.js +++ b/test/webcals/request/propfind_test.js @@ -98,7 +98,7 @@ suite('webcals/request/propfind', function() { xhr, calledWith; - defineSample('xml/propget.xml', function(data) { + testSupport.defineSample('xml/propget.xml', function(data) { xml = data; }); diff --git a/test/webcals/sax/base_test.js b/test/webcals/sax/base_test.js index 04d8fda..63d7103 100644 --- a/test/webcals/sax/base_test.js +++ b/test/webcals/sax/base_test.js @@ -1,5 +1,5 @@ -requireLib('sax'); -requireLib('sax/base'); +testSupport.requireLib('sax'); +testSupport.requireLib('sax/base'); suite('webcals/sax/base', function() { @@ -58,7 +58,7 @@ suite('webcals/sax/base', function() { suite('base parser', function() { var xml, data; - defineSample('xml/simple.xml', function(data) { + testSupport.defineSample('xml/simple.xml', function(data) { xml = data; }); diff --git a/test/webcals/sax/dav_response_test.js b/test/webcals/sax/dav_response_test.js index f91fcef..a3e3d2b 100644 --- a/test/webcals/sax/dav_response_test.js +++ b/test/webcals/sax/dav_response_test.js @@ -1,7 +1,7 @@ -requireLib('sax'); -requireLib('sax/base'); -requireLib('sax/dav_response'); -requireLib('ical'); +testSupport.requireLib('sax'); +testSupport.requireLib('sax/base'); +testSupport.requireLib('sax/dav_response'); +testSupport.requireLib('ical'); suite('webcals/sax/dav_response', function() { @@ -30,7 +30,7 @@ suite('webcals/sax/dav_response', function() { suite('parsing', function() { var xml; - defineSample('xml/propget.xml', function(data) { + testSupport.defineSample('xml/propget.xml', function(data) { xml = data; }); diff --git a/test/webcals/sax_test.js b/test/webcals/sax_test.js index f9479e6..75ff496 100644 --- a/test/webcals/sax_test.js +++ b/test/webcals/sax_test.js @@ -1,5 +1,5 @@ -requireLib('sax'); -requireLib('sax/base'); +testSupport.requireLib('sax'); +testSupport.requireLib('sax/base'); suite('webcals/sax', function() { @@ -255,7 +255,7 @@ suite('webcals/sax', function() { var ResponseHandler; var TextOnlyHandler; - defineSample('xml/complex-tree.xml', function(data) { + testSupport.defineSample('xml/complex-tree.xml', function(data) { xml = data; }); diff --git a/test/webcals/template_test.js b/test/webcals/template_test.js index eb1e280..a59fc9c 100644 --- a/test/webcals/template_test.js +++ b/test/webcals/template_test.js @@ -1,4 +1,4 @@ -requireLib('template'); +testSupport.requireLib('template'); suite('templates', function() { diff --git a/test/webcals/templates/calendar_data_test.js b/test/webcals/templates/calendar_data_test.js index 1828b39..290b012 100644 --- a/test/webcals/templates/calendar_data_test.js +++ b/test/webcals/templates/calendar_data_test.js @@ -1,5 +1,5 @@ requireRequest(); -requireLib('templates/calendar_data'); +testSupport.requireLib('templates/calendar_data'); suite('webcals/templates/calendar_data', function() { var CalendarData; diff --git a/test/webcals/templates/calendar_filter_test.js b/test/webcals/templates/calendar_filter_test.js index d79883b..be8d133 100644 --- a/test/webcals/templates/calendar_filter_test.js +++ b/test/webcals/templates/calendar_filter_test.js @@ -1,6 +1,6 @@ requireRequest(); -requireLib('templates/calendar_data'); -requireLib('templates/calendar_filter'); +testSupport.requireLib('templates/calendar_data'); +testSupport.requireLib('templates/calendar_filter'); suite('webcals/templates/calendar_filter', function() { var CalendarFilter; diff --git a/test/webcals/xhr_test.js b/test/webcals/xhr_test.js index 33f692d..75504f0 100644 --- a/test/webcals/xhr_test.js +++ b/test/webcals/xhr_test.js @@ -1,5 +1,5 @@ -requireLib('xhr'); -requireSupport('fake_xhr'); +testSupport.requireLib('xhr'); +testSupport.requireSupport('fake_xhr'); suite('webacls/xhr', function() { var subject, -- cgit