Initial import from local backup (Documents-Playground/pakerpale)

This commit is contained in:
jeonghwa
2026-07-03 05:27:22 +09:00
commit 66e997d585
4064 changed files with 558483 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
'use strict';
var expect = require('expect.js');
var conversion = require('../../src/convert-expression/asterisk-to-range-conversion');
describe('asterisk-to-range-conversion.js', () => {
it('shuld convert * to ranges', () => {
var expressions = '* * * * * *'.split(' ');
var expression = conversion(expressions).join(' ');
expect(expression).to.equal('0-59 0-59 0-23 1-31 1-12 0-6');
});
});

View File

@@ -0,0 +1,18 @@
'use strict';
var expect = require('expect.js');
var conversion = require('../../src/convert-expression');
describe('month-names-conversion.js', () => {
it('shuld convert month names', () => {
var expression = conversion('* * * * January,February *');
var expressions = expression.split(' ');
expect(expressions[4]).to.equal('1,2');
});
it('shuld convert week day names', () => {
var expression = conversion('* * * * * Mon,Sun');
var expressions = expression.split(' ');
expect(expressions[5]).to.equal('1,0');
});
});

View File

@@ -0,0 +1,16 @@
'use strict';
var expect = require('expect.js');
var conversion = require('../../src/convert-expression/month-names-conversion');
describe('month-names-conversion.js', () => {
it('shuld convert month names', () => {
var months = conversion('January,February,March,April,May,June,July,August,September,October,November,December');
expect(months).to.equal('1,2,3,4,5,6,7,8,9,10,11,12');
});
it('shuld convert month names', () => {
var months = conversion('Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec');
expect(months).to.equal('1,2,3,4,5,6,7,8,9,10,11,12');
});
});

View File

@@ -0,0 +1,18 @@
'use strict';
var expect = require('expect.js');
var conversion = require('../../src/convert-expression/range-conversion');
describe('range-conversion.js', () => {
it('shuld convert ranges to numbers', () => {
var expressions = '0-3 0-3 0-2 1-3 1-2 0-3'.split(' ');
var expression = conversion(expressions).join(' ');
expect(expression).to.equal('0,1,2,3 0,1,2,3 0,1,2 1,2,3 1,2 0,1,2,3');
});
it('shuld convert ranges to numbers', () => {
var expressions = '0-3 0-3 8-10 1-3 1-2 0-3'.split(' ');
var expression = conversion(expressions).join(' ');
expect(expression).to.equal('0,1,2,3 0,1,2,3 8,9,10 1,2,3 1,2 0,1,2,3');
});
});

View File

@@ -0,0 +1,14 @@
'use strict';
var expect = require('expect.js');
var conversion = require('../../src/convert-expression/step-values-conversion');
describe('step-values-conversion.js', () => {
it('shuld convert step values', () => {
var expressions = '1,2,3,4,5,6,7,8,9,10/2 0,1,2,3,4,5,6,7,8,9/5 * * * *'.split(' ');
expressions = conversion(expressions);
console.log(expressions);
expect(expressions[0]).to.equal('2,4,6,8,10');
expect(expressions[1]).to.equal('0,5');
});
});

View File

@@ -0,0 +1,21 @@
'use strict';
var expect = require('expect.js');
var conversion = require('../../src/convert-expression/week-day-names-conversion');
describe('week-day-names-conversion.js', () => {
it('shuld convert week day names names', () => {
var weekDays = conversion('Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday');
expect(weekDays).to.equal('1,2,3,4,5,6,0');
});
it('shuld convert short week day names names', () => {
var weekDays = conversion('Mon,Tue,Wed,Thu,Fri,Sat,Sun');
expect(weekDays).to.equal('1,2,3,4,5,6,0');
});
it('shuld convert 7 to 0', () => {
var weekDays = conversion('7');
expect(weekDays).to.equal('0');
});
});

27
node_modules/node-cron/test/defer-start-test.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('defer a task', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should defer start of a task', () => {
var executed = 0,
task = cron.schedule('* * * * *', () => {
executed++;
}, false);
this.clock.tick(1000 * 60);
task.start();
this.clock.tick(1001 * 60);
expect(executed).to.equal(1);
});
});

30
node_modules/node-cron/test/destroy-task-test.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('destroying a task', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should destroy the task', () => {
var executed = 0,
task = cron.schedule('* * * * *', () => {
executed++;
});
this.clock.tick(1000 * 60 + 1);
task.destroy();
this.clock.tick(1000 * 60 + 1);
task.start();
this.clock.tick(1000 * 60 + 1);
expect(executed).to.equal(1);
});
});

37
node_modules/node-cron/test/multiples-values-test.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('scheduling with multiples values', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should accept multiples values in minute', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
var executed = 0;
cron.schedule('2,3,4 * * * *', () => {
executed += 1;
});
this.clock.tick(7000 * 60);
expect(executed).to.equal(3);
});
it('should accept multiples values in hour', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
var executed = 0;
cron.schedule('2,3,4 * * * *', () => {
executed += 1;
});
this.clock.tick(7000 * 60);
expect(executed).to.equal(3);
});
});

View File

@@ -0,0 +1,34 @@
'use strict';
var expect = require('expect.js');
var validate = require('../../src/pattern-validation');
describe('pattern-validation.js', () => {
describe('validate day of month', () => {
it('should fail with invalid day of month', () => {
expect(() => {
validate('* * 32 * *');
}).to.throwException((e) =>{
expect('32 is a invalid expression for day of month').to.equal(e);
});
});
it('should not fail with valid day of month', () => {
expect(() => {
validate('0 * * 15 * *');
}).to.not.throwException();
});
it('should not fail with * for day of month', () => {
expect(() => {
validate('* * * * * *');
}).to.not.throwException();
});
it('should not fail with */2 for day of month', () => {
expect(() => {
validate('* * */2 * *');
}).to.not.throwException();
});
});
});

View File

@@ -0,0 +1,40 @@
'use strict';
var expect = require('expect.js');
var validate = require('../../src/pattern-validation');
describe('pattern-validation.js', () => {
describe('validate hour', () => {
it('should fail with invalid hour', () => {
expect(() => {
validate('* 25 * * *');
}).to.throwException((e) => {
expect('25 is a invalid expression for hour').to.equal(e);
});
});
it('should not fail with valid hour', () => {
expect(() => {
validate('* 12 * * *');
}).to.not.throwException();
});
it('should not fail with * for hour', () => {
expect(() => {
validate('* * * * * *');
}).to.not.throwException();
});
it('should not fail with */2 for hour', () => {
expect(() => {
validate('* */2 * * *');
}).to.not.throwException();
});
it('should accept range for hours', () => {
expect(() => {
validate('* 3-20 * * *');
}).to.not.throwException();
});
});
});

View File

@@ -0,0 +1,34 @@
'use strict';
var expect = require('expect.js');
var validate = require('../../src/pattern-validation');
describe('pattern-validation.js', () => {
describe('validate minutes', () => {
it('should fail with invalid minute', () => {
expect(() => {
validate('63 * * * *');
}).to.throwException((e) => {
expect('63 is a invalid expression for minute').to.equal(e);
});
});
it('should not fail with valid minute', () => {
expect(() => {
validate('30 * * * *');
}).to.not.throwException();
});
it('should not fail with *', () => {
expect(() => {
validate('* * * * *');
}).to.not.throwException();
});
it('should not fail with */2', () => {
expect(() => {
validate('*/2 * * * *');
}).to.not.throwException();
});
});
});

View File

@@ -0,0 +1,48 @@
'use strict';
var expect = require('expect.js');
var validate = require('../../src/pattern-validation');
describe('pattern-validation.js', () => {
describe('validate month', () => {
it('should fail with invalid month', () => {
expect( () => {
validate('* * * 13 *');
}).to.throwException((e) => {
expect('13 is a invalid expression for month').to.equal(e);
});
});
it('should fail with invalid month name', () => {
expect( () => {
validate('* * * foo *');
}).to.throwException(function(e){
expect('foo is a invalid expression for month').to.equal(e);
});
});
it('should not fail with valid month', () => {
expect( () => {
validate('* * * 10 *');
}).to.not.throwException();
});
it('should not fail with valid month name', () => {
expect( () => {
validate('* * * September *');
}).to.not.throwException();
});
it('should not fail with * for month', () => {
expect( () => {
validate('* * * * *');
}).to.not.throwException();
});
it('should not fail with */2 for month', () => {
expect( () => {
validate('* * * */2 *');
}).to.not.throwException();
});
});
});

View File

@@ -0,0 +1,21 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
it('should accept string for pattern', () => {
expect(() => {
new Task('* * * * *');
}).to.not.throwException();
});
it('should fail with a non string value for pattern', () => {
expect(() => {
new Task([]);
}).to.throwException((e) => {
expect('pattern must be a string!').to.equal(e);
});
});
});

View File

@@ -0,0 +1,34 @@
'use strict';
var expect = require('expect.js');
var validate = require('../../src/pattern-validation');
describe('pattern-validation.js', () => {
describe('validate seconds', () => {
it('should fail with invalid second', () => {
expect(() => {
validate('63 * * * * *');
}).to.throwException((e) => {
expect('63 is a invalid expression for second').to.equal(e);
});
});
it('should not fail with valid second', () => {
expect(() => {
validate('30 * * * * *');
}).to.not.throwException();
});
it('should not fail with * for second', () => {
expect(() => {
validate('* * * * * *');
}).to.not.throwException();
});
it('should not fail with */2 for second', () => {
expect(() => {
validate('*/2 * * * * *');
}).to.not.throwException();
});
});
});

View File

@@ -0,0 +1,16 @@
'use strict';
var expect = require('expect.js');
var cron = require('../../src/node-cron');
describe('public .validate() method', () => {
it('should succeed with a valid expression', () => {
var result = cron.validate('59 * * * *');
expect(result).to.equal(true);
});
it('should fail with an invalid expression', () => {
var result = cron.validate('60 * * * *');
expect(result).to.equal(false);
});
});

View File

@@ -0,0 +1,60 @@
'use strict';
var expect = require('expect.js');
var validate = require('../../src/pattern-validation');
describe('pattern-validation.js', () => {
describe('validate week day', () => {
it('should fail with invalid week day', () => {
expect(() => {
validate('* * * * 9');
}).to.throwException((e) => {
expect('9 is a invalid expression for week day').to.equal(e);
});
});
it('should fail with invalid week day name', () => {
expect(() => {
validate('* * * * foo');
}).to.throwException((e) => {
expect('foo is a invalid expression for week day').to.equal(e);
});
});
it('should not fail with valid week day', () => {
expect(() => {
validate('* * * * 5');
}).to.not.throwException();
});
it('should not fail with valid week day name', () => {
expect(() => {
validate('* * * * Friday');
}).to.not.throwException();
});
it('should not fail with * for week day', () => {
expect(() => {
validate('* * * * *');
}).to.not.throwException();
});
it('should not fail with */2 for week day', () => {
expect(() => {
validate('* * * */2 *');
}).to.not.throwException();
});
it('should not fail with Monday-Sunday for week day', () => {
expect(() => {
validate('* * * * Monday-Sunday');
}).to.not.throwException();
});
it('should not fail with 1-7 for week day', () => {
expect(() => {
validate('0 0 1 1 1-7');
}).to.not.throwException();
});
});
});

37
node_modules/node-cron/test/range-values-test.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('scheduling with range values', () =>{
beforeEach(() =>{
this.clock = sinon.useFakeTimers();
});
afterEach(() =>{
this.clock.restore();
});
it('should accept range values in minute', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
var executed = 0;
cron.schedule('2-4 * * * *', () =>{
executed += 1;
});
this.clock.tick(7001 * 60);
expect(executed).to.equal(3);
});
it('should accept range values in hour', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
var executed = 0;
cron.schedule('0 2-4 * * *', () =>{
executed += 1;
});
this.clock.tick(7001 * 60 * 60);
expect(executed).to.equal(3);
});
});

30
node_modules/node-cron/test/restart-task-test.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('restarting a task', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should restart a task', () => {
var executed = 0,
task = cron.schedule('* * * * *', () => {
executed++;
});
this.clock.tick(1000 * 60 + 1);
task.stop();
this.clock.tick(1000 * 60 + 1);
task.start();
this.clock.tick(1000 * 60 + 1);
expect(executed).to.equal(2);
});
});

74
node_modules/node-cron/test/scheduled-taks-test.js generated vendored Normal file
View File

@@ -0,0 +1,74 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var ScheduledTask = require('../src/scheduled-task');
var Task = require('../src/task');
describe('ScheduledTask', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() =>{
this.clock.restore();
});
it('should return scheduled status', () => {
var task = new Task('* * * * *');
var scheduledTask = new ScheduledTask(task, {});
expect(scheduledTask.getStatus()).to.equal('scheduled');
});
it('should return running status', (done) => {
var task = new Task('* * * * * *', () =>{});
var scheduledTask = new ScheduledTask(task, {});
task.on('started', () => {
expect(scheduledTask.getStatus()).to.equal('running');
done();
});
this.clock.tick(1100);
});
it('should return stoped status', () => {
var task = new Task('* * * * *');
var scheduledTask = new ScheduledTask(task, {});
scheduledTask.stop();
expect(scheduledTask.getStatus()).to.equal('stoped');
});
it('should return destroyed status', () => {
var task = new Task('* * * * *');
var scheduledTask = new ScheduledTask(task, {});
scheduledTask.destroy();
expect(scheduledTask.getStatus()).to.equal('destroyed');
});
it('should return scheduled status after execution', (done) => {
var task = new Task('* * * * * *', () =>{});
var scheduledTask = new ScheduledTask(task, {});
task.on('done', () => {
expect(scheduledTask.getStatus()).to.equal('scheduled');
done();
});
this.clock.tick(1100);
});
it('should return failed status after task error', (done) => {
var task = new Task('* * * * * *', () => {
throw 'Error';
});
var scheduledTask = new ScheduledTask(task, {});
task.on('failed', () => {
expect(scheduledTask.getStatus()).to.equal('failed');
done();
});
this.clock.tick(1100);
});
});

120
node_modules/node-cron/test/scheduling-test.js generated vendored Normal file
View File

@@ -0,0 +1,120 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('scheduling on minutes', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should execute a task every minute', () => {
var executed = 0;
cron.schedule('* * * * *', () => {
executed += 1;
});
this.clock.tick(3000 * 60 + 1);
expect(executed).to.equal(3);
});
it('should execute a task on minute 1', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
this.clock = sinon.useFakeTimers(initialDate.getTime());
var executed = 0;
cron.schedule('1 * * * *', () => {
executed += 1;
});
this.clock.tick(3000 * 60);
expect(executed).to.equal(1);
});
it('should execute a task on minutes multiples of 5', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
this.clock = sinon.useFakeTimers(initialDate.getTime());
var executed = 0;
cron.schedule('*/5 * * * *', () => {
executed += 1;
});
this.clock.tick(1000 * 60 * 23);
expect(executed).to.equal(4);
});
it('should execute a task every minute from 10 to 20', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
this.clock = sinon.useFakeTimers(initialDate.getTime());
var executed = 0;
cron.schedule('10-20 * * * *', () => {
executed += 1;
});
this.clock.tick(1000 * 60 * 30);
expect(executed).to.equal(11);
});
it('should execute a task every minute from 10 to 20 and from 30 to 35', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
this.clock = sinon.useFakeTimers(initialDate.getTime());
var executed = 0;
cron.schedule('10-20,30-35 * * * *', () => {
executed += 1;
});
this.clock.tick(1000 * 60 * 40);
expect(executed).to.equal(17);
});
it('should allows lead zeros', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
this.clock = sinon.useFakeTimers(initialDate.getTime());
var executed = 0;
cron.schedule('01 * * * * *', () => {
executed += 1;
});
this.clock.tick(2000);
expect(executed).to.equal(1);
});
it('should allows lead zeros range', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
this.clock = sinon.useFakeTimers(initialDate.getTime());
var executed = 0;
cron.schedule('01-05 * * * * *', () => {
executed += 1;
});
this.clock.tick(6000);
expect(executed).to.equal(5);
});
it('should allows lead zeros step', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
this.clock = sinon.useFakeTimers(initialDate.getTime());
var executed = 0;
cron.schedule('*/02 * * * * *', () => {
executed += 1;
});
this.clock.tick(6001);
expect(executed).to.equal(3);
});
it('should schedule a task that returns a promise', () => {
let executed = 0;
cron.schedule('* * * * * *', () => {
return new Promise((resolve) => {
executed += 1;
resolve();
});
});
this.clock.tick(1001);
expect(executed).to.equal(1);
});
});

38
node_modules/node-cron/test/step-value-test.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('scheduling with divided values', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should accept * divided by 2 for minutes', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
var executed = 0;
cron.schedule('*/2 * * * *', () => {
executed += 1;
});
this.clock.tick(5000 * 60);
expect(executed).to.equal(2);
});
it('should accept 0-10 divided by 2 for minutes', () => {
var initialDate = new Date();
initialDate.setMinutes(0);
var executed = 0;
cron.schedule('0-10/2 * * * *', () => {
executed += 1;
});
this.clock.tick(15000 * 60);
expect(executed).to.equal(5);
});
});

27
node_modules/node-cron/test/stop-task-test.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('stopping a task', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should stop a task', () => {
var executed = 0,
task = cron.schedule('* * * * *', () => {
executed++;
});
this.clock.tick(1000 * 60 + 1);
task.stop();
this.clock.tick(1000 * 60 + 1);
expect(executed).to.equal(1);
});
});

View File

@@ -0,0 +1,76 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
describe('day of day', () => {
it('should run on day', () => {
let executed = 0;
var task = new Task('* * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setDate(0);
task.update(date);
date.setDate(15);
task.update(date);
date.setDate(50);
task.update(date);
expect(3).to.equal(executed);
});
it('should run only on day 9', () => {
let executed = 0;
var task = new Task('* * 9 * *', () => {
executed += 1;
});
executed = 0;
var date = new Date(2016, 1, 1);
date.setDate(3);
task.update(date);
date.setDate(9);
task.update(date);
date.setDate(11);
task.update(date);
expect(1).to.equal(executed);
});
it('should run only on day 4, 6 and 12 ', () => {
let executed = 0;
var task = new Task('* * 4,6,12 * *', () => {
executed += 1;
});
executed = 0;
var date = new Date(2016, 1, 1);
date.setDate(1);
task.update(date);
date.setDate(4);
task.update(date);
date.setDate(6);
task.update(date);
date.setDate(8);
task.update(date);
date.setDate(12);
task.update(date);
expect(3).to.equal(executed);
});
it('should run in even day', () => {
let executed = 0;
var task = new Task('* * */2 * *', () => {
executed += 1;
});
executed = 0;
var date = new Date(2016, 1, 1);
date.setDate(2);
task.update(date);
date.setDate(15);
task.update(date);
date.setDate(20);
task.update(date);
expect(2).to.equal(executed);
});
});
});

25
node_modules/node-cron/test/task/task-fail-test.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../../src/node-cron');
describe('scheduling a task with exception', () =>{
beforeEach(() =>{
this.clock = sinon.useFakeTimers();
});
afterEach(() =>{
this.clock.restore();
});
it('should not stop on task exception', () => {
var executed = 0;
cron.schedule('* * * * *', () =>{
executed += 1;
throw 'exception!';
});
this.clock.tick(3000 * 60 + 1);
expect(executed).to.equal(3);
});
});

90
node_modules/node-cron/test/task/task-hour-test.js generated vendored Normal file
View File

@@ -0,0 +1,90 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
describe('hour', () => {
it('should run a task on hour', () => {
let executed = 0;
var task = new Task('* * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setHours(0);
task.update(date);
date.setHours(15);
task.update(date);
date.setHours(50);
task.update(date);
expect(3).to.equal(executed);
});
it('should run only on hour 12', () => {
let executed = 0;
var task = new Task('0 12 * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setHours(3);
task.update(date);
date.setHours(12);
task.update(date);
date.setHours(15);
task.update(date);
expect(1).to.equal(executed);
});
it('should run only on hours 20, 30 and 40 ', () => {
let executed = 0;
var task = new Task('0 5,10,20 * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setHours(5);
task.update(date);
date.setHours(10);
task.update(date);
date.setHours(13);
task.update(date);
date.setHours(20);
task.update(date);
date.setHours(22);
task.update(date);
expect(3).to.equal(executed);
});
it('should run in even hours', () => {
let executed = 0;
var task = new Task('* */2 * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setHours(0);
task.update(date);
date.setHours(15);
task.update(date);
date.setHours(50);
task.update(date);
expect(2).to.equal(executed);
});
it('should run every hour on range', () => {
let executed = 0;
var task = new Task('* 8-20 * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setHours(0);
task.update(date);
date.setHours(8);
task.update(date);
date.setHours(19);
task.update(date);
date.setHours(21);
task.update(date);
expect(2).to.equal(executed);
});
});
});

73
node_modules/node-cron/test/task/task-minute-test.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
describe('minute', () => {
it('should run a task on minute', () => {
let executed = 0;
var task = new Task('* * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setMinutes(0);
task.update(date);
date.setMinutes(15);
task.update(date);
date.setMinutes(50);
task.update(date);
expect(3).to.equal(executed);
});
it('should run only on minute 33', () => {
let executed = 0;
var task = new Task('33 * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setMinutes(3);
task.update(date);
date.setMinutes(33);
task.update(date);
date.setMinutes(32);
task.update(date);
expect(1).to.equal(executed);
});
it('should run only on minutes 20, 30 and 40 ', () => {
let executed = 0;
var task = new Task('20,30,40 * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setMinutes(20);
task.update(date);
date.setMinutes(30);
task.update(date);
date.setMinutes(33);
task.update(date);
date.setMinutes(40);
task.update(date);
date.setMinutes(50);
task.update(date);
expect(3).to.equal(executed);
});
it('should run in even minutes', () => {
let executed = 0;
var task = new Task('*/2 * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setMinutes(0);
task.update(date);
date.setMinutes(15);
task.update(date);
date.setMinutes(50);
task.update(date);
expect(2).to.equal(executed);
});
});
});

82
node_modules/node-cron/test/task/task-month-test.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
describe('month', () => {
it('should run a task on month', () => {
let executed = 0;
var task = new Task('* * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setMonth(0);
task.update(date);
date.setMonth(10);
task.update(date);
date.setMonth(12);
task.update(date);
expect(3).to.equal(executed);
});
it('should run only on month 9', () => {
let executed = 0;
var task = new Task('* * * 9 *', () => {
executed += 1;
});
var date = new Date(2016, 3, 1);
date.setMonth(3);
task.update(date);
date.setMonth(8);
task.update(date);
date.setMonth(10);
task.update(date);
expect(1).to.equal(executed);
});
it('should run only on months 2, 4 and 6 ', () => {
let executed = 0;
var task = new Task('* * * 2,4,6 *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setMonth(0);
task.update(date);
date.setMonth(1);
task.update(date);
date.setMonth(3);
task.update(date);
date.setMonth(5);
task.update(date);
date.setMonth(7);
task.update(date);
expect(3).to.equal(executed);
});
it('should run in even months', () => {
let executed = 0;
var task = new Task('* * * */2 *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setMonth(1);
task.update(date);
date.setMonth(9);
task.update(date);
date.setMonth(8);
task.update(date);
expect(2).to.equal(executed);
});
it('should run on September', () => {
let executed = 0;
var task = new Task('* * * Sep *', () => {
executed += 1;
});
task.update(new Date(2016, 8, 1));
expect(1).to.equal(executed);
});
});
});

73
node_modules/node-cron/test/task/task-second-test.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
describe('second', () => {
it('should run a task on second', () => {
let executed = 0;
var task = new Task('* * * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setSeconds(0);
task.update(date);
date.setSeconds(15);
task.update(date);
date.setSeconds(50);
task.update(date);
expect(3).to.equal(executed);
});
it('should run only on second 33', () => {
let executed = 0;
var task = new Task('33 * * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setSeconds(3);
task.update(date);
date.setSeconds(33);
task.update(date);
date.setSeconds(32);
task.update(date);
expect(1).to.equal(executed);
});
it('should run only on seconds 20, 30 and 40 ', () => {
let executed = 0;
var task = new Task('20,30,40 * * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setSeconds(20);
task.update(date);
date.setSeconds(30);
task.update(date);
date.setSeconds(33);
task.update(date);
date.setSeconds(40);
task.update(date);
date.setSeconds(50);
task.update(date);
expect(3).to.equal(executed);
});
it('should run in even seconds', () => {
let executed = 0;
var task = new Task('*/2 * * * * *', () => {
executed += 1;
});
var date = new Date(2016, 1, 1);
date.setSeconds(0);
task.update(date);
date.setSeconds(15);
task.update(date);
date.setSeconds(50);
task.update(date);
expect(2).to.equal(executed);
});
});
});

View File

@@ -0,0 +1,89 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
describe('week day & day of month', () => {
it('should run on week day', () => {
let executed = 0;
var task = new Task('* * * * 1', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
for (var day = 1; day <= 7; day++) {
date.setDate(day);
task.update(date);
}
expect(1).to.equal(executed);
});
it('should run on day of month', () => {
let executed = 0;
var task = new Task('* * 1 * *', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
for (var day = 1; day <= 7; day++) {
date.setDate(day);
task.update(date);
}
expect(1).to.equal(executed);
});
it('should run on week day & day of month', () => {
let executed = 0;
var task = new Task('* * 1 * 1', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
for (var day = 1; day <= 7; day++) {
date.setDate(day);
task.update(date);
}
expect(2).to.equal(executed);
});
it('should run on week day with seconds', () => {
let executed = 0;
var task = new Task('0 * * * * 1', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
for (var day = 1; day <= 7; day++) {
date.setDate(day);
task.update(date);
}
expect(1).to.equal(executed);
});
it('should run on day of month with seconds', () => {
let executed = 0;
var task = new Task('0 * * 1 * *', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
for (var day = 1; day <= 7; day++) {
date.setDate(day);
task.update(date);
}
expect(1).to.equal(executed);
});
it('should run on week day & day of month with seconds', () => {
let executed = 0;
var task = new Task('0 * * 1 * 1', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
for (var day = 1; day <= 7; day++) {
date.setDate(day);
task.update(date);
}
expect(2).to.equal(executed);
});
});
});

82
node_modules/node-cron/test/task/task-week-day-test.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
'use strict';
var expect = require('expect.js');
var Task = require('../../src/task');
describe('Task', () => {
describe('week day', () => {
it('should run on week day', () => {
let executed = 0;
var task = new Task('* * * * *', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
date.setDate(4);
task.update(date);
date.setDate(5);
task.update(date);
date.setDate(6);
task.update(date);
expect(3).to.equal(executed);
});
it('should run only on week day 3', () => {
let executed = 0;
var task = new Task('* * * * 3', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
date.setDate(5);
task.update(date);
date.setDate(6);
task.update(date);
date.setDate(9);
task.update(date);
expect(1).to.equal(executed);
});
it('should run only on week days 2, 3 and 5 ', () => {
let executed = 0;
var task = new Task('* * * * 2,3,5', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
date.setDate(4);
task.update(date);
date.setDate(5);
task.update(date);
date.setDate(6);
task.update(date);
date.setDate(7);
task.update(date);
date.setDate(8);
task.update(date);
expect(3).to.equal(executed);
});
it('should run in even week days', () => {
let executed = 0;
var task = new Task('* * * * */2', () => {
executed += 1;
});
var date = new Date(2016, 0, 1);
date.setDate(4);
task.update(date);
date.setDate(5);
task.update(date);
date.setDate(7);
task.update(date);
expect(2).to.equal(executed);
});
it('should run on monday', () => {
let executed = 0;
var task = new Task('* * * * Monday', () => {
executed += 1;
});
task.update(new Date(2016, 0, 4));
expect(1).to.equal(executed);
});
});
});

38
node_modules/node-cron/test/timezone-test.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('scheduling with timezone', () => {
beforeEach(() =>{
this.clock = sinon.useFakeTimers();
});
afterEach(() =>{
this.clock.restore();
});
it('should schedule a task without timezone', () => {
var executed = 0;
cron.schedule('0 0 * * *', () => {
executed++;
});
this.clock.tick(1000 * 60 * 60 * 24);
expect(executed).to.equal(1);
});
it('should schedule a task with timezone', () => {
var executedAt;
cron.schedule('0 0 * * *', () => {
executedAt = new Date();
}, {
timezone: 'Etc/UTC'
});
this.clock.tick(1000 * 60 * 60 * 24 + 1);
expect(executedAt.getHours()).to.equal(21);
});
});

View File

@@ -0,0 +1,39 @@
'use strict';
var expect = require('expect.js');
var sinon = require('sinon');
var cron = require('../src/node-cron');
describe('validate cron on task schaduling', () => {
beforeEach(() => {
this.clock = sinon.useFakeTimers();
});
afterEach(() => {
this.clock.restore();
});
it('should fail with a invalid cron expression', () => {
expect(() => {
cron.schedule('65 * * * *', () => {});
}).to.throwException(function(e){
expect(e).to.equal('65 is a invalid expression for minute');
});
});
it('validate some spaces in task string', () => {
var result = cron.validate('5 * * * *');
expect(result).to.equal(true);
});
it('multiple spaces in task string', () => {
var result = cron.validate('5 * * * *');
expect(result).to.equal(true);
});
it('spaces in begin and end of string', () => {
var result = cron.validate(' 5 * * * * ');
expect(result).to.equal(true);
});
});