diff --git a/packages/browser-integration-tests/suites/public-api/setContext/multiple_contexts/test.ts b/packages/browser-integration-tests/suites/public-api/setContext/multiple_contexts/test.ts index d1e85f49cf27..29ab95edb776 100644 --- a/packages/browser-integration-tests/suites/public-api/setContext/multiple_contexts/test.ts +++ b/packages/browser-integration-tests/suites/public-api/setContext/multiple_contexts/test.ts @@ -16,7 +16,6 @@ sentryTest('should record multiple contexts', async ({ getLocalTestPath, page }) baz: { qux: 'quux' }, }, context_2: { 1: 'foo', bar: false }, - context_4: '[undefined]', context_5: '[NaN]', context_6: 3.141592653589793, }); diff --git a/packages/replay/test/unit/coreHandlers/util/addBreadcrumbEvent.test.ts b/packages/replay/test/unit/coreHandlers/util/addBreadcrumbEvent.test.ts index 436aa79162a1..45483ebab5b4 100644 --- a/packages/replay/test/unit/coreHandlers/util/addBreadcrumbEvent.test.ts +++ b/packages/replay/test/unit/coreHandlers/util/addBreadcrumbEvent.test.ts @@ -39,7 +39,7 @@ describe('Unit | coreHandlers | util | addBreadcrumbEvent', function () { category: 'console', message: 'Test message', thisIsNull: null, - thisIsUndefined: '[undefined]', + thisIsUndefined: undefined, circular: '[Circular ~]', timestamp: BASE_TIMESTAMP / 1000, }, diff --git a/packages/utils/src/normalize.ts b/packages/utils/src/normalize.ts index 6bc4afadbf28..1f200640dbb1 100644 --- a/packages/utils/src/normalize.ts +++ b/packages/utils/src/normalize.ts @@ -79,7 +79,10 @@ function visit( const [memoize, unmemoize] = memo; // Get the simple cases out of the way first - if (value === null || (['number', 'boolean', 'string'].includes(typeof value) && !isNaN(value))) { + if ( + value == null || // this matches null and undefined -> eqeq not eqeqeq + (['number', 'boolean', 'string'].includes(typeof value) && !isNaN(value)) + ) { return value as Primitive; } @@ -220,11 +223,6 @@ function stringifyValue( return '[NaN]'; } - // this catches `undefined` (but not `null`, which is a primitive and can be serialized on its own) - if (value === void 0) { - return '[undefined]'; - } - if (typeof value === 'function') { return `[Function: ${getFunctionName(value)}]`; } diff --git a/packages/utils/test/normalize.test.ts b/packages/utils/test/normalize.test.ts index 76579d29e048..c1c90a7ec07d 100644 --- a/packages/utils/test/normalize.test.ts +++ b/packages/utils/test/normalize.test.ts @@ -14,6 +14,7 @@ describe('normalize()', () => { expect(normalize(42)).toEqual(42); expect(normalize(true)).toEqual(true); expect(normalize(null)).toEqual(null); + expect(normalize(undefined)).toBeUndefined(); }); test('return same object or arrays for referenced inputs', () => { @@ -403,7 +404,6 @@ describe('normalize()', () => { describe('changes unserializeable/global values/classes to their respective string representations', () => { test('primitive values', () => { - expect(normalize(undefined)).toEqual('[undefined]'); expect(normalize(NaN)).toEqual('[NaN]'); expect(normalize(Symbol('dogs'))).toEqual('[Symbol(dogs)]'); // `BigInt` doesn't exist in Node 8 @@ -425,28 +425,26 @@ describe('normalize()', () => { }); test('primitive values in objects/arrays', () => { - expect(normalize(['foo', 42, undefined, NaN])).toEqual(['foo', 42, '[undefined]', '[NaN]']); + expect(normalize(['foo', 42, NaN])).toEqual(['foo', 42, '[NaN]']); expect( normalize({ foo: 42, - bar: undefined, - baz: NaN, + bar: NaN, }), ).toEqual({ foo: 42, - bar: '[undefined]', - baz: '[NaN]', + bar: '[NaN]', }); }); test('primitive values in deep objects/arrays', () => { - expect(normalize(['foo', 42, [[undefined]], [NaN]])).toEqual(['foo', 42, [['[undefined]']], ['[NaN]']]); + expect(normalize(['foo', 42, [[undefined]], [NaN]])).toEqual(['foo', 42, [[undefined]], ['[NaN]']]); expect( normalize({ foo: 42, bar: { baz: { - quz: undefined, + quz: null, }, }, wat: { @@ -457,7 +455,7 @@ describe('normalize()', () => { foo: 42, bar: { baz: { - quz: '[undefined]', + quz: null, }, }, wat: {