fix: console assert only logs when arg 0 is falsy (#1530)

* fix: console assert only logs when arg 0 is falsy
This commit is contained in:
Paul D'Ambra
2024-07-02 14:28:24 +01:00
committed by GitHub
parent 89ae4d2bad
commit 874933b550
4 changed files with 53 additions and 36 deletions

View File

@@ -189,6 +189,12 @@ function initLogObserver(
(original: (...args: Array<unknown>) => void) => {
return (...args: Array<unknown>) => {
original.apply(this, args);
if (level === 'assert' && !!args[0]) {
// assert does not log if the first argument evaluates to true
return;
}
if (inStack) {
// If we are already in a stack this means something from the following code is calling a console method
// likely a proxy method called from stringify. We don't want to log this as it will cause an infinite loop
@@ -199,7 +205,11 @@ function initLogObserver(
const trace = ErrorStackParser.parse(new Error())
.map((stackFrame: StackFrame) => stackFrame.toString())
.splice(1); // splice(1) to omit the hijacked log function
const payload = args.map((s) =>
// assert does not log its first arg, that's only used for deciding whether to log
const argsForPayload = level === 'assert' ? args.slice(1) : args;
const payload = argsForPayload.map((s) =>
stringify(s, logOptions.stringifyOptions),
);
logCount++;