8000 Added a couple tests to ensure proper parsing and running behavior of… · github4f/node-cron@a078d40 · GitHub
[go: up one dir, main page]

Skip to content

Commit a078d40

Browse files
committed
Added a couple tests to ensure proper parsing and running behavior of */2 style syntax. Also, added a couple pending tests as reminders for later features.
Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
1 parent 9844022 commit a078d40

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

tests/test-cron.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ describe('cron', function() {
1414

1515
clock.tick(1000);
1616
job.stop();
17-
expect(c).to.eql(1);
18-
1917
clock.restore();
18+
19+
expect(c).to.eql(1);
2020
});
2121

2222
it('should run second with oncomplete (* * * * * *)', function(done) {
@@ -104,6 +104,38 @@ describe('cron', function() {
104104
expect(c).to.eql(5);
105105
});
106106

107+
//ensure that this is running on the second second
108+
it('should run every 2 seconds for 1 seconds (*/2 * * * * *)', function() {
109+
var clock = sinon.useFakeTimers();
110+
var c = 0;
111+
112+
var job = new cron.CronJob('*/2 * * * * *', function() {
113+
c++;
114+
}, null, true);
115+
116+
clock.tick(1000);
117+
118+
clock.restore();
119+
job.stop();
120+
expect(c).to.eql(0);
121+
});
122+
123+
it('should run every 2 seconds for 5 seconds (*/2 * * * * *)', function() {
124+
var clock = sinon.useFakeTimers();
125+
var c = 0;
126+
127+
var job = new cron.CronJob('*/2 * * * * *', function() {
128+
c++;
129+
}, null, true);
130+
131+
for (var i = 0; i < 5; i++)
132+
clock.tick(1000);
133+
134+
clock.restore();
135+
job.stop();
136+
expect(c).to.eql(2);
137+
});
138+
107139
it('should run every second for 5 seconds with oncomplete (*/1 * * * * *)', function(done) {
108140
var clock = sinon.useFakeTimers();
109141
var c = 0;
@@ -457,7 +489,7 @@ describe('cron', function() {
457489
clock.restore();
458490
});
459491

460-
it('test start of month', function() {
492+
it('should test start of month', function() {
461493
var c = 0;
462494
var d = new Date('12/31/2014');
463495
d.setSeconds(59);
@@ -476,8 +508,11 @@ describe('cron', function() {
476508
expect(c).to.eql(1);
477509

478510
clock.tick(2678400001); //jump over 2 firsts
479-
expect(c).to.eql(3);
480511
clock.restore();
481512
job.stop();
513+
514+
expect(c).to.eql(3);
482515
});
516+
517+
it('should run every second monday');
483518
});

tests/test-crontime.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ describe('crontime', function() {
106106
}).to.not.throw;
107107
});
108108

109+
it('should test every second monday (* * * * * mon/2)');
110+
109111
it('should test unknown alias (* * * * jar *)', function() {
110112
expect(function() {
111113
new cron.CronTime('* * * * jar *');
@@ -184,16 +186,17 @@ describe('crontime', function() {
184186
});
185187

186188
it('should test next month selection', function() {
187-
var date = new Date();
188-
var dom = date.getDate() + 1;
189+
var d = new Date();
190+
var dom = d.getDate() + 1;
191+
console.log(dom);
189192
var ct = new cron.CronTime('0 0 0 ' + dom + ' * *');
190193

191194
var saDate = ct.sendAt();
192195

193-
if (dom < date.getDate())
194-
date.setMonth(date.getMonth()+1);
196+
if (dom < d.getDate())
197+
d.setMonth(d.getMonth()+1);
195198

196-
expect(date.getMonth()).to.eql(saDate.month());
199+
expect(d.getMonth()).to.eql(saDate.month());
197200
});
198201

199202
describe('should throw an exception because `L` not supported', function() {

0 commit comments

Comments
 (0)
0