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:
5
.changeset/gold-experts-type.md
Normal file
5
.changeset/gold-experts-type.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@rrweb/rrweb-plugin-console-record": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
corrects behaviour of console.assert logging to only capture logs when the provided assertion is falsey
|
||||||
@@ -189,6 +189,12 @@ function initLogObserver(
|
|||||||
(original: (...args: Array<unknown>) => void) => {
|
(original: (...args: Array<unknown>) => void) => {
|
||||||
return (...args: Array<unknown>) => {
|
return (...args: Array<unknown>) => {
|
||||||
original.apply(this, args);
|
original.apply(this, args);
|
||||||
|
|
||||||
|
if (level === 'assert' && !!args[0]) {
|
||||||
|
// assert does not log if the first argument evaluates to true
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (inStack) {
|
if (inStack) {
|
||||||
// If we are already in a stack this means something from the following code is calling a console method
|
// 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
|
// 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())
|
const trace = ErrorStackParser.parse(new Error())
|
||||||
.map((stackFrame: StackFrame) => stackFrame.toString())
|
.map((stackFrame: StackFrame) => stackFrame.toString())
|
||||||
.splice(1); // splice(1) to omit the hijacked log function
|
.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),
|
stringify(s, logOptions.stringifyOptions),
|
||||||
);
|
);
|
||||||
logCount++;
|
logCount++;
|
||||||
|
|||||||
@@ -356,11 +356,10 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"assert\\",
|
\\"level\\": \\"assert\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:2:15\\"
|
\\"__puppeteer_evaluation_script__:3:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"true\\",
|
\\"\\\\\\"should log assert\\\\\\"\\"
|
||||||
\\"\\\\\\"assert\\\\\\"\\"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -371,21 +370,6 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"plugin\\": \\"rrweb/console@1\\",
|
\\"plugin\\": \\"rrweb/console@1\\",
|
||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"count\\",
|
\\"level\\": \\"count\\",
|
||||||
\\"trace\\": [
|
|
||||||
\\"__puppeteer_evaluation_script__:3:15\\"
|
|
||||||
],
|
|
||||||
\\"payload\\": [
|
|
||||||
\\"\\\\\\"count\\\\\\"\\"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
\\"type\\": 6,
|
|
||||||
\\"data\\": {
|
|
||||||
\\"plugin\\": \\"rrweb/console@1\\",
|
|
||||||
\\"payload\\": {
|
|
||||||
\\"level\\": \\"countReset\\",
|
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:4:15\\"
|
\\"__puppeteer_evaluation_script__:4:15\\"
|
||||||
],
|
],
|
||||||
@@ -400,10 +384,25 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"data\\": {
|
\\"data\\": {
|
||||||
\\"plugin\\": \\"rrweb/console@1\\",
|
\\"plugin\\": \\"rrweb/console@1\\",
|
||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"debug\\",
|
\\"level\\": \\"countReset\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:5:15\\"
|
\\"__puppeteer_evaluation_script__:5:15\\"
|
||||||
],
|
],
|
||||||
|
\\"payload\\": [
|
||||||
|
\\"\\\\\\"count\\\\\\"\\"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
\\"type\\": 6,
|
||||||
|
\\"data\\": {
|
||||||
|
\\"plugin\\": \\"rrweb/console@1\\",
|
||||||
|
\\"payload\\": {
|
||||||
|
\\"level\\": \\"debug\\",
|
||||||
|
\\"trace\\": [
|
||||||
|
\\"__puppeteer_evaluation_script__:6:15\\"
|
||||||
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"debug\\\\\\"\\"
|
\\"\\\\\\"debug\\\\\\"\\"
|
||||||
]
|
]
|
||||||
@@ -417,7 +416,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"dir\\",
|
\\"level\\": \\"dir\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:6:15\\"
|
\\"__puppeteer_evaluation_script__:7:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"dir\\\\\\"\\"
|
\\"\\\\\\"dir\\\\\\"\\"
|
||||||
@@ -432,7 +431,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"dirxml\\",
|
\\"level\\": \\"dirxml\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:7:15\\"
|
\\"__puppeteer_evaluation_script__:8:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"dirxml\\\\\\"\\"
|
\\"\\\\\\"dirxml\\\\\\"\\"
|
||||||
@@ -447,7 +446,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"group\\",
|
\\"level\\": \\"group\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:8:15\\"
|
\\"__puppeteer_evaluation_script__:9:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": []
|
\\"payload\\": []
|
||||||
}
|
}
|
||||||
@@ -460,7 +459,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"groupCollapsed\\",
|
\\"level\\": \\"groupCollapsed\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:9:15\\"
|
\\"__puppeteer_evaluation_script__:10:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": []
|
\\"payload\\": []
|
||||||
}
|
}
|
||||||
@@ -473,7 +472,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"info\\",
|
\\"level\\": \\"info\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:10:15\\"
|
\\"__puppeteer_evaluation_script__:11:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"info\\\\\\"\\"
|
\\"\\\\\\"info\\\\\\"\\"
|
||||||
@@ -488,7 +487,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"log\\",
|
\\"level\\": \\"log\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:11:15\\"
|
\\"__puppeteer_evaluation_script__:12:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"log\\\\\\"\\"
|
\\"\\\\\\"log\\\\\\"\\"
|
||||||
@@ -503,7 +502,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"table\\",
|
\\"level\\": \\"table\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:12:15\\"
|
\\"__puppeteer_evaluation_script__:13:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"table\\\\\\"\\"
|
\\"\\\\\\"table\\\\\\"\\"
|
||||||
@@ -518,7 +517,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"time\\",
|
\\"level\\": \\"time\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:13:15\\"
|
\\"__puppeteer_evaluation_script__:14:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": []
|
\\"payload\\": []
|
||||||
}
|
}
|
||||||
@@ -531,7 +530,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"timeEnd\\",
|
\\"level\\": \\"timeEnd\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:14:15\\"
|
\\"__puppeteer_evaluation_script__:15:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": []
|
\\"payload\\": []
|
||||||
}
|
}
|
||||||
@@ -544,7 +543,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"timeLog\\",
|
\\"level\\": \\"timeLog\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:15:15\\"
|
\\"__puppeteer_evaluation_script__:16:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": []
|
\\"payload\\": []
|
||||||
}
|
}
|
||||||
@@ -557,7 +556,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"trace\\",
|
\\"level\\": \\"trace\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:16:15\\"
|
\\"__puppeteer_evaluation_script__:17:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"trace\\\\\\"\\"
|
\\"\\\\\\"trace\\\\\\"\\"
|
||||||
@@ -572,7 +571,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"warn\\",
|
\\"level\\": \\"warn\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:17:15\\"
|
\\"__puppeteer_evaluation_script__:18:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"warn\\\\\\"\\"
|
\\"\\\\\\"warn\\\\\\"\\"
|
||||||
@@ -587,7 +586,7 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"clear\\",
|
\\"level\\": \\"clear\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:18:15\\"
|
\\"__puppeteer_evaluation_script__:19:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": []
|
\\"payload\\": []
|
||||||
}
|
}
|
||||||
@@ -600,10 +599,10 @@ exports[`rrweb-plugin-console-record > should record console messages 1`] = `
|
|||||||
\\"payload\\": {
|
\\"payload\\": {
|
||||||
\\"level\\": \\"log\\",
|
\\"level\\": \\"log\\",
|
||||||
\\"trace\\": [
|
\\"trace\\": [
|
||||||
\\"__puppeteer_evaluation_script__:19:15\\"
|
\\"__puppeteer_evaluation_script__:20:15\\"
|
||||||
],
|
],
|
||||||
\\"payload\\": [
|
\\"payload\\": [
|
||||||
\\"\\\\\\"TypeError: a message\\\\\\\\n at __puppeteer_evaluation_script__:19:19\\\\\\\\nEnd of stack for Error object\\\\\\"\\"
|
\\"\\\\\\"TypeError: a message\\\\\\\\n at __puppeteer_evaluation_script__:20:19\\\\\\\\nEnd of stack for Error object\\\\\\"\\"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,10 @@ describe('rrweb-plugin-console-record', () => {
|
|||||||
await page.goto(`${serverUrl}test/html/log.html`);
|
await page.goto(`${serverUrl}test/html/log.html`);
|
||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
console.assert(0 === 0, 'assert');
|
// truthy assert does not log
|
||||||
|
console.assert(0 === 0, 'should not log assert');
|
||||||
|
// falsy assert does log
|
||||||
|
console.assert(false, 'should log assert');
|
||||||
console.count('count');
|
console.count('count');
|
||||||
console.countReset('count');
|
console.countReset('count');
|
||||||
console.debug('debug');
|
console.debug('debug');
|
||||||
|
|||||||
Reference in New Issue
Block a user