Permalink
Browse files

add test files for issue #46

  • Loading branch information...
1 parent 85841cf commit 1e77cb4aa21ceaed4b1947ac378fa13dff130bf0 @longlho longlho committed Oct 22, 2012
Showing with 39 additions and 10 deletions.
  1. +5 −1 Jakefile
  2. +14 −9 spec/test-utils.js
  3. +20 −0 spec/tz.manual.spec.js
View
6 Jakefile
@@ -25,7 +25,11 @@ namespace('test', function () {
jake.mkdirP('lib/tz');
jake.exec(cmds, function () {
console.log('Retrieved new timezone data');
- complete();
+ console.log('Parsing tz...');
+ jake.exec('node src/node-preparse.js lib/tz > lib/all_cities.json', function () {
+ console.log('Done parsing tz');
+ complete();
+ }, {printStdout: true, printStderr: true});
}, {printStdout: true});
}, {async: true});
View
23 spec/test-utils.js
@@ -1,6 +1,5 @@
var fs = require('fs');
(function () {
-
var root = this;
var TestUtils = {};
@@ -18,13 +17,7 @@ var fs = require('fs');
for (var k in (options || {})) {
opts[k] = options[k];
}
- //Reset everything
- timezoneJS.timezone.zones = {};
- timezoneJS.timezone.rules = {};
- timezoneJS.timezone.loadedZones = {};
-
- //Set up again
- timezoneJS.timezone.zoneFileBasePath = 'lib/tz';
+
timezoneJS.timezone.transport = function (opts) {
// No success handler, what's the point?
if (opts.async) {
@@ -36,12 +29,24 @@ var fs = require('fs');
}
return fs.readFileSync(opts.url, 'utf8');
};
+
timezoneJS.timezone.loadingScheme = opts.loadingScheme;
- timezoneJS.timezone.init(opts);
+ if (opts.loadingScheme !== timezoneJS.timezone.loadingSchemes.MANUAL_LOAD) {
+ //Set up again
+ timezoneJS.timezone.zoneFileBasePath = 'lib/tz';
+ timezoneJS.timezone.init(opts);
+ }
+
return timezoneJS;
};
TestUtils.getTimezoneJS = function (options) {
+ //Delete date.js from require cache to force it to reload
+ for (var k in require.cache) {
+ if (k.indexOf('date.js') > -1) {
+ delete require.cache[k];
+ }
+ }
return init(require('../src/date'), options);
}
View
20 spec/tz.manual.spec.js
@@ -0,0 +1,20 @@
+var TestUtils = require('./test-utils')
+ , parseISO = TestUtils.parseISO
+ , date = require('../src/date')
+ , timezoneJS = TestUtils.getTimezoneJS({
+ loadingScheme: date.timezone.loadingSchemes.MANUAL_LOAD
+ });
+describe('TimezoneJS', function () {
+ it('should manually load everything correctly', function () {
+ var i = 0
+ , sampleTz;
+
+ expect(timezoneJS.timezone.loadingScheme).toEqual(date.timezone.loadingSchemes.MANUAL_LOAD);
+ //Let's load some stuff
+ timezoneJS.timezone.loadZoneJSONData('lib/all_cities.json', true);
+ expect(Object.keys(timezoneJS.timezone.zones).length > 100).toBeTruthy();
+ sampleTz = timezoneJS.timezone.getTzInfo(new Date(), 'Asia/Bangkok');
+ expect(sampleTz).toBeDefined();
+ expect(sampleTz.tzAbbr).toEqual('ICT');
+ });
+});

0 comments on commit 1e77cb4

Please sign in to comment.