taskbuffer/test/test.2.taskchain.ts

50 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2023-07-26 12:16:33 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2022-03-25 11:14:49 +00:00
import * as taskbuffer from '../ts/index.js';
2017-06-17 14:56:33 +00:00
2023-07-26 12:16:33 +00:00
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartdelay from '@push.rocks/smartdelay';
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
let task1Executed = false;
2019-09-22 13:16:27 +00:00
const task1 = new taskbuffer.Task({
2017-06-17 14:56:33 +00:00
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task1Executed = true;
2020-07-12 00:48:51 +00:00
},
2018-08-04 15:53:22 +00:00
});
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
let task2Executed = false;
2019-09-22 13:16:27 +00:00
const task2 = new taskbuffer.Task({
2017-06-17 14:56:33 +00:00
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task2Executed = true;
2020-07-12 00:48:51 +00:00
},
2018-08-04 15:53:22 +00:00
});
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
let task3Executed = false;
2019-09-22 13:16:27 +00:00
const task3 = new taskbuffer.Task({
2017-06-17 14:56:33 +00:00
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task3Executed = true;
2020-07-12 00:48:51 +00:00
},
2018-08-04 15:53:22 +00:00
});
2017-06-17 14:56:33 +00:00
tap.test('expect run tasks in sequence', async () => {
2019-09-22 13:16:27 +00:00
const testTaskchain = new taskbuffer.Taskchain({
2017-06-17 14:56:33 +00:00
name: 'Taskchain1',
2020-07-12 00:48:51 +00:00
taskArray: [task1, task2, task3],
2018-08-04 15:53:22 +00:00
});
2019-09-22 13:16:27 +00:00
const testPromise = testTaskchain.trigger();
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2100);
2017-06-17 14:56:33 +00:00
// tslint:disable-next-line:no-unused-expression
2022-03-25 11:14:49 +00:00
expect(task1Executed).toBeTrue();
2017-06-17 14:56:33 +00:00
// tslint:disable-next-line:no-unused-expression
2022-03-25 11:14:49 +00:00
expect(task2Executed).toBeFalse();
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2100);
2017-06-17 14:56:33 +00:00
// tslint:disable-next-line:no-unused-expression
2022-03-25 11:14:49 +00:00
expect(task2Executed).toBeTrue();
2018-08-04 15:53:22 +00:00
await testPromise;
});
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
tap.start();