2017-04-20 19:17:05 -04:00
|
|
|
const test = require('tap').test;
|
|
|
|
const Clock = require('../../src/io/clock');
|
|
|
|
const Runtime = require('../../src/engine/runtime');
|
2016-10-21 12:42:32 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('spec', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const c = new Clock(rt);
|
2016-10-21 12:42:32 -04:00
|
|
|
|
|
|
|
t.type(Clock, 'function');
|
|
|
|
t.type(c, 'object');
|
|
|
|
t.type(c.projectTimer, 'function');
|
|
|
|
t.type(c.pause, 'function');
|
|
|
|
t.type(c.resume, 'function');
|
|
|
|
t.type(c.resetProjectTimer, 'function');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('cycle', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const c = new Clock(rt);
|
2016-10-21 12:42:32 -04:00
|
|
|
|
2016-10-24 15:16:06 -04:00
|
|
|
t.ok(c.projectTimer() <= 0.1);
|
2017-04-20 19:17:05 -04:00
|
|
|
setTimeout(() => {
|
2016-10-21 12:42:32 -04:00
|
|
|
c.resetProjectTimer();
|
2017-04-20 19:17:05 -04:00
|
|
|
setTimeout(() => {
|
2019-01-22 15:53:13 -05:00
|
|
|
// The timer shouldn't advance until all threads have been stepped
|
|
|
|
t.ok(c.projectTimer() === 0);
|
2016-10-21 12:42:32 -04:00
|
|
|
c.pause();
|
2019-01-22 15:53:13 -05:00
|
|
|
t.ok(c.projectTimer() === 0);
|
2016-10-21 12:42:32 -04:00
|
|
|
c.resume();
|
2019-01-22 15:53:13 -05:00
|
|
|
t.ok(c.projectTimer() === 0);
|
2016-10-21 12:42:32 -04:00
|
|
|
t.end();
|
|
|
|
}, 100);
|
|
|
|
}, 100);
|
2019-01-22 15:53:13 -05:00
|
|
|
rt._step();
|
|
|
|
t.ok(c.projectTimer() > 0);
|
2016-10-21 12:42:32 -04:00
|
|
|
});
|