@trackunit/react-core-contexts-test 0.1.160 → 0.1.162

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ var jsxRuntime = require('react/jsx-runtime');
5
5
  var react = require('@testing-library/react');
6
6
  var pure = require('@testing-library/react/pure');
7
7
  require('@trackunit/react-core-hooks');
8
- require('lodash');
8
+ require('lodash/omit');
9
9
  require('react-router-dom');
10
10
  require('@apollo/client');
11
11
  require('@apollo/client/link/error');
@@ -3,7 +3,7 @@ import { jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { act } from '@testing-library/react';
4
4
  import { renderHook } from '@testing-library/react/pure';
5
5
  import '@trackunit/react-core-hooks';
6
- import 'lodash';
6
+ import 'lodash/omit';
7
7
  import 'react-router-dom';
8
8
  import '@apollo/client';
9
9
  import '@apollo/client/link/error';
package/index.cjs.js CHANGED
@@ -6,7 +6,7 @@ var index = require('./index.cjs2.js');
6
6
  require('react/jsx-runtime');
7
7
  require('@testing-library/react');
8
8
  require('@trackunit/react-core-hooks');
9
- require('lodash');
9
+ require('lodash/omit');
10
10
  require('react-router-dom');
11
11
  require('@apollo/client');
12
12
  require('@apollo/client/link/error');
package/index.cjs2.js CHANGED
@@ -3,7 +3,7 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var react = require('@testing-library/react');
5
5
  var reactCoreHooks = require('@trackunit/react-core-hooks');
6
- var lodash = require('lodash');
6
+ var omit = require('lodash/omit');
7
7
  var reactRouterDom = require('react-router-dom');
8
8
  var client = require('@apollo/client');
9
9
  var error = require('@apollo/client/link/error');
@@ -14,6 +14,7 @@ var graphql = require('graphql');
14
14
 
15
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
16
 
17
+ var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
17
18
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
19
 
19
20
  /******************************************************************************
@@ -65,22 +66,22 @@ const defaultOptions = {
65
66
  * This is a wrapper around the MockedProvider that logs errors to the console.
66
67
  */
67
68
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- function ApolloMockedProviderWithError(props, forceDebugging = false) {
69
+ function ApolloMockedProviderWithError(props) {
69
70
  const isDebugging = process ? !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG : false;
70
71
  const { mocks } = props, otherProps = __rest(props, ["mocks"]);
71
- const mockLink = new testing.MockLink(mocks, false, { showWarnings: forceDebugging || isDebugging });
72
+ const mockLink = new testing.MockLink(mocks, false, { showWarnings: props.forceDebugging || isDebugging });
72
73
  const errorLoggingLink = error.onError(({ graphQLErrors, networkError }) => {
73
74
  if (graphQLErrors) {
74
75
  // eslint-disable-next-line array-callback-return
75
76
  graphQLErrors.map(({ message, locations, path }) => {
76
- if (forceDebugging || isDebugging) {
77
+ if (props.forceDebugging || isDebugging) {
77
78
  // eslint-disable-next-line no-console
78
79
  console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
79
80
  }
80
81
  });
81
82
  }
82
83
  if (networkError) {
83
- if (forceDebugging || isDebugging) {
84
+ if (props.forceDebugging || isDebugging) {
84
85
  // eslint-disable-next-line no-console
85
86
  console.log(`[Network error]: ${networkError}`);
86
87
  }
@@ -474,7 +475,7 @@ class TrackunitProvidersMockBuilder {
474
475
  }
475
476
  return f;
476
477
  })) || [];
477
- this.selectedUserSubscriptionContext = Object.assign(Object.assign(Object.assign({}, mockUserSubscriptionContext), lodash.omit(userSubscription, "features")), { features: [...(mockUserSubscriptionContext.features || []), ...featuresConverted] });
478
+ this.selectedUserSubscriptionContext = Object.assign(Object.assign(Object.assign({}, mockUserSubscriptionContext), omit__default["default"](userSubscription, "features")), { features: [...(mockUserSubscriptionContext.features || []), ...featuresConverted] });
478
479
  return this;
479
480
  }
480
481
  /**
@@ -716,16 +717,28 @@ const trackunitProviders = () => new TrackunitProvidersMockBuilder();
716
717
  * @param propsToWatch all the props to watch for changes
717
718
  * @example
718
719
  * const propsToWatch = { foo: props.foo, bar: props.bar };
719
- * useDebugger({ id: "MyComponent", propsToWatch });
720
+ * useDebugger(propsToWatch);
720
721
  */
721
- const useDebugger = ({ id, propsToWatch, }) => {
722
+ const useDebugger = (propsToWatch, id) => {
722
723
  const prevPropsRef = React.useRef(propsToWatch);
723
724
  const uniqueId = React.useMemo(() => {
724
- var _a, _b;
725
- return id || ((_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2]) === null || _b === void 0 ? void 0 : _b.trim()) || "unknown-id";
725
+ var _a;
726
+ let stackId = id;
727
+ const stack = new Error().stack;
728
+ if (!stackId && stack) {
729
+ const stackLines = stack.split("\n");
730
+ for (let i = 0; i < stackLines.length; i++) {
731
+ const stackLine = stackLines[i];
732
+ if (stackLine === null || stackLine === void 0 ? void 0 : stackLine.includes("useDebugger")) {
733
+ stackId = (_a = stackLines[i + 1]) === null || _a === void 0 ? void 0 : _a.trim().split(" ")[1];
734
+ break;
735
+ }
736
+ }
737
+ }
738
+ return stackId || "unknown-id";
726
739
  }, [id]);
727
740
  // eslint-disable-next-line no-console
728
- console.log("Rerender ", id);
741
+ console.log("Rerender", uniqueId);
729
742
  React.useEffect(() => {
730
743
  const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
731
744
  if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
@@ -743,10 +756,12 @@ const useDebugger = ({ id, propsToWatch, }) => {
743
756
  const result0 = result[0];
744
757
  const result1 = result[1];
745
758
  result0 &&
759
+ typeof result0 === "object" &&
746
760
  Object.keys(result0).forEach(prop => {
747
761
  result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
748
762
  });
749
763
  result1 &&
764
+ typeof result1 === "object" &&
750
765
  Object.keys(result1).forEach(prop => {
751
766
  result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
752
767
  });
@@ -778,7 +793,7 @@ const Debugger = ({ id, logPropsChanges, stop, children, }) => {
778
793
  (_e = (_d = (_c = (_b = (_a = React__default["default"]["__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED"]) === null || _a === void 0 ? void 0 : _a.ReactCurrentOwner) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c._debugOwner) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e.name) ||
779
794
  ((_g = (_f = new Error().stack) === null || _f === void 0 ? void 0 : _f.split("\n")[2]) === null || _g === void 0 ? void 0 : _g.trim()) ||
780
795
  "unknown-id";
781
- useDebugger({ id: uniqueId, propsToWatch: logPropsChanges || {} });
796
+ useDebugger(logPropsChanges || {}, id);
782
797
  // eslint-disable-next-line no-console
783
798
  console.log(`${uniqueId} Debugger is rendering`);
784
799
  React.useEffect(() => {
package/index.esm.js CHANGED
@@ -2,7 +2,7 @@ export { D as Debugger, T as TrackunitProvidersMockBuilder, h as doNothing, f as
2
2
  import 'react/jsx-runtime';
3
3
  import '@testing-library/react';
4
4
  import '@trackunit/react-core-hooks';
5
- import 'lodash';
5
+ import 'lodash/omit';
6
6
  import 'react-router-dom';
7
7
  import '@apollo/client';
8
8
  import '@apollo/client/link/error';
package/index.esm2.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { act, render } from '@testing-library/react';
3
3
  import { EnvironmentContextProvider, CurrentUserProvider, AnalyticsContext, UserSubscriptionProvider, OemBrandingContextProvider, TokenProvider, ToastProvider, FilterBarProvider, AssetSortingProvider, NavigationContextProvider, CurrentUserPreferenceProvider } from '@trackunit/react-core-hooks';
4
- import { omit } from 'lodash';
4
+ import omit from 'lodash/omit';
5
5
  import { MemoryRouter } from 'react-router-dom';
6
6
  import { ApolloLink } from '@apollo/client';
7
7
  import { onError } from '@apollo/client/link/error';
@@ -59,22 +59,22 @@ const defaultOptions = {
59
59
  * This is a wrapper around the MockedProvider that logs errors to the console.
60
60
  */
61
61
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
- function ApolloMockedProviderWithError(props, forceDebugging = false) {
62
+ function ApolloMockedProviderWithError(props) {
63
63
  const isDebugging = process ? !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG : false;
64
64
  const { mocks } = props, otherProps = __rest(props, ["mocks"]);
65
- const mockLink = new MockLink(mocks, false, { showWarnings: forceDebugging || isDebugging });
65
+ const mockLink = new MockLink(mocks, false, { showWarnings: props.forceDebugging || isDebugging });
66
66
  const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
67
67
  if (graphQLErrors) {
68
68
  // eslint-disable-next-line array-callback-return
69
69
  graphQLErrors.map(({ message, locations, path }) => {
70
- if (forceDebugging || isDebugging) {
70
+ if (props.forceDebugging || isDebugging) {
71
71
  // eslint-disable-next-line no-console
72
72
  console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
73
73
  }
74
74
  });
75
75
  }
76
76
  if (networkError) {
77
- if (forceDebugging || isDebugging) {
77
+ if (props.forceDebugging || isDebugging) {
78
78
  // eslint-disable-next-line no-console
79
79
  console.log(`[Network error]: ${networkError}`);
80
80
  }
@@ -710,16 +710,28 @@ const trackunitProviders = () => new TrackunitProvidersMockBuilder();
710
710
  * @param propsToWatch all the props to watch for changes
711
711
  * @example
712
712
  * const propsToWatch = { foo: props.foo, bar: props.bar };
713
- * useDebugger({ id: "MyComponent", propsToWatch });
713
+ * useDebugger(propsToWatch);
714
714
  */
715
- const useDebugger = ({ id, propsToWatch, }) => {
715
+ const useDebugger = (propsToWatch, id) => {
716
716
  const prevPropsRef = useRef(propsToWatch);
717
717
  const uniqueId = useMemo(() => {
718
- var _a, _b;
719
- return id || ((_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2]) === null || _b === void 0 ? void 0 : _b.trim()) || "unknown-id";
718
+ var _a;
719
+ let stackId = id;
720
+ const stack = new Error().stack;
721
+ if (!stackId && stack) {
722
+ const stackLines = stack.split("\n");
723
+ for (let i = 0; i < stackLines.length; i++) {
724
+ const stackLine = stackLines[i];
725
+ if (stackLine === null || stackLine === void 0 ? void 0 : stackLine.includes("useDebugger")) {
726
+ stackId = (_a = stackLines[i + 1]) === null || _a === void 0 ? void 0 : _a.trim().split(" ")[1];
727
+ break;
728
+ }
729
+ }
730
+ }
731
+ return stackId || "unknown-id";
720
732
  }, [id]);
721
733
  // eslint-disable-next-line no-console
722
- console.log("Rerender ", id);
734
+ console.log("Rerender", uniqueId);
723
735
  useEffect(() => {
724
736
  const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
725
737
  if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
@@ -737,10 +749,12 @@ const useDebugger = ({ id, propsToWatch, }) => {
737
749
  const result0 = result[0];
738
750
  const result1 = result[1];
739
751
  result0 &&
752
+ typeof result0 === "object" &&
740
753
  Object.keys(result0).forEach(prop => {
741
754
  result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
742
755
  });
743
756
  result1 &&
757
+ typeof result1 === "object" &&
744
758
  Object.keys(result1).forEach(prop => {
745
759
  result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
746
760
  });
@@ -772,7 +786,7 @@ const Debugger = ({ id, logPropsChanges, stop, children, }) => {
772
786
  (_e = (_d = (_c = (_b = (_a = React["__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED"]) === null || _a === void 0 ? void 0 : _a.ReactCurrentOwner) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c._debugOwner) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e.name) ||
773
787
  ((_g = (_f = new Error().stack) === null || _f === void 0 ? void 0 : _f.split("\n")[2]) === null || _g === void 0 ? void 0 : _g.trim()) ||
774
788
  "unknown-id";
775
- useDebugger({ id: uniqueId, propsToWatch: logPropsChanges || {} });
789
+ useDebugger(logPropsChanges || {}, id);
776
790
  // eslint-disable-next-line no-console
777
791
  console.log(`${uniqueId} Debugger is rendering`);
778
792
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "0.1.160",
3
+ "version": "0.1.162",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -2,4 +2,4 @@
2
2
  /**
3
3
  * This is a wrapper around the MockedProvider that logs errors to the console.
4
4
  */
5
- export declare function ApolloMockedProviderWithError(props: any, forceDebugging?: boolean): JSX.Element;
5
+ export declare function ApolloMockedProviderWithError(props: any): JSX.Element;
package/src/debugger.d.ts CHANGED
@@ -10,12 +10,9 @@ type PropsToWatch<P> = P extends object ? P : never;
10
10
  * @param propsToWatch all the props to watch for changes
11
11
  * @example
12
12
  * const propsToWatch = { foo: props.foo, bar: props.bar };
13
- * useDebugger({ id: "MyComponent", propsToWatch });
13
+ * useDebugger(propsToWatch);
14
14
  */
15
- export declare const useDebugger: <P extends object>({ id, propsToWatch, }: {
16
- id?: string | undefined;
17
- propsToWatch: PropsToWatch<P> | null;
18
- }) => void;
15
+ export declare const useDebugger: <P extends object>(propsToWatch: PropsToWatch<P> | null, id?: string) => void;
19
16
  /**
20
17
  * Debugger component for debugging state changes and re-renders.
21
18
  *