Skip to content

Commit

Permalink
test parsing debug levels
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson committed Dec 4, 2024
1 parent 1a68e24 commit 464d517
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
30 changes: 30 additions & 0 deletions __tests__/unit/logger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { LOG_LEVELS, parseDebugLevel } from "../../src";

describe("logging", () => {
describe("parseDebugLevel", () => {
it.each`
testName | input | result
${"'0'"} | ${"0"} | ${"0"}
${"'1'"} | ${"1"} | ${"1"}
${"'2'"} | ${"2"} | ${"2"}
${"'3'"} | ${"3"} | ${"3"}
${"'4'"} | ${"4"} | ${"4"}
${"LOG_LEVELS.TRACE"} | ${LOG_LEVELS.TRACE} | ${LOG_LEVELS.TRACE}
${"LOG_LEVELS.DEBUG"} | ${LOG_LEVELS.DEBUG} | ${LOG_LEVELS.DEBUG}
${"LOG_LEVELS.INFO"} | ${LOG_LEVELS.INFO} | ${LOG_LEVELS.INFO}
${"LOG_LEVELS.WARN"} | ${LOG_LEVELS.WARN} | ${LOG_LEVELS.WARN}
${"LOG_LEVELS.ERROR"} | ${LOG_LEVELS.ERROR} | ${LOG_LEVELS.ERROR}
${"empty"} | ${""} | ${"4"}
${"null"} | ${null} | ${"4"}
${"undefined"} | ${undefined} | ${"4"}
${"unkown number string"} | ${"42"} | ${"4"}
${"unknown string"} | ${"asdf"} | ${"4"}
${"number"} | ${42} | ${"4"}
`(
"correctly parses input '$input' to log level '$result'",
({ input, result }) => {
expect(parseDebugLevel(input)).toBe(result);
},
);
});
});
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ export {
type HTTPStreamClient,
type StreamAdapter,
} from "./http-client";
export { LogLevel, LOG_LEVELS, ConsoleLogHandler } from "./util/logging";
export {
LogLevel,
LOG_LEVELS,
ConsoleLogHandler,
parseDebugLevel,
} from "./util/logging";

0 comments on commit 464d517

Please sign in to comment.