Skip to content

Commit

Permalink
Add unit tests for the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Spark-NF committed Nov 9, 2021
1 parent c18d1fb commit 09139af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ On the CLI, the header argument can be repeated. Format is "Name: value".

#### `--quiet`, `logger`
In CLI, the quiet flag will disable all output except errors.
Using the API, you can provide a logger config, which is either `null` to disable logging completely, a function taking any number of arguments, or an object with two members, `log` and `error`, each being a function taking any number of arguments.
Using the API, you can provide a logger config, which is either `null` to disable logging completely, a function taking any number of arguments, or an object with two members, `log` and `error`, each being a function taking any number of arguments.

* Default: `false` in CLI, `console` in API

Expand Down
2 changes: 1 addition & 1 deletion src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export interface IConfig {
mergedSegmentsFile?: string;
outputFile: string;
httpHeaders?: HttpHeaders;
logger?: ILogger | ((...params: any) => void);
logger?: ILogger | ((...params: any) => void) | null;
}
31 changes: 31 additions & 0 deletions test/Logger.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { buildLogger } from "../src/Logger";

describe("buildLogger", () => {
it("Should use the console by default", () => {
expect(buildLogger(undefined)).toBe(console);
});

it("Should return a no-op logger when passed null", () => {
const logger = buildLogger(null);

expect(typeof logger.error).toBe("function");
expect(typeof logger.log).toBe("function");
expect(logger.error).toBe(logger.log);
});

it("Should provide a logger object when passed a function", () => {
const input = (): void => { /* no-op */ };
const logger = buildLogger(input);

expect(logger.error).toBe(input);
expect(logger.log).toBe(input);
})

it("Should use the passed logged when provided", () => {
const input = {
error(): void { /* no-op */ },
log(): void { /* no-op */ },
};
expect(buildLogger(input)).toBe(input);
})
});

0 comments on commit 09139af

Please sign in to comment.