Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from bchelli/master
Fix the support of Day of week vs Day of month
- Loading branch information
Showing
2 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict'; | ||
|
||
var expect = require('expect.js'); | ||
var Task = require('../src/task'); | ||
|
||
describe('Task', function(){ | ||
describe('week day & day of month', function(){ | ||
|
||
it('should run on week day', function(){ | ||
var task = new Task('* * * * 1', function(){ | ||
this.executed += 1; | ||
}); | ||
task.executed = 0; | ||
var date = new Date(2016, 0, 1); | ||
for (var day = 1; day <= 7; day++) { | ||
date.setDate(day); | ||
task.update(date); | ||
} | ||
expect(1).to.equal(task.executed); | ||
}); | ||
|
||
it('should run on day of month', function(){ | ||
var task = new Task('* * 1 * *', function(){ | ||
this.executed += 1; | ||
}); | ||
task.executed = 0; | ||
var date = new Date(2016, 0, 1); | ||
for (var day = 1; day <= 7; day++) { | ||
date.setDate(day); | ||
task.update(date); | ||
} | ||
expect(1).to.equal(task.executed); | ||
}); | ||
|
||
it('should run on week day & day of month', function(){ | ||
var task = new Task('* * 1 * 1', function(){ | ||
this.executed += 1; | ||
}); | ||
task.executed = 0; | ||
var date = new Date(2016, 0, 1); | ||
for (var day = 1; day <= 7; day++) { | ||
date.setDate(day); | ||
task.update(date); | ||
} | ||
expect(2).to.equal(task.executed); | ||
}); | ||
|
||
it('should run on week day with seconds', function(){ | ||
var task = new Task('0 * * * * 1', function(){ | ||
this.executed += 1; | ||
}); | ||
task.executed = 0; | ||
var date = new Date(2016, 0, 1); | ||
for (var day = 1; day <= 7; day++) { | ||
date.setDate(day); | ||
task.update(date); | ||
} | ||
expect(1).to.equal(task.executed); | ||
}); | ||
|
||
it('should run on day of month with seconds', function(){ | ||
var task = new Task('0 * * 1 * *', function(){ | ||
this.executed += 1; | ||
}); | ||
task.executed = 0; | ||
var date = new Date(2016, 0, 1); | ||
for (var day = 1; day <= 7; day++) { | ||
date.setDate(day); | ||
task.update(date); | ||
} | ||
expect(1).to.equal(task.executed); | ||
}); | ||
|
||
it('should run on week day & day of month with seconds', function(){ | ||
var task = new Task('0 * * 1 * 1', function(){ | ||
this.executed += 1; | ||
}); | ||
task.executed = 0; | ||
var date = new Date(2016, 0, 1); | ||
for (var day = 1; day <= 7; day++) { | ||
date.setDate(day); | ||
task.update(date); | ||
} | ||
expect(2).to.equal(task.executed); | ||
}); | ||
|
||
}); | ||
}); | ||
|