Skip to content

Commit

Permalink
increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Sep 24, 2016
1 parent 26c7af8 commit 1752cb6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/yago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class Yago extends EventEmitter {
register(runner: ITaskRunnerClass): void {
if (runner.taskName) {
this.runners[runner.taskName] = runner;
}
} else
throw new Error(`${runner.name} does not have a RunTask decoration.`);
}

schedule(cron: string, taskName: string, options?: TaskOptions): void {
Expand Down
11 changes: 9 additions & 2 deletions test/Yago.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { expect } from "chai";
import { Task } from "../src/task";
import { Yago } from "../src/yago";
import { ExecutionResult, ExecutionResultOutcome } from "../src/task_runner";
import { InProcessTaskQueue } from "../src/inprocess_task_queue";
import { DEFAULT_RETRY_COUNT, ExecutionResult, ExecutionResultOutcome } from "../src/task_runner";
import { HelloWorldTaskRunner } from "./dummy/helloworld_task_runner";
import { ThrowErrorTaskRunner } from "./dummy/throwerror_task_runner";
import { NoNameTaskRunner } from "./dummy/noname_task_runner";
import { MemoryStream } from "./helper/memory_stream";

describe("Yago", () => {
Expand All @@ -14,6 +16,7 @@ describe("Yago", () => {
output = new MemoryStream();
yago = new Yago({
output,
queue: new InProcessTaskQueue(),
interval: 5
});
yago.register(HelloWorldTaskRunner);
Expand Down Expand Up @@ -79,7 +82,7 @@ describe("Yago", () => {
let count = 0;
yago.on("errored", (task: Task, err: any) => {
expect(err).to.deep.eq(new Error("Something happened..."));
if (++count === 2)
if (++count === DEFAULT_RETRY_COUNT)
done();
});

Expand Down Expand Up @@ -109,4 +112,8 @@ describe("Yago", () => {

yago.start();
});

it("should throw error when registering unnamed TaskRunners", () => {
expect(yago.register.bind(yago, NoNameTaskRunner)).to.throw(Error, "NoNameTaskRunner does not have a RunTask decoration.");
});
});
11 changes: 11 additions & 0 deletions test/dummy/noname_task_runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
TaskRunner,
ExecutionResult, ExecutionResultOutcome,
ExecutionContext
} from "../../src/task_runner";

export class NoNameTaskRunner extends TaskRunner {
async execute(ctx: ExecutionContext) {
return new ExecutionResult(ExecutionResultOutcome.Success);
}
}
4 changes: 0 additions & 4 deletions test/dummy/throwerror_task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ export class ThrowErrorTaskRunner extends TaskRunner {
async execute(ctx: ExecutionContext) {
throw new Error("Something happened...");
}

retryCount(): number {
return 2;
}
}

0 comments on commit 1752cb6

Please sign in to comment.