Skip to content

Commit 520f3eb

Browse files
committed
small fixes and tests
1 parent ee5395b commit 520f3eb

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

.size-limit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module.exports = [
160160
name: 'CDN Bundle (incl. Tracing)',
161161
path: createCDNPath('bundle.tracing.min.js'),
162162
gzip: true,
163-
limit: '38 KB',
163+
limit: '39 KB',
164164
},
165165
{
166166
name: 'CDN Bundle (incl. Tracing, Replay)',

packages/core/src/utils/merge.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
22
* Shallow merge two objects.
33
* Does not mutate the passed in objects.
4+
* Undefined/empty values in the merge object will overwrite existing values.
5+
*
46
* By default, this merges 2 levels deep.
57
*/
68
export function merge<T>(initialObj: T, mergeObj: T, levels = 2): T {
79
// If the merge value is not an object, or we have no merge levels left,
810
// we just set the value to the merge value
9-
if (typeof mergeObj !== 'object' || levels <= 0) {
11+
if (!mergeObj || typeof mergeObj !== 'object' || levels <= 0) {
1012
return mergeObj;
1113
}
1214

packages/core/test/lib/envelope.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ describe('createSpanEnvelope', () => {
9595
client = new TestClient(options);
9696
setCurrentClient(client);
9797
client.init();
98+
99+
// We want to avoid console errors in the tests
100+
jest.spyOn(console, 'error').mockImplementation(() => {});
101+
});
102+
103+
afterEach(() => {
104+
jest.resetAllMocks();
98105
});
99106

100107
it('creates a span envelope', () => {

packages/core/test/lib/utils/merge.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,25 @@ describe('merge', () => {
5151
expect(actual).not.toBe(oldData);
5252
expect(actual).not.toBe(newData);
5353
});
54+
55+
it.each([
56+
[undefined, { a: 'aa' }, { a: 'aa' }],
57+
[{ a: 'aa' }, undefined, undefined],
58+
[{ a: 'aa' }, null, null],
59+
[{ a: 'aa' }, { a: undefined }, { a: undefined }],
60+
[{ a: 'aa' }, { a: null }, { a: null }],
61+
[{ a: 'aa' }, { a: '' }, { a: '' }],
62+
[
63+
{ a0: { a1: { a2: { a3: { a4: 'a4a' }, a3a: 'a3a' }, a2a: 'a2a' }, a1a: 'a1a' }, a0a: 'a0a' },
64+
{ a0: { a1: { a2: { a3: { a4: 'a4b' }, a3b: 'a3b' }, a2b: 'a2b' }, a1b: 'a1b' }, a0b: 'a0b' },
65+
{
66+
a0: { a1: { a2: { a3: { a4: 'a4a' }, a3b: 'a3a' }, a2b: 'a2b' }, a1b: 'a1b', a1a: 'a1a' },
67+
a0b: 'a0b',
68+
a0a: 'a0a',
69+
},
70+
],
71+
])('works with %p and %p', (oldData, newData, expected) => {
72+
const actual = merge(oldData, newData as any);
73+
expect(actual).toEqual(expected);
74+
});
5475
});

0 commit comments

Comments
 (0)