pgdata und yaml
This commit is contained in:
3
app/node_modules/node-cron/test/assets/dummy-task.js
generated
vendored
Normal file
3
app/node_modules/node-cron/test/assets/dummy-task.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
exports.task = () => {
|
||||
return 'dummy task';
|
||||
};
|
||||
47
app/node_modules/node-cron/test/background-scheduled-task-test.js
generated
vendored
Normal file
47
app/node_modules/node-cron/test/background-scheduled-task-test.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
const { assert } = require('chai');
|
||||
const BackgroundScheduledTask = require('../src/background-scheduled-task');
|
||||
|
||||
describe('BackgroundScheduledTask', () => {
|
||||
it('should start a task by default', (done) => {
|
||||
let task = new BackgroundScheduledTask('* * * * * *', './test/assets/dummy-task.js');
|
||||
task.on('task-done', (result) => {
|
||||
assert.equal('dummy task', result);
|
||||
task.stop();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should create a task stoped', () => {
|
||||
let task = new BackgroundScheduledTask('* * * * * *', './test/assets/dummy-task.js', {
|
||||
scheduled: false
|
||||
});
|
||||
|
||||
assert.isUndefined(task.pid());
|
||||
});
|
||||
|
||||
it('should start a task', (done) => {
|
||||
let task = new BackgroundScheduledTask('* * * * * *', './test/assets/dummy-task.js', {
|
||||
scheduled: false
|
||||
});
|
||||
|
||||
assert.isUndefined(task.pid());
|
||||
|
||||
task.on('task-done', (result) => {
|
||||
assert.equal('dummy task', result);
|
||||
task.stop();
|
||||
done();
|
||||
});
|
||||
|
||||
task.start();
|
||||
assert.isNotNull(task.pid());
|
||||
});
|
||||
|
||||
it('should stop a task', () => {
|
||||
let task = new BackgroundScheduledTask('* * * * * *', './test/assets/dummy-task.js', {
|
||||
scheduled: true
|
||||
});
|
||||
assert.isNotNull(task.pid());
|
||||
assert.isTrue(task.isRunning());
|
||||
task.stop();
|
||||
assert.isFalse(task.isRunning());
|
||||
});
|
||||
});
|
||||
12
app/node_modules/node-cron/test/convert-expression/asterisk-to-range-conversion-test.js
generated
vendored
Normal file
12
app/node_modules/node-cron/test/convert-expression/asterisk-to-range-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const conversion = require('../../src/convert-expression/asterisk-to-range-conversion');
|
||||
|
||||
describe('asterisk-to-range-conversion.js', () => {
|
||||
it('shuld convert * to ranges', () => {
|
||||
const expressions = '* * * * * *'.split(' ');
|
||||
const expression = conversion(expressions).join(' ');
|
||||
expect(expression).to.equal('0-59 0-59 0-23 1-31 1-12 0-6');
|
||||
});
|
||||
});
|
||||
18
app/node_modules/node-cron/test/convert-expression/convert-expression-test.js
generated
vendored
Normal file
18
app/node_modules/node-cron/test/convert-expression/convert-expression-test.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const conversion = require('../../src/convert-expression');
|
||||
|
||||
describe('month-names-conversion.js', () => {
|
||||
it('shuld convert month names', () => {
|
||||
const expression = conversion('* * * * January,February *');
|
||||
const expressions = expression.split(' ');
|
||||
expect(expressions[4]).to.equal('1,2');
|
||||
});
|
||||
|
||||
it('shuld convert week day names', () => {
|
||||
const expression = conversion('* * * * * Mon,Sun');
|
||||
const expressions = expression.split(' ');
|
||||
expect(expressions[5]).to.equal('1,0');
|
||||
});
|
||||
});
|
||||
16
app/node_modules/node-cron/test/convert-expression/month-names-conversion-test.js
generated
vendored
Normal file
16
app/node_modules/node-cron/test/convert-expression/month-names-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const conversion = require('../../src/convert-expression/month-names-conversion');
|
||||
|
||||
describe('month-names-conversion.js', () => {
|
||||
it('shuld convert month names', () => {
|
||||
const 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', () => {
|
||||
const 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');
|
||||
});
|
||||
});
|
||||
24
app/node_modules/node-cron/test/convert-expression/range-conversion-test.js
generated
vendored
Normal file
24
app/node_modules/node-cron/test/convert-expression/range-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const conversion = require('../../src/convert-expression/range-conversion');
|
||||
|
||||
describe('range-conversion.js', () => {
|
||||
it('shuld convert ranges to numbers', () => {
|
||||
const expressions = '0-3 0-3 0-2 1-3 1-2 0-3'.split(' ');
|
||||
const 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', () => {
|
||||
const expressions = '0-3 0-3 8-10 1-3 1-2 0-3'.split(' ');
|
||||
const 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');
|
||||
});
|
||||
|
||||
it('should convert comma delimited ranges to numbers', () => {
|
||||
var expressions = '0-2,10-23'.split(' ');
|
||||
var expression = conversion(expressions).join(' ');
|
||||
expect(expression).to.equal('0,1,2,10,11,12,13,14,15,16,17,18,19,20,21,22,23');
|
||||
});
|
||||
});
|
||||
19
app/node_modules/node-cron/test/convert-expression/step-values-conversion-test.js
generated
vendored
Normal file
19
app/node_modules/node-cron/test/convert-expression/step-values-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const conversion = require('../../src/convert-expression/step-values-conversion');
|
||||
|
||||
describe('step-values-conversion.js', () => {
|
||||
it('should 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);
|
||||
expect(expressions[0]).to.equal('2,4,6,8,10');
|
||||
expect(expressions[1]).to.equal('0,5');
|
||||
});
|
||||
|
||||
it('should throw an error if step value is not a number', () => {
|
||||
var expressions = '1,2,3,4,5,6,7,8,9,10/someString 0,1,2,3,4,5,6,7,8,9/5 * * * *'.split(' ');
|
||||
expect(() => conversion(expressions)).to.throw('someString is not a valid step value');
|
||||
});
|
||||
|
||||
});
|
||||
21
app/node_modules/node-cron/test/convert-expression/week-day-names-conversion-test.js
generated
vendored
Normal file
21
app/node_modules/node-cron/test/convert-expression/week-day-names-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const conversion = require('../../src/convert-expression/week-day-names-conversion');
|
||||
|
||||
describe('week-day-names-conversion.js', () => {
|
||||
it('shuld convert week day names names', () => {
|
||||
const 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', () => {
|
||||
const 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', () => {
|
||||
const weekDays = conversion('7');
|
||||
expect(weekDays).to.equal('0');
|
||||
});
|
||||
});
|
||||
138
app/node_modules/node-cron/test/node-cron-test.js
generated
vendored
Normal file
138
app/node_modules/node-cron/test/node-cron-test.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
const { assert } = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const cron = require('../src/node-cron');
|
||||
|
||||
describe('node-cron', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers(new Date(2018, 0, 1, 0, 0, 0, 0));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
describe('schedule', () => {
|
||||
it('should schedule a task', () => {
|
||||
let executed = 0;
|
||||
cron.schedule('* * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
|
||||
this.clock.tick(2000);
|
||||
|
||||
assert.equal(2, executed);
|
||||
});
|
||||
|
||||
it('should schedule a task with America/Sao_Paulo timezone', (done) => {
|
||||
let startDate = new Date('Thu, 20 Sep 2018 00:00:00.000Z');
|
||||
this.clock.restore();
|
||||
this.clock = sinon.useFakeTimers(startDate);
|
||||
cron.schedule('* * * * * *', (date) => {
|
||||
assert.equal(19, date.getDate());
|
||||
assert.equal(8, date.getMonth());
|
||||
assert.equal(2018, date.getFullYear());
|
||||
assert.equal(21, date.getHours());
|
||||
assert.equal(0, date.getMinutes());
|
||||
assert.equal(1, date.getSeconds());
|
||||
done();
|
||||
}, {
|
||||
timezone: 'America/Sao_Paulo'
|
||||
});
|
||||
this.clock.tick(1000);
|
||||
});
|
||||
|
||||
it('should schedule a task with Europe/Rome timezone', (done) => {
|
||||
let startDate = new Date('Thu, 20 Sep 2018 00:00:00.000Z');
|
||||
this.clock.restore();
|
||||
this.clock = sinon.useFakeTimers(startDate);
|
||||
cron.schedule('* * * * * *', (date) => {
|
||||
assert.equal(20, date.getDate());
|
||||
assert.equal(8, date.getMonth());
|
||||
assert.equal(2018, date.getFullYear());
|
||||
assert.equal(2, date.getHours());
|
||||
assert.equal(0, date.getMinutes());
|
||||
assert.equal(1, date.getSeconds());
|
||||
done();
|
||||
}, {
|
||||
timezone: 'Europe/Rome'
|
||||
});
|
||||
this.clock.tick(1000);
|
||||
});
|
||||
|
||||
it('should schedule a task stoped', () => {
|
||||
let executed = 0;
|
||||
cron.schedule('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: false });
|
||||
|
||||
this.clock.tick(2000);
|
||||
|
||||
assert.equal(0, executed);
|
||||
});
|
||||
|
||||
it('should start a stoped task', () => {
|
||||
let executed = 0;
|
||||
let scheduledTask = cron.schedule('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: false });
|
||||
|
||||
this.clock.tick(2000);
|
||||
assert.equal(0, executed);
|
||||
scheduledTask.start();
|
||||
this.clock.tick(2000);
|
||||
assert.equal(2, executed);
|
||||
});
|
||||
|
||||
it('should recover missed executions', (done) => {
|
||||
let executed = 0;
|
||||
this.clock.restore();
|
||||
let scheduledTask = cron.schedule('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { recoverMissedExecutions: true });
|
||||
|
||||
let wait = true;
|
||||
let startedAt = new Date();
|
||||
|
||||
while(wait){
|
||||
if((new Date().getTime() - startedAt.getTime()) > 1000){
|
||||
wait = false;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
scheduledTask.stop();
|
||||
assert.equal(2, executed);
|
||||
done();
|
||||
}, 1000);
|
||||
}).timeout(4000);
|
||||
|
||||
it('should schedule a background task', () => {
|
||||
let task = cron.schedule('* * * * * *', './test/assets/dummy-task.js');
|
||||
assert.isNotNull(task);
|
||||
assert.isDefined(task);
|
||||
assert.isTrue(task.isRunning());
|
||||
task.stop();
|
||||
});
|
||||
});
|
||||
|
||||
describe('validate', () => {
|
||||
it('should validate a pattern', () => {
|
||||
assert.isTrue(cron.validate('* * * * * *'));
|
||||
});
|
||||
|
||||
it('should fail with a invalid pattern', () => {
|
||||
assert.isFalse(cron.validate('62 * * * * *'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTasks', () => {
|
||||
beforeEach(() => {
|
||||
global.scheduledTasks = new Map();
|
||||
});
|
||||
|
||||
it('should store a task', () => {
|
||||
cron.schedule('* * * * *', () => {});
|
||||
assert.lengthOf(cron.getTasks(), 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
32
app/node_modules/node-cron/test/pattern-validation/validate-day-test.js
generated
vendored
Normal file
32
app/node_modules/node-cron/test/pattern-validation/validate-day-test.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const 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.throw('32 is a invalid expression for day of month');
|
||||
});
|
||||
|
||||
it('should not fail with valid day of month', () => {
|
||||
expect(() => {
|
||||
validate('0 * * 15 * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with * for day of month', () => {
|
||||
expect(() => {
|
||||
validate('* * * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for day of month', () => {
|
||||
expect(() => {
|
||||
validate('* * */2 * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
38
app/node_modules/node-cron/test/pattern-validation/validate-hours-test.js
generated
vendored
Normal file
38
app/node_modules/node-cron/test/pattern-validation/validate-hours-test.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate hour', () => {
|
||||
it('should fail with invalid hour', () => {
|
||||
expect(() => {
|
||||
validate('* 25 * * *');
|
||||
}).to.throw('25 is a invalid expression for hour');
|
||||
});
|
||||
|
||||
it('should not fail with valid hour', () => {
|
||||
expect(() => {
|
||||
validate('* 12 * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with * for hour', () => {
|
||||
expect(() => {
|
||||
validate('* * * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for hour', () => {
|
||||
expect(() => {
|
||||
validate('* */2 * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should accept range for hours', () => {
|
||||
expect(() => {
|
||||
validate('* 3-20 * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
32
app/node_modules/node-cron/test/pattern-validation/validate-minute-test.js
generated
vendored
Normal file
32
app/node_modules/node-cron/test/pattern-validation/validate-minute-test.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate minutes', () => {
|
||||
it('should fail with invalid minute', () => {
|
||||
expect(() => {
|
||||
validate('63 * * * *');
|
||||
}).to.throw('63 is a invalid expression for minute');
|
||||
});
|
||||
|
||||
it('should not fail with valid minute', () => {
|
||||
expect(() => {
|
||||
validate('30 * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with *', () => {
|
||||
expect(() => {
|
||||
validate('* * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with */2', () => {
|
||||
expect(() => {
|
||||
validate('*/2 * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
44
app/node_modules/node-cron/test/pattern-validation/validate-month-test.js
generated
vendored
Normal file
44
app/node_modules/node-cron/test/pattern-validation/validate-month-test.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate month', () => {
|
||||
it('should fail with invalid month', () => {
|
||||
expect( () => {
|
||||
validate('* * * 13 *');
|
||||
}).to.throw('13 is a invalid expression for month');
|
||||
});
|
||||
|
||||
it('should fail with invalid month name', () => {
|
||||
expect( () => {
|
||||
validate('* * * foo *');
|
||||
}).to.throw('foo is a invalid expression for month');
|
||||
});
|
||||
|
||||
it('should not fail with valid month', () => {
|
||||
expect( () => {
|
||||
validate('* * * 10 *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with valid month name', () => {
|
||||
expect( () => {
|
||||
validate('* * * September *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with * for month', () => {
|
||||
expect( () => {
|
||||
validate('* * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for month', () => {
|
||||
expect( () => {
|
||||
validate('* * * */2 *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
19
app/node_modules/node-cron/test/pattern-validation/validate-pattern-type.js
generated
vendored
Normal file
19
app/node_modules/node-cron/test/pattern-validation/validate-pattern-type.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
it('should accept a function', () => {
|
||||
expect(() => {
|
||||
new Task(() => {});
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should fail without a function', () => {
|
||||
expect(() => {
|
||||
new Task([]);
|
||||
}).to.throw('execution must be a function');
|
||||
});
|
||||
|
||||
});
|
||||
32
app/node_modules/node-cron/test/pattern-validation/validate-second-test.js
generated
vendored
Normal file
32
app/node_modules/node-cron/test/pattern-validation/validate-second-test.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate seconds', () => {
|
||||
it('should fail with invalid second', () => {
|
||||
expect(() => {
|
||||
validate('63 * * * * *');
|
||||
}).to.throw('63 is a invalid expression for second');
|
||||
});
|
||||
|
||||
it('should not fail with valid second', () => {
|
||||
expect(() => {
|
||||
validate('30 * * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with * for second', () => {
|
||||
expect(() => {
|
||||
validate('* * * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for second', () => {
|
||||
expect(() => {
|
||||
validate('*/2 * * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
24
app/node_modules/node-cron/test/pattern-validation/validate-test.js
generated
vendored
Normal file
24
app/node_modules/node-cron/test/pattern-validation/validate-test.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation', () => {
|
||||
it('should succeed with a valid expression', () => {
|
||||
expect(() => {
|
||||
validate('59 * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should fail with an invalid expression', () => {
|
||||
expect(() => {
|
||||
validate('60 * * * *');
|
||||
}).to.throw('60 is a invalid expression for minute');
|
||||
});
|
||||
|
||||
it('should fail without a string', () => {
|
||||
expect(() => {
|
||||
validate(50);
|
||||
}).to.throw('pattern must be a string!');
|
||||
});
|
||||
});
|
||||
56
app/node_modules/node-cron/test/pattern-validation/validate-week-day-test.js
generated
vendored
Normal file
56
app/node_modules/node-cron/test/pattern-validation/validate-week-day-test.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
const { expect } = require('chai');
|
||||
const validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate week day', () => {
|
||||
it('should fail with invalid week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * 9');
|
||||
}).to.throw('9 is a invalid expression for week day');
|
||||
});
|
||||
|
||||
it('should fail with invalid week day name', () => {
|
||||
expect(() => {
|
||||
validate('* * * * foo');
|
||||
}).to.throw('foo is a invalid expression for week day');
|
||||
});
|
||||
|
||||
it('should not fail with valid week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * 5');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with valid week day name', () => {
|
||||
expect(() => {
|
||||
validate('* * * * Friday');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with * for week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * */2 *');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with Monday-Sunday for week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * Monday-Sunday');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should not fail with 1-7 for week day', () => {
|
||||
expect(() => {
|
||||
validate('0 0 1 1 1-7');
|
||||
}).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
91
app/node_modules/node-cron/test/scheduled-task-test.js
generated
vendored
Normal file
91
app/node_modules/node-cron/test/scheduled-task-test.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
const { assert } = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const ScheduledTask = require('../src/scheduled-task');
|
||||
|
||||
describe('ScheduledTask', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers(new Date(2018, 0, 1, 0, 0, 0, 0));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should start a task by default', (done) => {
|
||||
let executed = 0;
|
||||
let scheduledTask = new ScheduledTask('* * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(3000);
|
||||
assert.equal(3, executed);
|
||||
scheduledTask.stop();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should create a task stoped', (done) => {
|
||||
let executed = 0;
|
||||
let scheduledTask = new ScheduledTask('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: false });
|
||||
this.clock.tick(3000);
|
||||
assert.equal(0, executed);
|
||||
scheduledTask.stop();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should start a task', (done) => {
|
||||
let executed = 0;
|
||||
let scheduledTask = new ScheduledTask('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: false });
|
||||
this.clock.tick(3000);
|
||||
assert.equal(0, executed);
|
||||
scheduledTask.start();
|
||||
this.clock.tick(3000);
|
||||
assert.equal(3, executed);
|
||||
scheduledTask.stop();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should stop a task', () => {
|
||||
let executed = 0;
|
||||
let scheduledTask = new ScheduledTask('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: true });
|
||||
this.clock.tick(3000);
|
||||
assert.equal(3, executed);
|
||||
scheduledTask.stop();
|
||||
this.clock.tick(3000);
|
||||
assert.equal(3, executed);
|
||||
});
|
||||
|
||||
it('should create a task stopped and run it once created', () => {
|
||||
let executed = 0;
|
||||
new ScheduledTask('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: false, runOnInit: true });
|
||||
this.clock.tick(3000);
|
||||
assert.equal(1, executed);
|
||||
});
|
||||
|
||||
it('should create a task stopped and run it once manually', () => {
|
||||
let executed = 0;
|
||||
let scheduledTask = new ScheduledTask('* * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: false });
|
||||
this.clock.tick(3000);
|
||||
assert.equal(0, executed);
|
||||
scheduledTask.now();
|
||||
assert.equal(1, executed);
|
||||
});
|
||||
|
||||
it('should emit event every minute', () => {
|
||||
let executed = 0;
|
||||
let scheduledTask = new ScheduledTask('0 * * * * *', () => {
|
||||
executed += 1;
|
||||
}, { scheduled: true });
|
||||
this.clock.tick(60000 * 3);
|
||||
assert.equal(3, executed);
|
||||
scheduledTask.stop();
|
||||
});
|
||||
});
|
||||
91
app/node_modules/node-cron/test/scheduler-test.js
generated
vendored
Normal file
91
app/node_modules/node-cron/test/scheduler-test.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
const { assert } = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const Scheduler = require('../src/scheduler');
|
||||
|
||||
describe('Scheduler', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should emit an event on matched time', (done) => {
|
||||
let scheduler = new Scheduler('* * * * * *');
|
||||
|
||||
scheduler.on('scheduled-time-matched', (date) => {
|
||||
assert.isNotNull(date);
|
||||
assert.instanceOf(date, Date);
|
||||
scheduler.stop();
|
||||
done();
|
||||
});
|
||||
|
||||
scheduler.start();
|
||||
this.clock.tick(1000);
|
||||
});
|
||||
|
||||
it('should emit an event every second', (done) => {
|
||||
let scheduler = new Scheduler('* * * * * *');
|
||||
let emited = 0;
|
||||
scheduler.on('scheduled-time-matched', (date) => {
|
||||
emited += 1;
|
||||
assert.isNotNull(date);
|
||||
assert.instanceOf(date, Date);
|
||||
if(emited === 5){
|
||||
scheduler.stop();
|
||||
done();
|
||||
}
|
||||
});
|
||||
scheduler.start();
|
||||
this.clock.tick(5000);
|
||||
});
|
||||
|
||||
it('should recover missed executions', (done) => {
|
||||
this.clock.restore();
|
||||
let scheduler = new Scheduler('* * * * * *', null, true);
|
||||
let emited = 0;
|
||||
scheduler.on('scheduled-time-matched', () => {
|
||||
emited += 1;
|
||||
});
|
||||
scheduler.start();
|
||||
let wait = true;
|
||||
let startedAt = new Date();
|
||||
|
||||
while(wait){
|
||||
if((new Date().getTime() - startedAt.getTime()) > 1000){
|
||||
wait = false;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
scheduler.stop();
|
||||
assert.equal(2, emited);
|
||||
done();
|
||||
}, 1000);
|
||||
}).timeout(3000);
|
||||
|
||||
it('should ignore missed executions', (done) => {
|
||||
this.clock.restore();
|
||||
let scheduler = new Scheduler('* * * * * *', null, false);
|
||||
let emited = 0;
|
||||
scheduler.on('scheduled-time-matched', () => {
|
||||
emited += 1;
|
||||
});
|
||||
scheduler.start();
|
||||
let wait = true;
|
||||
let startedAt = new Date();
|
||||
|
||||
while(wait){
|
||||
if((new Date().getTime() - startedAt.getTime()) > 1000){
|
||||
wait = false;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
scheduler.stop();
|
||||
assert.equal(1, emited);
|
||||
done();
|
||||
}, 1000);
|
||||
}).timeout(3000);
|
||||
});
|
||||
26
app/node_modules/node-cron/test/storage-test.js
generated
vendored
Normal file
26
app/node_modules/node-cron/test/storage-test.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
const { assert } = require('chai');
|
||||
const storage = require('../src/storage');
|
||||
|
||||
describe('storage', () => {
|
||||
it('should store a task', () => {
|
||||
global.scheduledTasks = new Map();
|
||||
storage.save({});
|
||||
assert.lengthOf(global.scheduledTasks, 1);
|
||||
});
|
||||
|
||||
it('should get all tasks', () => {
|
||||
global.scheduledTasks = new Map();
|
||||
global.scheduledTasks.set(0, {});
|
||||
assert.lengthOf(storage.getTasks(), 1);
|
||||
});
|
||||
|
||||
describe('on import', () => {
|
||||
it('should keep stored items across imports', () => {
|
||||
delete require.cache[require.resolve('../src/storage')];
|
||||
global.scheduledTasks = new Map();
|
||||
storage.save({});
|
||||
let storage2 = require('../src/storage');
|
||||
assert.lengthOf(storage2.getTasks(), 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
49
app/node_modules/node-cron/test/task-test.js
generated
vendored
Normal file
49
app/node_modules/node-cron/test/task-test.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
const { assert } = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const Task = require('../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers(new Date(2018, 0, 1, 0, 0, 0, 0));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should emit event on finish a task', async () => {
|
||||
let finished = false;
|
||||
let task = new Task(() => 'ok');
|
||||
task.on('task-finished', () => finished = true);
|
||||
await task.execute();
|
||||
assert.equal(true, finished);
|
||||
});
|
||||
|
||||
it('should emit event on error a task', async () => {
|
||||
let error;
|
||||
let task = new Task(() => {
|
||||
throw Error('execution error');
|
||||
});
|
||||
task.on('task-failed', (err) => error = err.message);
|
||||
await task.execute();
|
||||
assert.equal('execution error', error);
|
||||
});
|
||||
|
||||
it('should emit event on finish a promise task', async () => {
|
||||
let finished = false;
|
||||
const promise = () => new Promise((resolve) => resolve('ok'));
|
||||
let task = new Task(promise);
|
||||
task.on('task-finished', () => finished = true);
|
||||
await task.execute();
|
||||
assert.equal(true, finished);
|
||||
});
|
||||
|
||||
it('should emit event on error a promise task', async () => {
|
||||
let failed = false;
|
||||
const promise = () => new Promise((resolve, reject) => reject('errou'));
|
||||
const task = new Task(promise);
|
||||
task.on('task-failed', (error) => failed = error);
|
||||
await task.execute();
|
||||
assert.equal('errou', failed);
|
||||
});
|
||||
});
|
||||
244
app/node_modules/node-cron/test/time-matcher-test.js
generated
vendored
Normal file
244
app/node_modules/node-cron/test/time-matcher-test.js
generated
vendored
Normal file
@@ -0,0 +1,244 @@
|
||||
const { assert } = require('chai');
|
||||
const TimeMatcher = require('../src/time-matcher');
|
||||
const moment = require('moment-timezone');
|
||||
|
||||
describe('TimeMatcher', () => {
|
||||
describe('wildcard', () => {
|
||||
it('should accept wildcard for second', () => {
|
||||
let matcher = new TimeMatcher('* * * * * *');
|
||||
assert.isTrue(matcher.match(new Date()));
|
||||
});
|
||||
|
||||
it('should accept wildcard for minute', () => {
|
||||
let matcher = new TimeMatcher('0 * * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 10, 20, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 10, 20, 1)));
|
||||
});
|
||||
|
||||
it('should accept wildcard for hour', () => {
|
||||
let matcher = new TimeMatcher('0 0 * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 10, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 10, 1, 0)));
|
||||
});
|
||||
|
||||
it('should accept wildcard for day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 1, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept wildcard for month', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 1 * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 2, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept wildcard for week day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 1 4 *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 3, 1, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 3, 2, 0, 0, 0)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('single value', () => {
|
||||
it('should accept single value for second', () => {
|
||||
let matcher = new TimeMatcher('5 * * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 5)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 0, 6)));
|
||||
});
|
||||
|
||||
it('should accept single value for minute', () => {
|
||||
let matcher = new TimeMatcher('0 5 * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 5, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 6, 0)));
|
||||
});
|
||||
|
||||
it('should accept single value for hour', () => {
|
||||
let matcher = new TimeMatcher('0 0 5 * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 5, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 6, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept single value for day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 5 * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 5, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 6, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept single value for month', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 1 5 *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 1, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 5, 1, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept single value for week day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 * * monday');
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 7, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 4, 8, 0, 0, 0)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('multiple values', () => {
|
||||
it('should accept multiple values for second', () => {
|
||||
let matcher = new TimeMatcher('5,6 * * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 5)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 6)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 0, 7)));
|
||||
});
|
||||
|
||||
it('should accept multiple values for minute', () => {
|
||||
let matcher = new TimeMatcher('0 5,6 * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 5, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 6, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 7, 0)));
|
||||
});
|
||||
|
||||
it('should accept multiple values for hour', () => {
|
||||
let matcher = new TimeMatcher('0 0 5,6 * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 5, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 6, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 7, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept multiple values for day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 5,6 * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 5, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 6, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 7, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept multiple values for month', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 1 may,june *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 1, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 5, 1, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 6, 1, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept multiple values for week day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 * * monday,tue');
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 7, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 8, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 4, 9, 0, 0, 0)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('range', () => {
|
||||
it('should accept range for second', () => {
|
||||
let matcher = new TimeMatcher('5-7 * * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 5)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 6)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 7)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 0, 8)));
|
||||
});
|
||||
|
||||
it('should accept range for minute', () => {
|
||||
let matcher = new TimeMatcher('0 5-7 * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 5, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 6, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 7, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 8, 0)));
|
||||
});
|
||||
|
||||
it('should accept range for hour', () => {
|
||||
let matcher = new TimeMatcher('0 0 5-7 * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 5, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 6, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 7, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 8, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept range for day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 5-7 * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 5, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 6, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 7, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 8, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept range for month', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 1 may-july *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 1, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 5, 1, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 6, 1, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 7, 1, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept range for week day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 * * monday-wed');
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 7, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 8, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 9, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 4, 10, 0, 0, 0)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('step values', () => {
|
||||
it('should accept step values for second', () => {
|
||||
let matcher = new TimeMatcher('*/2 * * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 2)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 0, 6)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 0, 7)));
|
||||
});
|
||||
|
||||
it('should accept step values for minute', () => {
|
||||
let matcher = new TimeMatcher('0 */2 * * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 2, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 0, 6, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 0, 7, 0)));
|
||||
});
|
||||
|
||||
it('should accept step values for hour', () => {
|
||||
let matcher = new TimeMatcher('0 0 */2 * * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 2, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 1, 6, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 1, 7, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept step values for day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 */2 * *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 2, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 0, 6, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 0, 7, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept step values for month', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 1 */2 *');
|
||||
assert.isTrue(matcher.match(new Date(2018, 1, 1, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 5, 1, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 6, 1, 0, 0, 0)));
|
||||
});
|
||||
|
||||
it('should accept step values for week day', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 * * */2');
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 6, 0, 0, 0)));
|
||||
assert.isTrue(matcher.match(new Date(2018, 4, 8, 0, 0, 0)));
|
||||
assert.isFalse(matcher.match(new Date(2018, 4, 9, 0, 0, 0)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('timezone', ()=>{
|
||||
it('should match with timezone America/Sao_Paulo', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 * * *', 'America/Sao_Paulo');
|
||||
let utcTime = new Date('Thu Oct 11 2018 03:00:00Z');
|
||||
assert.isTrue(matcher.match(utcTime));
|
||||
});
|
||||
|
||||
it('should match with timezone Europe/Rome', () => {
|
||||
let matcher = new TimeMatcher('0 0 0 * * *', 'Europe/Rome');
|
||||
let utcTime = new Date('Thu Oct 11 2018 22:00:00Z');
|
||||
assert.isTrue(matcher.match(utcTime));
|
||||
});
|
||||
|
||||
it('should match with all available timezone of moment-timezone', () => {
|
||||
const allTimeZone = moment.tz.names();
|
||||
for (let zone in allTimeZone) {
|
||||
const tmp = moment();
|
||||
const expected = moment.tz(tmp,allTimeZone[zone]);
|
||||
const pattern = expected.second() + ' ' + expected.minute() + ' ' + expected.hour() + ' ' + expected.date() + ' ' + (expected.month()+1) + ' ' + expected.day();
|
||||
const matcher = new TimeMatcher(pattern, allTimeZone[zone]);
|
||||
const utcTime = new Date(tmp.year(), tmp.month(), tmp.date(), tmp.hour(), tmp.minute(), tmp.second(), tmp.millisecond());
|
||||
assert.isTrue(matcher.match(utcTime));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user