Skip to content

Commit

Permalink
GH-400 - Testing around execution at midnight.
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information
ncb000gt committed Feb 9, 2019
1 parent aaf8d42 commit 3773c23
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/at_midnight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const CronJob = require('../lib/cron.js').CronJob;

console.log('Before job instantiation');
const job = new CronJob('00 00 00 * * *', function() {
const d = new Date();
console.log('Midnight:', d);
});
console.log('After job instantiation');
job.start();
25 changes: 25 additions & 0 deletions tests/test-cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,31 @@ describe('cron', function() {
expect(c).to.eql(8);
});

it.only('should trigger onTick at midnight', function() {
var c = 0;
var d = new Date('12/31/2014');
d.setSeconds(59);
d.setMinutes(59);
d.setHours(23);
var clock = sinon.useFakeTimers(d.getTime());

var job = new cron.CronJob({
cronTime: '00 * * * * *',
onTick: function() {
c++;
},
start: true,
timeZone: 'UTC'
});

clock.tick(1000); // move clock 1 second
expect(c).to.eql(1);

clock.restore();
job.stop();
expect(c).to.eql(1);
});

it('should run every day UTC', function() {
var c = 0;
var d = new Date('12/31/2014');
Expand Down

0 comments on commit 3773c23

Please sign in to comment.