cron 1.0.5 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +1 -2
- package/README.md +0 -4
- package/lib/cron.js +451 -424
- package/package.json +7 -3
- package/test.js +37 -20
- package/tests/test-cron.js +445 -397
- package/tests/test-crontime.js +51 -7
package/tests/test-crontime.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = testCase({
|
|
|
37
37
|
});
|
|
38
38
|
assert.done();
|
|
39
39
|
},
|
|
40
|
-
'test no second digit doesnt throw, i.e. standard cron format (
|
|
40
|
+
'test no second digit doesnt throw, i.e. standard cron format (* * * * *)': function(assert) {
|
|
41
41
|
assert.expect(1);
|
|
42
42
|
assert.doesNotThrow(function() {
|
|
43
43
|
new cron.CronTime('* * * * *');
|
|
@@ -45,11 +45,18 @@ module.exports = testCase({
|
|
|
45
45
|
assert.done();
|
|
46
46
|
},
|
|
47
47
|
'test no second digit defaults to 0, i.e. standard cron format (8 8 8 8 5)': function(assert) {
|
|
48
|
-
assert.expect(
|
|
49
|
-
var now =
|
|
48
|
+
assert.expect(6);
|
|
49
|
+
var now = Date.now();
|
|
50
50
|
var standard = new cron.CronTime('8 8 8 8 5');
|
|
51
51
|
var extended = new cron.CronTime('0 8 8 8 8 5');
|
|
52
|
-
|
|
52
|
+
|
|
53
|
+
assert.deepEqual(standard.dayOfWeek, extended.dayOfWeek);
|
|
54
|
+
assert.deepEqual(standard.month, extended.month);
|
|
55
|
+
assert.deepEqual(standard.dayOfMonth, extended.dayOfMonth);
|
|
56
|
+
assert.deepEqual(standard.hour, extended.hour);
|
|
57
|
+
assert.deepEqual(standard.minute, extended.minute);
|
|
58
|
+
assert.deepEqual(standard.second, extended.second);
|
|
59
|
+
|
|
53
60
|
assert.done();
|
|
54
61
|
},
|
|
55
62
|
'test hyphen (0-10 * * * * *)': function(assert) {
|
|
@@ -133,7 +140,7 @@ module.exports = testCase({
|
|
|
133
140
|
assert.expect(1);
|
|
134
141
|
var d = new Date();
|
|
135
142
|
var ct = new cron.CronTime(d);
|
|
136
|
-
assert.
|
|
143
|
+
assert.ok(ct.source.isSame(d.getTime()));
|
|
137
144
|
assert.done();
|
|
138
145
|
},
|
|
139
146
|
'test day roll-over': function(assert) {
|
|
@@ -163,7 +170,15 @@ module.exports = testCase({
|
|
|
163
170
|
nextDate.setHours(23);
|
|
164
171
|
var nextdt = ct._getNextDateFrom(nextDate);
|
|
165
172
|
assert.ok(nextdt > nextDate);
|
|
166
|
-
assert.ok(nextdt.
|
|
173
|
+
assert.ok(nextdt.hours() % 4 === 0);
|
|
174
|
+
assert.done();
|
|
175
|
+
},
|
|
176
|
+
'test next date from invalid date': function(assert) {
|
|
177
|
+
assert.expect(1);
|
|
178
|
+
var ct = new cron.CronTime('0 0 * * * *');
|
|
179
|
+
var nextDate = new Date('My invalid date string');
|
|
180
|
+
var nextdt = ct._getNextDateFrom(nextDate);
|
|
181
|
+
assert.equal(nextdt.toString(), 'Invalid date');
|
|
167
182
|
assert.done();
|
|
168
183
|
},
|
|
169
184
|
'test next real date': function(assert) {
|
|
@@ -174,7 +189,36 @@ module.exports = testCase({
|
|
|
174
189
|
nextDate.setMonth(nextDate.getMonth()+1);
|
|
175
190
|
assert.ok(nextDate > ct.source);
|
|
176
191
|
var nextdt = ct._getNextDateFrom(nextDate);
|
|
177
|
-
assert.
|
|
192
|
+
assert.ok(nextdt.isSame(nextDate));
|
|
178
193
|
assert.done();
|
|
194
|
+
},
|
|
195
|
+
'test < constraints day of month': function(assert) {
|
|
196
|
+
assert.expect(5);
|
|
197
|
+
|
|
198
|
+
var ltm = [1, 3, 5, 8, 10];
|
|
199
|
+
for (var i = 0; i < ltm.length; i++) {
|
|
200
|
+
(function(m) {
|
|
201
|
+
assert.throws(function() {
|
|
202
|
+
var ct = new cron.CronTime('0 0 0 33 ' + m + ' *');
|
|
203
|
+
});
|
|
204
|
+
})(ltm[i]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
assert.done();
|
|
208
|
+
},
|
|
209
|
+
'test next month selection': function(assert) {
|
|
210
|
+
assert.expect(1);
|
|
211
|
+
var date = new Date();
|
|
212
|
+
var dom = date.getDate() + 1;
|
|
213
|
+
var ct = new cron.CronTime('0 0 0 ' + dom + ' * *');
|
|
214
|
+
|
|
215
|
+
var saDate = ct.sendAt();
|
|
216
|
+
|
|
217
|
+
if (dom < date.getDate())
|
|
218
|
+
date.setMonth(date.getMonth()+1);
|
|
219
|
+
|
|
220
|
+
assert.equal(date.getMonth(), saDate.month());
|
|
221
|
+
|
|
222
|
+
assert.done()
|
|
179
223
|
}
|
|
180
224
|
});
|