Skip to content

Commit 1e77cb4

Browse files
committed
add test files for issue mde#46
1 parent 85841cf commit 1e77cb4

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

Jakefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ namespace('test', function () {
2525
jake.mkdirP('lib/tz');
2626
jake.exec(cmds, function () {
2727
console.log('Retrieved new timezone data');
28-
complete();
28+
console.log('Parsing tz...');
29+
jake.exec('node src/node-preparse.js lib/tz > lib/all_cities.json', function () {
30+
console.log('Done parsing tz');
31+
complete();
32+
}, {printStdout: true, printStderr: true});
2933
}, {printStdout: true});
3034
}, {async: true});
3135

spec/test-utils.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var fs = require('fs');
22
(function () {
3-
43
var root = this;
54

65
var TestUtils = {};
@@ -18,13 +17,7 @@ var fs = require('fs');
1817
for (var k in (options || {})) {
1918
opts[k] = options[k];
2019
}
21-
//Reset everything
22-
timezoneJS.timezone.zones = {};
23-
timezoneJS.timezone.rules = {};
24-
timezoneJS.timezone.loadedZones = {};
25-
26-
//Set up again
27-
timezoneJS.timezone.zoneFileBasePath = 'lib/tz';
20+
2821
timezoneJS.timezone.transport = function (opts) {
2922
// No success handler, what's the point?
3023
if (opts.async) {
@@ -36,12 +29,24 @@ var fs = require('fs');
3629
}
3730
return fs.readFileSync(opts.url, 'utf8');
3831
};
32+
3933
timezoneJS.timezone.loadingScheme = opts.loadingScheme;
40-
timezoneJS.timezone.init(opts);
34+
if (opts.loadingScheme !== timezoneJS.timezone.loadingSchemes.MANUAL_LOAD) {
35+
//Set up again
36+
timezoneJS.timezone.zoneFileBasePath = 'lib/tz';
37+
timezoneJS.timezone.init(opts);
38+
}
39+
4140
return timezoneJS;
4241
};
4342

4443
TestUtils.getTimezoneJS = function (options) {
44+
//Delete date.js from require cache to force it to reload
45+
for (var k in require.cache) {
46+
if (k.indexOf('date.js') > -1) {
47+
delete require.cache[k];
48+
}
49+
}
4550
return init(require('../src/date'), options);
4651
}
4752

spec/tz.manual.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var TestUtils = require('./test-utils')
2+
, parseISO = TestUtils.parseISO
3+
, date = require('../src/date')
4+
, timezoneJS = TestUtils.getTimezoneJS({
5+
loadingScheme: date.timezone.loadingSchemes.MANUAL_LOAD
6+
});
7+
describe('TimezoneJS', function () {
8+
it('should manually load everything correctly', function () {
9+
var i = 0
10+
, sampleTz;
11+
12+
expect(timezoneJS.timezone.loadingScheme).toEqual(date.timezone.loadingSchemes.MANUAL_LOAD);
13+
//Let's load some stuff
14+
timezoneJS.timezone.loadZoneJSONData('lib/all_cities.json', true);
15+
expect(Object.keys(timezoneJS.timezone.zones).length > 100).toBeTruthy();
16+
sampleTz = timezoneJS.timezone.getTzInfo(new Date(), 'Asia/Bangkok');
17+
expect(sampleTz).toBeDefined();
18+
expect(sampleTz.tzAbbr).toEqual('ICT');
19+
});
20+
});

0 commit comments

Comments
 (0)