Skip to content
This repository was archived by the owner on Jan 26, 2020. It is now read-only.

Commit 0f6b451

Browse files
committed
now that NodeJS support is there, no need to do it in test utils
some cleanup
1 parent aae9023 commit 0f6b451

File tree

2 files changed

+28
-43
lines changed

2 files changed

+28
-43
lines changed

Diff for: spec/test-utils.js

-12
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ var fs = require('fs');
1818
opts[k] = options[k];
1919
}
2020

21-
timezoneJS.timezone.transport = function (opts) {
22-
// No success handler, what's the point?
23-
if (opts.async) {
24-
if (typeof opts.success !== 'function') return;
25-
opts.error = opts.error || console.error;
26-
return fs.readFile(opts.url, 'utf8', function (err, data) {
27-
return err ? opts.error(err) : opts.success(data);
28-
});
29-
}
30-
return fs.readFileSync(opts.url, 'utf8');
31-
};
32-
3321
timezoneJS.timezone.loadingScheme = opts.loadingScheme;
3422
timezoneJS.timezone.defaultZoneFile = opts.defaultZoneFile;
3523
if (opts.loadingScheme !== timezoneJS.timezone.loadingSchemes.MANUAL_LOAD) {

Diff for: src/date.js

+28-31
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
, SHORT_DAYS = {}
6767
, EXACT_DATE_TIME = {};
6868

69-
// if node, require the file system module
70-
if (typeof window === 'undefined' && typeof require === 'function') {
71-
var nodefs = require('fs');
72-
}
73-
7469
//`{ "Jan": 0, "Feb": 1, "Mar": 2, "Apr": 3, "May": 4, "Jun": 5, "Jul": 6, "Aug": 7, "Sep": 8, "Oct": 9, "Nov": 10, "Dec": 11 }`
7570
for (var i = 0; i < MONTHS.length; i++) {
7671
SHORT_MONTHS[MONTHS[i].substr(0, 3)] = i;
@@ -153,8 +148,14 @@
153148
// - `error`: error callback function
154149
// Returns response from URL if async is false, otherwise the AJAX request object itself
155150
var _transport = function (opts) {
151+
if (!opts) return;
152+
if (!opts.url) throw new Error ('URL must be specified');
153+
if (!('async' in opts)) opts.async = true;
154+
156155
// Server-side (node)
157-
if (nodefs) {
156+
// if node, require the file system module
157+
if (typeof window === 'undefined' && typeof require === 'function') {
158+
var nodefs = require('fs');
158159
if (opts.async) {
159160
// No point if there's no success handler
160161
if (typeof opts.success !== 'function') return;
@@ -165,34 +166,30 @@
165166
}
166167
return nodefs.readFileSync(opts.url, 'utf8');
167168
}
169+
168170
// Client-side
169-
else {
170-
if ((!fleegix || typeof fleegix.xhr === 'undefined') && (!ajax_lib || typeof ajax_lib.ajax === 'undefined')) {
171-
throw new Error('Please use the Fleegix.js XHR module, jQuery ajax, Zepto ajax, or define your own transport mechanism for downloading zone files.');
172-
}
173-
if (!opts) return;
174-
if (!opts.url) throw new Error ('URL must be specified');
175-
if (!('async' in opts)) opts.async = true;
176-
if (!opts.async) {
177-
return fleegix && fleegix.xhr
178-
? fleegix.xhr.doReq({ url: opts.url, async: false })
179-
: ajax_lib.ajax({ url : opts.url, async : false, dataType: 'text' }).responseText;
180-
}
171+
if ((!fleegix || typeof fleegix.xhr === 'undefined') && (!ajax_lib || typeof ajax_lib.ajax === 'undefined')) {
172+
throw new Error('Please use the Fleegix.js XHR module, jQuery ajax, Zepto ajax, or define your own transport mechanism for downloading zone files.');
173+
}
174+
if (!opts.async) {
181175
return fleegix && fleegix.xhr
182-
? fleegix.xhr.send({
183-
url : opts.url,
184-
method : 'get',
185-
handleSuccess : opts.success,
186-
handleErr : opts.error
187-
})
188-
: ajax_lib.ajax({
189-
url : opts.url,
190-
dataType: 'text',
191-
method : 'GET',
192-
error : opts.error,
193-
success : opts.success
194-
});
176+
? fleegix.xhr.doReq({ url: opts.url, async: false })
177+
: ajax_lib.ajax({ url : opts.url, async : false, dataType: 'text' }).responseText;
195178
}
179+
return fleegix && fleegix.xhr
180+
? fleegix.xhr.send({
181+
url : opts.url,
182+
method : 'get',
183+
handleSuccess : opts.success,
184+
handleErr : opts.error
185+
})
186+
: ajax_lib.ajax({
187+
url : opts.url,
188+
dataType: 'text',
189+
method : 'GET',
190+
error : opts.error,
191+
success : opts.success
192+
});
196193
};
197194

198195
// Constructor, which is similar to that of the native Date object itself

0 commit comments

Comments
 (0)