aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2019-12-11 09:40:22 -0500
committerKevin J Hoerr <kjhoerr@protonmail.com>2019-12-11 09:40:22 -0500
commit3ae4f9352ee73a21581735883b4049327dce07bf (patch)
tree6c24d2e14cf37474b6580d4b31cc4ec5ac215742 /src/util
parente51ba6220576172b39d1a96a9ab4dfba87769428 (diff)
downloadao-coverage-3ae4f9352ee73a21581735883b4049327dce07bf.tar.gz
ao-coverage-3ae4f9352ee73a21581735883b4049327dce07bf.tar.bz2
ao-coverage-3ae4f9352ee73a21581735883b4049327dce07bf.zip
Add Jest to handle unit and integration testing
Wrote a couple of initial unit tests for some of the logic-heavy points in the application, being logger.ts and formats.ts. Evidently colorize() causes an error when transforming on the Format object that's returned. Since that is specific to the Console transport anyways, I just moved it to the transport, since the unit test was only testing the passed label in the returned Formats object. Also the bash template has some issues that I didn't test (oops), so those are fixed now.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/logger.test.ts24
-rw-r--r--src/util/logger.ts19
2 files changed, 33 insertions, 10 deletions
diff --git a/src/util/logger.test.ts b/src/util/logger.test.ts
new file mode 100644
index 0000000..ca181c4
--- /dev/null
+++ b/src/util/logger.test.ts
@@ -0,0 +1,24 @@
+import configureLogger from "./logger";
+
+describe("Logger configurer", () => {
+ it("should set passed clazz as label", () => {
+ // Arrange
+ const clazz = "important-clazz-name";
+
+ // Act
+ const result = configureLogger(clazz);
+
+ // Assert
+ const adapter = {
+ level: "info",
+ message: "test/10"
+ };
+ const actual = result.format.transform(Object.assign({}, adapter));
+ expect(typeof actual).not.toEqual("boolean");
+ if (typeof actual !== "boolean") {
+ expect(actual.level).toEqual(adapter.level);
+ expect(actual.message).toEqual(adapter.message);
+ expect(actual.label).toEqual(clazz);
+ }
+ });
+});
diff --git a/src/util/logger.ts b/src/util/logger.ts
index d108ae0..27eeefe 100644
--- a/src/util/logger.ts
+++ b/src/util/logger.ts
@@ -6,6 +6,13 @@ const { Console } = winston.transports;
const LOG_LEVEL = process.env.LOG_LEVEL || "info";
+const consoleFormat = combine(
+ colorize(),
+ printf(({ level, message, label, timestamp }) => {
+ return `${timestamp} [${label}] ${level}: ${message}`;
+ })
+);
+
/**
* Provides standard logging format and output for the server.
*/
@@ -16,14 +23,6 @@ export default (
format: Format;
transports: Transport[];
} => ({
- format: combine(
- splat(),
- timestamp(),
- label({ label: clazz }),
- colorize(),
- printf(({ level, message, label, timestamp }) => {
- return `${timestamp} [${label}] ${level}: ${message}`;
- })
- ),
- transports: [new Console({ level: level })]
+ format: combine(splat(), timestamp(), label({ label: clazz })),
+ transports: [new Console({ level: level, format: consoleFormat })]
});