taskbuffer/test/test.7.taskloop.ts

52 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2023-07-26 12:16:33 +00:00
import { tap, expect } from '@push.rocks/tapbundle';
2019-09-22 13:16:27 +00:00
2022-03-25 11:14:49 +00:00
import * as taskbuffer from '../ts/index.js';
2019-09-22 13:16:27 +00:00
let preTask: taskbuffer.Task;
let afterTask: taskbuffer.Task;
let mainTask: taskbuffer.Task;
tap.test('should create tasks', async () => {
preTask = new taskbuffer.Task({
name: 'myPreTask',
taskFunction: async () => {
console.log('pretask executed :)');
2019-09-23 14:31:06 +00:00
return 'hi';
2020-07-12 00:48:51 +00:00
},
2019-09-22 13:16:27 +00:00
});
afterTask = new taskbuffer.Task({
name: 'myAfterTask',
2020-07-12 00:48:51 +00:00
taskFunction: async (x) => {
2019-09-23 14:31:06 +00:00
if (x === 'hi') {
console.log('afterTask: values get passed along alright');
}
2019-09-22 13:16:27 +00:00
console.log('afterTask executed :)');
2019-09-23 14:31:06 +00:00
return x;
2019-09-22 13:16:27 +00:00
},
preTask,
2020-07-12 00:48:51 +00:00
afterTask,
2019-09-22 13:16:27 +00:00
});
mainTask = new taskbuffer.Task({
name: 'mainTask',
2020-07-12 00:48:51 +00:00
taskFunction: async (x) => {
2019-09-23 14:31:06 +00:00
if (x === 'hi') {
console.log('mainTask: values get passed along alright');
}
console.log('afterTask executed :)');
return x;
2019-09-22 13:16:27 +00:00
},
2019-09-23 16:06:43 +00:00
preTask: () => {
return preTask;
},
2020-07-12 00:48:51 +00:00
afterTask,
2019-09-22 13:16:27 +00:00
});
});
2019-09-23 16:06:43 +00:00
tap.test('should execute the mainTask', async () => {
2019-09-22 13:16:27 +00:00
await mainTask.trigger();
});
tap.start();