aboutsummaryrefslogtreecommitdiffstats
path: root/test/helper.js
blob: f568bf8352dd977bfa23dc82aa75400990f12ff9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(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);
    }
  }

  requireRequest = function(callback) {
    requireLib('xhr');
    requireLib('sax');
    requireLib('request/abstract');
    requireLib('template');
    requireSupport('fake_xhr');


    //in the future we need a callback for browser support.
    if (typeof(callback) !== 'undefined') {
      callback();
    }
  };

}());