2016-05-05 17:30:24 +00:00
|
|
|
"use strict";
|
2016-02-18 21:26:18 +00:00
|
|
|
/// <reference path="../ts/typings/main.d.ts" />
|
2016-07-31 22:53:27 +00:00
|
|
|
const taskbuffer = require("../dist/index");
|
|
|
|
let should = require("should");
|
|
|
|
let plugins = {
|
2016-05-06 00:05:45 +00:00
|
|
|
q: require("q")
|
|
|
|
};
|
2016-05-15 01:16:50 +00:00
|
|
|
// setup some testData to work with
|
2016-07-31 22:53:27 +00:00
|
|
|
let testTask;
|
|
|
|
let testTaskFunction = function () {
|
|
|
|
let done = plugins.q.defer();
|
2016-05-06 00:05:45 +00:00
|
|
|
console.log("main function executed!");
|
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-31 22:53:27 +00:00
|
|
|
let testPreTask = new taskbuffer.Task({
|
2016-05-14 02:28:22 +00:00
|
|
|
taskFunction: function () {
|
|
|
|
console.log("preTask executed");
|
|
|
|
},
|
|
|
|
preTask: testTask
|
|
|
|
});
|
2016-05-04 00:49:43 +00:00
|
|
|
describe("taskbuffer", function () {
|
2016-05-06 00:05:45 +00:00
|
|
|
describe(".Task", function () {
|
|
|
|
it("new Task() should return a new task", function () {
|
|
|
|
testTask = new taskbuffer.Task({ taskFunction: testTaskFunction, preTask: testPreTask });
|
2016-05-04 00:49:43 +00:00
|
|
|
});
|
2016-05-05 17:30:24 +00:00
|
|
|
it("testTask should be and instance of Task", function () {
|
|
|
|
testTask.should.be.instanceof(taskbuffer.Task);
|
2016-05-04 00:49:43 +00:00
|
|
|
});
|
|
|
|
it("testTask.idle is true", function () {
|
|
|
|
if (!testTask.idle) {
|
|
|
|
throw new Error("testTask.idle is not true");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
it("testTask.running is type boolean and initially false", function () {
|
|
|
|
testTask.running.should.be.type("boolean");
|
|
|
|
testTask.running.should.be.false();
|
2016-02-12 03:49:31 +00:00
|
|
|
});
|
2016-05-06 00:05:45 +00:00
|
|
|
it("testTask.trigger() should return Promise", function () {
|
|
|
|
testTask.trigger().should.be.Promise();
|
|
|
|
});
|
|
|
|
it("testTask.trigger() returned Promise should be fullfilled", function (done) {
|
|
|
|
testTask.trigger()
|
|
|
|
.then(done);
|
|
|
|
});
|
2016-05-15 01:16:50 +00:00
|
|
|
it("should run a task without pre and afterTask", function (done) {
|
2016-07-31 22:53:27 +00:00
|
|
|
let localTestTask = new taskbuffer.Task({ taskFunction: testTaskFunction });
|
2016-05-15 01:16:50 +00:00
|
|
|
localTestTask.trigger().then(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("Taskchain", function () {
|
2016-07-31 22:53:27 +00:00
|
|
|
let testTaskchain;
|
|
|
|
let testTaskArray = [
|
2016-05-15 01:16:50 +00:00
|
|
|
new taskbuffer.Task({
|
|
|
|
name: "task1",
|
|
|
|
taskFunction: function () {
|
2016-07-31 22:53:27 +00:00
|
|
|
let done = plugins.q.defer();
|
2016-05-15 13:52:59 +00:00
|
|
|
setTimeout(done.resolve, 2000);
|
2016-05-15 01:16:50 +00:00
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
new taskbuffer.Task({
|
|
|
|
name: "task2",
|
|
|
|
taskFunction: function () {
|
2016-07-31 22:53:27 +00:00
|
|
|
let done = plugins.q.defer();
|
2016-05-15 13:52:59 +00:00
|
|
|
setTimeout(done.resolve, 2000);
|
2016-05-15 01:16:50 +00:00
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
it("should run tasks in sequence", function (done) {
|
2016-05-15 13:52:59 +00:00
|
|
|
this.timeout(5000);
|
2016-05-15 01:16:50 +00:00
|
|
|
testTaskchain = new taskbuffer.Taskchain({
|
|
|
|
name: "Taskchain1",
|
|
|
|
taskArray: testTaskArray
|
|
|
|
});
|
|
|
|
testTaskchain.trigger().then(done);
|
|
|
|
});
|
2016-02-12 03:49:31 +00:00
|
|
|
});
|
|
|
|
});
|
2016-07-31 22:53:27 +00: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