Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid circular references when stringifying json #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

maroun9t
Copy link
Contributor

@maroun9t maroun9t commented Nov 4, 2024

Introduce a circularJsonStringify utility function. Using code from cycle.js, this function will simplify references to objects. This results in:

  • Objects that a referenced won't be repeated in the stringified json, instead replaced by their path, reducing the size of the string.
  • Circular references won't be an issue anymore because no referenced object will be present in the decycled result.

Copy link

CI Failure Feedback 🧐

Action: Tests 🧪

Failed stage: Test 🧪 [❌]

Failed test name: sdks-react packages/sdks/react/src/lib/Experience/useExperience.spec.tsx

Failure summary:

The action failed because the test useExperience.spec.tsx failed. The failure was due to the
following reasons:

  • The test is using ReactDOM.render, which is no longer supported in React 18. The warning suggests
    using createRoot instead.
  • There is an error indicating that a component using the context must be a descendant of the
    NinetailedProvider.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    513:  * [new branch]      DEV-3800-experience-js-privacy-plugin-race-condition-when-listening-on-enabled-features -> origin/DEV-3800-experience-js-privacy-plugin-race-condition-when-listening-on-enabled-features
    514:  * [new branch]      DEV-3831-experience-js-experience-mapper-wont-default-a-null-or-missing-variants-array-correctly -> origin/DEV-3831-experience-js-experience-mapper-wont-default-a-null-or-missing-variants-array-correctly
    515:  * [new branch]      DEV-4016-experience-js-sdk-insights-plugin-crashes-when-used-in-react-native -> origin/DEV-4016-experience-js-sdk-insights-plugin-crashes-when-used-in-react-native
    516:  * [new branch]      DEV-4194-gtm-template-track -> origin/DEV-4194-gtm-template-track
    517:  * [new branch]      DEV-4208-preview-plugin-multiple -> origin/DEV-4208-preview-plugin-multiple
    518:  * [new branch]      DEV-4223-abort-non-client-events-this -> origin/DEV-4223-abort-non-client-events-this
    519:  * [new branch]      DEV-4259-sdk-should-take-sticky-flag-from-experience-api-instead-of-cms-entry-into-account -> origin/DEV-4259-sdk-should-take-sticky-flag-from-experience-api-instead-of-cms-entry-into-account
    520:  * [new branch]      DEV-4362-privacy-plugin-break-loading-state -> origin/DEV-4362-privacy-plugin-break-loading-state
    521:  * [new branch]      DEV-4430-stop-abort-error-from-bubbling -> origin/DEV-4430-stop-abort-error-from-bubbling
    ...
    
    649:  [command]/usr/bin/tar -xf /home/runner/work/_temp/d8055458-6268-4f39-a594-76261a566b2f/cache.tzst -P -C /home/runner/work/experience.js/experience.js --use-compress-program unzstd
    650:  Received 409546065 of 409546065 (100.0%), 195.2 MBs/sec
    651:  Cache restored successfully
    652:  Cache restored from key: Linux-node-modules-yarn-c3f1d1144619d2e920e20f3f2da854d0e90a3b6c4e02a5b6e3c9bf6d54d61320
    653:  ##[group]Run nrwl/nx-set-shas@v3
    654:  with:
    655:  main-branch-name: main
    656:  set-environment-variables-for-job: true
    657:  error-on-no-successful-workflow: false
    658:  last-successful-event: push
    659:  working-directory: .
    660:  ##[endgroup]
    661:  ##[group]Run node "$GITHUB_ACTION_PATH/dist/index.js" "$gh_token" "$main_branch_name" "$error_on_no_successful_workflow" "$last_successful_event" "$working_directory" "$working_id"
    662:  �[36;1mnode "$GITHUB_ACTION_PATH/dist/index.js" "$gh_token" "$main_branch_name" "$error_on_no_successful_workflow" "$last_successful_event" "$working_directory" "$working_id"�[0m
    663:  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
    664:  env:
    665:  gh_token: ***
    666:  main_branch_name: main
    667:  error_on_no_successful_workflow: false
    ...
    
    805:  Time:        19.983 s
    806:  Ran all test suites.
    807:  > nx run sdks-react:test
    808:  PASS sdks-react packages/sdks/react/src/lib/Experience/ComponentMarker/ComponentMarker.spec.tsx (9.351 s)
    809:  PASS sdks-react packages/sdks/react/src/lib/MergeTag/helpers.spec.ts
    810:  PASS sdks-react packages/sdks/react/src/lib/MergeTag/MergeTag.spec.tsx (18.914 s)
    811:  FAIL sdks-react packages/sdks/react/src/lib/Experience/useExperience.spec.tsx (18.995 s)
    812:  ● Console
    813:  console.error
    814:  Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
    815:  88 |     };
    816:  89 |
    817:  > 90 |     const { result } = renderHook(
    818:  |                                  ^
    819:  91 |       () =>
    820:  92 |         useExperience({
    821:  93 |           baseline: {
    822:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    823:  at printWarning (../../../node_modules/react-dom/cjs/react-dom.development.js:86:30)
    824:  at error (../../../node_modules/react-dom/cjs/react-dom.development.js:60:7)
    ...
    
    826:  at ../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:80:18
    827:  at act (../../../node_modules/react/cjs/react.development.js:2512:16)
    828:  at render (../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:79:26)
    829:  at renderHook (../../../node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)
    830:  at src/lib/Experience/useExperience.spec.tsx:90:34
    831:  at ../../../node_modules/tslib/tslib.js:118:75
    832:  at Object.__awaiter (../../../node_modules/tslib/tslib.js:114:16)
    833:  at Object.<anonymous> (src/lib/Experience/useExperience.spec.tsx:59:79)
    834:  console.error
    835:  Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
    836:  151 |     };
    837:  152 |
    838:  > 153 |     const { result } = renderHook(
    839:  |                                  ^
    840:  154 |       () =>
    841:  155 |         useExperience({
    842:  156 |           baseline: {
    843:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    844:  at printWarning (../../../node_modules/react-dom/cjs/react-dom.development.js:86:30)
    845:  at error (../../../node_modules/react-dom/cjs/react-dom.development.js:60:7)
    ...
    
    847:  at ../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:80:18
    848:  at act (../../../node_modules/react/cjs/react.development.js:2512:16)
    849:  at render (../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:79:26)
    850:  at renderHook (../../../node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)
    851:  at src/lib/Experience/useExperience.spec.tsx:153:34
    852:  at ../../../node_modules/tslib/tslib.js:118:75
    853:  at Object.__awaiter (../../../node_modules/tslib/tslib.js:114:16)
    854:  at Object.<anonymous> (src/lib/Experience/useExperience.spec.tsx:119:61)
    855:  console.error
    856:  Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
    857:  226 |     (experience as any).exp = experience;
    858:  227 |
    859:  > 228 |     const { result } = renderHook(
    860:  |                                  ^
    861:  229 |       () =>
    862:  230 |         useExperience({
    863:  231 |           baseline,
    864:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    865:  at printWarning (../../../node_modules/react-dom/cjs/react-dom.development.js:86:30)
    866:  at error (../../../node_modules/react-dom/cjs/react-dom.development.js:60:7)
    ...
    
    883:  |                                   ^
    884:  173 |     expect(result.current.loading).toEqual(false);
    885:  174 |     expect(result.current.variantIndex).toEqual(1);
    886:  175 |     expect(result.current.variant).toEqual(
    887:  at src/lib/Experience/useExperience.spec.tsx:172:35
    888:  at fulfilled (../../../node_modules/tslib/tslib.js:115:62)
    889:  PASS sdks-react packages/sdks/react/src/lib/useNinetailed.spec.tsx (6.931 s)
    890:  ● Console
    891:  console.error
    892:  Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
    893:  17 |     };
    894:  18 |
    895:  > 19 |     const { result } = renderHook(() => useNinetailed(), {
    896:  |                                  ^
    897:  20 |       wrapper: contextWrapper,
    898:  21 |     });
    899:  22 |
    900:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    901:  at printWarning (../../../node_modules/react-dom/cjs/react-dom.development.js:86:30)
    902:  at error (../../../node_modules/react-dom/cjs/react-dom.development.js:60:7)
    903:  at Object.render (../../../node_modules/react-dom/cjs/react-dom.development.js:29670:5)
    904:  at ../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:80:18
    905:  at act (../../../node_modules/react/cjs/react.development.js:2512:16)
    906:  at render (../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:79:26)
    907:  at renderHook (../../../node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)
    908:  at Object.<anonymous> (src/lib/useNinetailed.spec.tsx:19:34)
    909:  console.error
    910:  Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
    911:  26 |
    912:  27 |   it('should throw an error if ninetailed context is not provided', () => {
    913:  > 28 |     const { result } = renderHook(() => useNinetailed());
    914:  |                                  ^
    915:  29 |
    916:  30 |     expect(result.error).toEqual(
    917:  31 |       new Error(
    918:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    919:  at printWarning (../../../node_modules/react-dom/cjs/react-dom.development.js:86:30)
    920:  at error (../../../node_modules/react-dom/cjs/react-dom.development.js:60:7)
    921:  at Object.render (../../../node_modules/react-dom/cjs/react-dom.development.js:29670:5)
    922:  at ../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:80:18
    923:  at act (../../../node_modules/react/cjs/react.development.js:2512:16)
    924:  at render (../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:79:26)
    925:  at renderHook (../../../node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)
    926:  at Object.<anonymous> (src/lib/useNinetailed.spec.tsx:28:34)
    927:  console.error
    928:  Error: Uncaught [Error: The component using the the context must be a descendant of the NinetailedProvider]
    929:  at reportException (/home/runner/work/experience.js/experience.js/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
    ...
    
    958:  at _runTestsForDescribeBlock (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/run.js:126:9)
    959:  at _runTestsForDescribeBlock (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/run.js:121:9)
    960:  at run (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/run.js:71:3)
    961:  at runAndTransformResultsToJestFormat (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    962:  at jestAdapter (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    963:  at runTestInternal (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/runTest.js:367:16)
    964:  at runTest (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/runTest.js:444:34)
    965:  at Object.worker (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/testWorker.js:106:12) {
    966:  detail: Error: The component using the the context must be a descendant of the NinetailedProvider
    ...
    
    1006:  at runAndTransformResultsToJestFormat (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    1007:  at jestAdapter (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    1008:  at runTestInternal (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/runTest.js:367:16)
    1009:  at runTest (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/runTest.js:444:34)
    1010:  at Object.worker (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/testWorker.js:106:12),
    1011:  type: 'unhandled exception'
    1012:  }
    1013:  26 |
    1014:  27 |   it('should throw an error if ninetailed context is not provided', () => {
    1015:  > 28 |     const { result } = renderHook(() => useNinetailed());
    1016:  |                                  ^
    1017:  29 |
    1018:  30 |     expect(result.error).toEqual(
    1019:  31 |       new Error(
    1020:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    1021:  at reportException (../../../node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:70:28)
    ...
    
    1036:  at legacyCreateRootFromDOMContainer (../../../node_modules/react-dom/cjs/react-dom.development.js:29575:5)
    1037:  at legacyRenderSubtreeIntoContainer (../../../node_modules/react-dom/cjs/react-dom.development.js:29601:12)
    1038:  at Object.render (../../../node_modules/react-dom/cjs/react-dom.development.js:29685:10)
    1039:  at ../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:80:18
    1040:  at act (../../../node_modules/react/cjs/react.development.js:2512:16)
    1041:  at render (../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:79:26)
    1042:  at renderHook (../../../node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)
    1043:  at Object.<anonymous> (src/lib/useNinetailed.spec.tsx:28:34)
    1044:  console.error
    1045:  Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
    1046:  44 |     };
    1047:  45 |
    1048:  > 46 |     const { result } = renderHook(() => useNinetailed(), {
    1049:  |                                  ^
    1050:  47 |       wrapper: contextWrapper,
    1051:  48 |     });
    1052:  49 |
    1053:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    1054:  at printWarning (../../../node_modules/react-dom/cjs/react-dom.development.js:86:30)
    1055:  at error (../../../node_modules/react-dom/cjs/react-dom.development.js:60:7)
    1056:  at Object.render (../../../node_modules/react-dom/cjs/react-dom.development.js:29670:5)
    1057:  at ../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:80:18
    1058:  at act (../../../node_modules/react/cjs/react.development.js:2512:16)
    1059:  at render (../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:79:26)
    1060:  at renderHook (../../../node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)
    1061:  at Object.<anonymous> (src/lib/useNinetailed.spec.tsx:46:34)
    1062:  console.error
    1063:  Error: Uncaught [Error: The component using the the context must be a descendant of the NinetailedProvider]
    1064:  at reportException (/home/runner/work/experience.js/experience.js/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
    ...
    
    1093:  at _runTestsForDescribeBlock (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/run.js:126:9)
    1094:  at _runTestsForDescribeBlock (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/run.js:121:9)
    1095:  at run (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/run.js:71:3)
    1096:  at runAndTransformResultsToJestFormat (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    1097:  at jestAdapter (/home/runner/work/experience.js/experience.js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    1098:  at runTestInternal (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/runTest.js:367:16)
    1099:  at runTest (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/runTest.js:444:34)
    1100:  at Object.worker (/home/runner/work/experience.js/experience.js/node_modules/jest-runner/build/testWorker.js:106:12) {
    1101:  detail: Error: The component using the the context must be a descendant of the NinetailedProvider
    ...
    
    1147:  }
    1148:  44 |     };
    1149:  45 |
    1150:  > 46 |     const { result } = renderHook(() => useNinetailed(), {
    1151:  |                                  ^
    1152:  47 |       wrapper: contextWrapper,
    1153:  48 |     });
    1154:  49 |
    1155:  at console.error (../../../node_modules/@testing-library/react-hooks/lib/core/console.js:19:7)
    1156:  at reportException (../../../node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:70:28)
    ...
    
    1171:  at legacyCreateRootFromDOMContainer (../../../node_modules/react-dom/cjs/react-dom.development.js:29575:5)
    1172:  at legacyRenderSubtreeIntoContainer (../../../node_modules/react-dom/cjs/react-dom.development.js:29601:12)
    1173:  at Object.render (../../../node_modules/react-dom/cjs/react-dom.development.js:29685:10)
    1174:  at ../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:80:18
    1175:  at act (../../../node_modules/react/cjs/react.development.js:2512:16)
    1176:  at render (../../../node_modules/@testing-library/react-hooks/lib/dom/pure.js:79:26)
    1177:  at renderHook (../../../node_modules/@testing-library/react-hooks/lib/core/index.js:114:5)
    1178:  at Object.<anonymous> (src/lib/useNinetailed.spec.tsx:46:34)
    1179:  Test Suites: 1 failed, 4 passed, 5 total
    1180:  Tests:       1 failed, 18 passed, 19 total
    ...
    
    1337:  ✓ should intercept page events, if the after consent config won't allow them (6 ms)
    1338:  ✓ should not intercept track events if all event names are allowed through * (5 ms)
    1339:  ✓ Should set the features which are used correctly. E.g. not using the location of the user, even if the consent is given (8 ms)
    1340:  Test Suites: 1 passed, 1 total
    1341:  Tests:       8 passed, 8 total
    1342:  Snapshots:   0 total
    1343:  Time:        11.659 s
    1344:  Ran all test suites.
    1345:  >  NX   Running target test for 24 projects failed
    1346:  Failed tasks:
    1347:  - sdks-react:test
    1348:  error Command failed with exit code 1.
    1349:  info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    1350:  ##[error]Process completed with exit code 1.
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants