fix(core): update

This commit is contained in:
2020-07-12 00:48:51 +00:00
parent f21b53b81d
commit fdfb780c33
28 changed files with 9040 additions and 841 deletions

View File

@ -11,7 +11,7 @@ let testPreTask = new taskbuffer.Task({
taskFunction: async () => {
console.log('preTask executed');
},
preTask: testTask
preTask: testTask,
});
// some more tasks to test with
@ -27,7 +27,7 @@ let task1 = new taskbuffer.Task({
done.resolve();
}, 5000);
return done.promise;
}
},
});
let task2 = new taskbuffer.Task({
@ -40,7 +40,7 @@ let task2 = new taskbuffer.Task({
done.resolve();
}, 5000);
await done.promise;
}
},
});
let task3 = new taskbuffer.Task({
@ -53,7 +53,7 @@ let task3 = new taskbuffer.Task({
done.resolve();
}, 5000);
return done.promise;
}
},
});
tap.test('new Task() should return a new task', async () => {
@ -61,7 +61,7 @@ tap.test('new Task() should return a new task', async () => {
taskFunction: async () => {
console.log('executed twice');
},
preTask: testPreTask
preTask: testPreTask,
});
});
@ -93,7 +93,7 @@ tap.test('expect to run a task without pre and afterTask errorless', async () =>
let localTestTask = new taskbuffer.Task({
taskFunction: async () => {
console.log('only once');
}
},
});
await localTestTask.trigger();
});
@ -104,7 +104,7 @@ tap.test('expect task to run in buffered mode', async () => {
await smartdelay.delayFor(3000);
},
buffered: true,
bufferMax: 2
bufferMax: 2,
});
localTestTask.trigger();
localTestTask.trigger();

View File

@ -9,7 +9,7 @@ const task1 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task1Executed = true;
}
},
});
let task2Executed = false;
@ -17,7 +17,7 @@ const task2 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task2Executed = true;
}
},
});
let task3Executed = false;
@ -25,13 +25,13 @@ const task3 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task3Executed = true;
}
},
});
tap.test('expect run tasks in sequence', async () => {
const testTaskchain = new taskbuffer.Taskchain({
name: 'Taskchain1',
taskArray: [task1, task2, task3]
taskArray: [task1, task2, task3],
});
const testPromise = testTaskchain.trigger();
await smartdelay.delayFor(2100);

View File

@ -7,7 +7,7 @@ const task1 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task1Executed = true;
}
},
});
let task2Executed = false;
@ -15,7 +15,7 @@ const task2 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task2Executed = true;
}
},
});
let task3Executed = false;
@ -23,12 +23,12 @@ const task3 = new taskbuffer.Task({
taskFunction: async () => {
await smartdelay.delayFor(2000);
task3Executed = true;
}
},
});
tap.test('expect run in Parallel', async () => {
const testTaskparallel = new taskbuffer.Taskparallel({
taskArray: [task1, task2, task3]
taskArray: [task1, task2, task3],
});
await testTaskparallel.trigger();
});

View File

@ -0,0 +1,42 @@
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
let myTaskManager: taskbuffer.TaskManager;
let taskRunCounter = 0;
const taskDone = smartpromise.defer();
tap.test('should create an instance of TaskManager', async () => {
myTaskManager = new taskbuffer.TaskManager();
expect(myTaskManager).to.be.instanceof(taskbuffer.TaskManager);
});
tap.test('should run the task as expected', async () => {
let referenceBoolean = false;
myTaskManager.addTask(
new taskbuffer.Task({
name: 'myTask',
taskFunction: async () => {
console.log('Task executed!');
referenceBoolean = true;
taskRunCounter++;
if (taskRunCounter === 10) {
taskDone.resolve();
}
},
})
);
await myTaskManager.triggerTaskByName('myTask');
// tslint:disable-next-line:no-unused-expression
expect(referenceBoolean).to.be.true;
});
tap.test('should schedule task', async () => {
myTaskManager.scheduleTaskByName('myTask', '* * * * * *');
await taskDone.promise;
myTaskManager.descheduleTaskByName('myTask');
});
tap.start();

View File

@ -25,7 +25,7 @@ tap.test('should run the task as expected', async () => {
if (taskRunCounter === 10) {
taskDone.resolve();
}
}
},
})
);
await myTaskManager.triggerTaskByName('myTask');

View File

@ -11,7 +11,7 @@ const flowTask1 = new taskbuffer.Task({
console.log(x);
done.resolve(x);
return done.promise;
}
},
});
const flowTaskBuffered = new taskbuffer.Task({
@ -23,7 +23,7 @@ const flowTaskBuffered = new taskbuffer.Task({
return done.promise;
},
buffered: true,
bufferMax: 1
bufferMax: 1,
});
const flowTask2 = new taskbuffer.Task({
@ -34,11 +34,11 @@ const flowTask2 = new taskbuffer.Task({
done.resolve(x);
return done.promise;
},
preTask: flowTask1
preTask: flowTask1,
});
const flowTask3 = new taskbuffer.Taskchain({
taskArray: [flowTask1, flowTask2]
taskArray: [flowTask1, flowTask2],
});
tap.test('should let a value flow through a task', async () => {

View File

@ -9,7 +9,7 @@ tap.test('should create a valid instance of TaskOnce', async () => {
myTaskOnce = new taskbuffer.TaskOnce({
taskFunction: async () => {
myNumber++;
}
},
});
expect(myTaskOnce).to.be.instanceof(taskbuffer.TaskOnce);
});

View File

@ -13,11 +13,11 @@ tap.test('should create tasks', async () => {
taskFunction: async () => {
console.log('pretask executed :)');
return 'hi';
}
},
});
afterTask = new taskbuffer.Task({
name: 'myAfterTask',
taskFunction: async x => {
taskFunction: async (x) => {
if (x === 'hi') {
console.log('afterTask: values get passed along alright');
}
@ -25,12 +25,12 @@ tap.test('should create tasks', async () => {
return x;
},
preTask,
afterTask
afterTask,
});
mainTask = new taskbuffer.Task({
name: 'mainTask',
taskFunction: async x => {
taskFunction: async (x) => {
if (x === 'hi') {
console.log('mainTask: values get passed along alright');
}
@ -40,7 +40,7 @@ tap.test('should create tasks', async () => {
preTask: () => {
return preTask;
},
afterTask
afterTask,
});
});

View File

@ -10,20 +10,24 @@ tap.test('should create a valid taskrunner', async () => {
tap.test('should execute task when its scheduled', async (tools) => {
const done = tools.defer();
testTaskRunner.addTask(new taskbuffer.Task({
taskFunction: async () => {
console.log('hi');
}
}));
testTaskRunner.addTask(
new taskbuffer.Task({
taskFunction: async () => {
console.log('hi');
},
})
);
testTaskRunner.addTask(new taskbuffer.Task({
taskFunction: async () => {
console.log('there');
done.resolve();
}
}));
testTaskRunner.addTask(
new taskbuffer.Task({
taskFunction: async () => {
console.log('there');
done.resolve();
},
})
);
await done.promise;
});
tap.start();
tap.start();