taskbuffer/test/test.js

83 lines
10 KiB
JavaScript
Raw Normal View History

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-05-04 00:49:43 +00:00
var taskbuffer = require("../dist/index");
var should = require("should");
2016-05-06 00:05:45 +00:00
var plugins = {
q: require("q")
};
2016-05-15 01:16:50 +00:00
// setup some testData to work with
2016-05-06 00:05:45 +00:00
var testTask;
var testTaskFunction = function () {
var done = plugins.q.defer();
console.log("main function executed!");
done.resolve();
return done.promise;
};
2016-05-14 02:28:22 +00:00
var testPreTask = new taskbuffer.Task({
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) {
var localTestTask = new taskbuffer.Task({ taskFunction: testTaskFunction });
localTestTask.trigger().then(done);
});
});
describe("Taskchain", function () {
var testTaskchain;
var testTaskArray = [
new taskbuffer.Task({
name: "task1",
taskFunction: function () {
var 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 () {
var 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-05-04 02:28:50 +00:00
2016-05-15 13:52:59 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLGdEQUFnRDtBQUNoRCxJQUFPLFVBQVUsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUM3QyxJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7QUFDL0IsSUFBSSxPQUFPLEdBQUc7SUFDVixDQUFDLEVBQUUsT0FBTyxDQUFDLEdBQUcsQ0FBQztDQUNsQixDQUFBO0FBRUQsbUNBQW1DO0FBQ25DLElBQUksUUFBd0IsQ0FBQztBQUM3QixJQUFJLGdCQUFnQixHQUFHO0lBQ25CLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsT0FBTyxDQUFDLEdBQUcsQ0FBQyx5QkFBeUIsQ0FBQyxDQUFBO0lBQ3RDLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUNmLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQTtBQUNELElBQUksV0FBVyxHQUFHLElBQUksVUFBVSxDQUFDLElBQUksQ0FBQztJQUNsQyxZQUFZLEVBQUM7UUFDVCxPQUFPLENBQUMsR0FBRy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