Skip to content

Commit

Permalink
\#192: Add additional protection against logs with JSON serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
archfz committed Jun 29, 2023
1 parent 9eda953 commit 6783aa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ directory. You should add `it.only` to the test case you are working on to speed
## Release Notes
- Fix circular reference causing error with expect logging. [issue](https://github.com/archfz/cypress-terminal-report/issues/192)
- Fix circular reference causing error with expect logging. [issue](https://github.com/archfz/cypress-terminal-report/issues/191)
- Add additional protection against logs containing objects that are non JSON serializable and also don't have `.toString()`. [issue](https://github.com/archfz/cypress-terminal-report/issues/192)
#### 5.2.0
Expand Down
10 changes: 8 additions & 2 deletions src/collector/LogCollectBrowserConsole.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const LOG_TYPE = require('../constants').LOG_TYPES;
const CONSTANTS = require('../constants');
const stringify = require('safe-json-stringify');
const {type} = require("mocha/lib/utils");

module.exports = class LogCollectBrowserConsole {

Expand Down Expand Up @@ -34,9 +36,13 @@ module.exports = class LogCollectBrowserConsole {

let json = '';
try {
json = JSON.stringify(arg, null, 2);
json = stringify(arg, null, 2);
} catch (e) {
return '[unprocessable=' + arg + ']';
if (typeof arg.toString === 'function') {
return '[unprocessable=' + arg.toString() + ']';
} else {
return '[unprocessable]';
}
}

if (typeof json === 'undefined') {
Expand Down

0 comments on commit 6783aa8

Please sign in to comment.