Skip to content

Commit

Permalink
fix: not stringifying data if data logging is disabled (#114)
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
bricka authored Dec 13, 2022
1 parent 1428255 commit d756595
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/common/__test__/string-builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ test('makeStatus should add status', () => {

expect(result).toContain('200:OK');
});

test('makeData should not stringify data if configured not to', () => {
const config = {
...getGlobalConfig(),
data: false,
};
const a = {};
const b = {};
a.b = b;
b.a = a;
const sb = new StringBuilder(config);
const result = sb.makeData(a).build();
expect(result).toEqual('');
});
6 changes: 4 additions & 2 deletions src/common/string-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class StringBuilder {
}

makeData(data: object) {
const str = typeof data === `string` ? data : JSON.stringify(data);
if(this.config.data && data) this.printQueue.push(str);
if(this.config.data && data) {
const str = typeof data === `string` ? data : JSON.stringify(data);
this.printQueue.push(str);
}
return this;
}

Expand Down

0 comments on commit d756595

Please sign in to comment.