Skip to content

Commit

Permalink
Fix: normalize should use Options limits or default (#766)
Browse files Browse the repository at this point in the history
* pass parameters from options

* space

* add changelog

* use cache when false or empty

* fix cache hit on build

* fix cache hit on build

* use node v4 and checkout v4
  • Loading branch information
lucas-zimerman authored Nov 5, 2024
1 parent ab94981 commit 886e501
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
timeout-minutes: 15
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
# we use a hash of yarn.lock as our cache key, because if it hasn't changed, our dependencies haven't changed,
# so no need to reinstall them
- name: Compute dependency cache key
Expand All @@ -38,7 +38,7 @@ jobs:
key: ${{ steps.compute_lockfile_hash.outputs.hash }}

- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit == ''
if: steps.cache_dependencies.outputs.cache-hit != 'true'
run: yarn install
outputs:
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
Expand All @@ -50,9 +50,9 @@ jobs:
timeout-minutes: 15
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
- name: Check dependency cache
uses: actions/[email protected]
with:
Expand All @@ -69,11 +69,11 @@ jobs:
# packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues
# where the built packages are beside the point. In that case, you can change `BUILD_CACHE_KEY` (at the top of
# this file) to a constant and skip rebuilding all of the packages each time CI runs.
if: steps.cache_built_packages.outputs.cache-hit == ''
if: steps.cache_built_packages.outputs.cache-hit != 'true'
run: yarn build
# yarn.lock cannot be dirty when releasing a new version.
- name: Check if yarn.lock is dirty
if: steps.cache_built_packages.outputs.cache-hit == ''
if: steps.cache_built_packages.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Publish package locally
run: |
Expand Down Expand Up @@ -107,9 +107,9 @@ jobs:
- bump: 'sample-vue'
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
- name: Check dependency cache
uses: actions/[email protected]
with:
Expand Down Expand Up @@ -149,9 +149,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
- name: Check dependency cache
uses: actions/[email protected]
with:
Expand All @@ -171,9 +171,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
- name: Check dependency cache
uses: actions/[email protected]
with:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
> [migration guide](https://docs.sentry.io/platforms/javascript/guides/capacitor/migration/) first.
<!-- prettier-ignore-end -->
## Unreleased

### Fixes

- options normalizeDepth and normalizeMaxBreadth are now being respected when adding a breadcrumb. ([#766](https://github.com/getsentry/sentry-capacitor/pull/766))

## 1.0.1

### Dependencies
Expand Down
4 changes: 3 additions & 1 deletion src/utils/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getClient } from '@sentry/core';
import { normalize } from '@sentry/utils';

const KEY = 'value';
Expand All @@ -7,7 +8,8 @@ const KEY = 'value';
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function convertToNormalizedObject(data: unknown): Record<string, any> {
const normalized: unknown = normalize(data);
const options = getClient()?.getOptions();
const normalized: unknown = normalize(data, options?.normalizeDepth, options?.normalizeMaxBreadth);
if (normalized === null || typeof normalized !== 'object') {
return {
[KEY]: normalized,
Expand Down
50 changes: 50 additions & 0 deletions test/utils/normalize.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { getClient } from '@sentry/core';

jest.mock('@sentry/core', () => ({
getClient: jest.fn(),
}));
import { convertToNormalizedObject } from '../../src/utils/normalize';

describe('normalize', () => {
describe('convertToNormalizedObject', () => {
beforeEach(() => {
(getClient as jest.Mock).mockReturnValue({
getOptions: jest.fn().mockReturnValue({
normalizeDepth: undefined,
normalizeMaxBreadth: undefined,
}),
});
});

test('output equals input for normalized objects', () => {
const actualResult = convertToNormalizedObject({ foo: 'bar' });
expect(actualResult).toEqual({ foo: 'bar' });
Expand All @@ -21,5 +35,41 @@ describe('normalize', () => {
const actualResult = convertToNormalizedObject(null);
expect(actualResult).toEqual({ value: null });
});

test('respect normalizeDepth and normalizeMaxBreadth when set', () => {
(getClient as jest.Mock).mockReturnValue({
getOptions: jest.fn().mockReturnValue({
normalizeDepth: 2,
normalizeMaxBreadth: 3,
})
});
const obj = {
key1: '1',
keyparent: {
child1: '1',
childparent2: {
child1: '1'
},
child2: '2',
child3: '3'
},
key2: '2',
key3: '3',
};
const expectedObj = {
key1: '1',
keyparent: {
child1: '1',
childparent2: '[Object]',
child2: '2',
child3: '[MaxProperties ~]'
},
key2: '2',
key3: '[MaxProperties ~]',
}

const actualResult = convertToNormalizedObject(obj);
expect((actualResult)).toStrictEqual(expectedObj);
});
});
});

0 comments on commit 886e501

Please sign in to comment.