diff --git a/README.md b/README.md index f2aa197..b7acb1f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Config.ts b/src/Config.ts index 51bbee9..d4bd8c6 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -13,5 +13,5 @@ export interface IConfig { mergedSegmentsFile?: string; outputFile: string; httpHeaders?: HttpHeaders; - logger?: ILogger | ((...params: any) => void); + logger?: ILogger | ((...params: any) => void) | null; } diff --git a/test/Logger.spec.ts b/test/Logger.spec.ts new file mode 100644 index 0000000..0a99438 --- /dev/null +++ b/test/Logger.spec.ts @@ -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); + }) +});