|
4 | 4 |
|
5 | 5 | import * as isModule from '../src/is'; |
6 | 6 | import { normalize } from '../src/normalize'; |
| 7 | +import { addNonEnumerableProperty } from '../src/object'; |
7 | 8 | import * as stacktraceModule from '../src/stacktrace'; |
8 | 9 |
|
9 | 10 | describe('normalize()', () => { |
@@ -504,4 +505,52 @@ describe('normalize()', () => { |
504 | 505 | qux: '[Function: qux]', |
505 | 506 | }); |
506 | 507 | }); |
| 508 | + |
| 509 | + describe('skips normalizing objects marked with a non-enumerable property __sentry_skip_normalization__', () => { |
| 510 | + test('by leaving non-serializable values intact', () => { |
| 511 | + const someFun = () => undefined; |
| 512 | + const alreadyNormalizedObj = { |
| 513 | + nan: NaN, |
| 514 | + fun: someFun, |
| 515 | + }; |
| 516 | + |
| 517 | + addNonEnumerableProperty(alreadyNormalizedObj, '__sentry_skip_normalization__', true); |
| 518 | + |
| 519 | + const result = normalize(alreadyNormalizedObj); |
| 520 | + expect(result).toEqual({ |
| 521 | + nan: NaN, |
| 522 | + fun: someFun, |
| 523 | + }); |
| 524 | + }); |
| 525 | + |
| 526 | + test('by ignoring normalization depth', () => { |
| 527 | + const alreadyNormalizedObj = { |
| 528 | + three: { |
| 529 | + more: { |
| 530 | + layers: '!', |
| 531 | + }, |
| 532 | + }, |
| 533 | + }; |
| 534 | + |
| 535 | + addNonEnumerableProperty(alreadyNormalizedObj, '__sentry_skip_normalization__', true); |
| 536 | + |
| 537 | + const obj = { |
| 538 | + foo: { |
| 539 | + bar: { |
| 540 | + baz: alreadyNormalizedObj, |
| 541 | + boo: { |
| 542 | + bam: { |
| 543 | + pow: 'poof', |
| 544 | + }, |
| 545 | + }, |
| 546 | + }, |
| 547 | + }, |
| 548 | + }; |
| 549 | + |
| 550 | + const result = normalize(obj, 4); |
| 551 | + |
| 552 | + expect(result?.foo?.bar?.baz?.three?.more?.layers).toBe('!'); |
| 553 | + expect(result?.foo?.bar?.boo?.bam?.pow).not.toBe('poof'); |
| 554 | + }); |
| 555 | + }); |
507 | 556 | }); |
0 commit comments