Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fullstack-build/tslog
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Dec 18, 2022
2 parents 3a0866e + 00bd40d commit 3e5612a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/BaseLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export class BaseLogger<LogObj> {
? new Date(source.getTime())
: source != null && typeof source === "object"
? Object.getOwnPropertyNames(source).reduce((o, prop) => {
Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop)!);
// mask
o[prop] = keys.includes(this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : prop.toLowerCase())
? this.settings.maskPlaceholder
Expand Down
32 changes: 17 additions & 15 deletions tests/Nodejs/14_Getters_Setters.test.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
import { ok } from "assert";
import "ts-jest";
import { ok } from "assert";
import { Logger } from "../../src/index.js";
import { mockConsoleLog } from "./helper.js";
import { getConsoleLog, mockConsoleLog } from "./helper.js";

class MissingSetter {
get test(): string {
get testProp(): string {
return "test";
}
}

const missingSetter = {
get test(): string {
get testProp(): string {
return "test";
}
}
},
};

describe("Getters and setters", () => {
beforeEach(() => {
mockConsoleLog(true, false);
});
test("[class] should not print getters", (): void => {

test("[class] should not print getters on class instance (prototype)", (): void => {
// Node.js issue: https://github.com/nodejs/node/issues/30183
const logger = new Logger({
type: "hidden",
type: "pretty",
});
const missingSetterObj = new MissingSetter();

const result = logger.info(missingSetterObj);

ok(result);
Object.keys(result).forEach((key) => {
expect(key).not.toBe("test");
});
expect(Object.keys(result)).not.toContain("testProp");
expect(getConsoleLog()).not.toContain("testProp");
});

test("[object] should print getters", (): void => {
const logger = new Logger({
type: "hidden",
type: "pretty",
});
const result = logger.info(missingSetter);
expect(result).toContain("test");
ok(result);
expect(Object.keys(result)).toContain("testProp");
expect(getConsoleLog()).toContain("testProp");
});
});

0 comments on commit 3e5612a

Please sign in to comment.