@trackunit/react-core-contexts-test 0.1.61 → 0.1.63

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.
package/HookRenderer.cjs CHANGED
@@ -4,6 +4,7 @@ var index = require('./index2.cjs');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var react = require('@testing-library/react');
6
6
  var pure = require('@testing-library/react/pure');
7
+ require('react');
7
8
  require('@trackunit/react-core-contexts-api');
8
9
  require('@trackunit/react-core-hooks');
9
10
  require('@trackunit/tailwind-styled-components');
@@ -11,7 +12,6 @@ require('react-router-dom');
11
12
  require('@apollo/client');
12
13
  require('@apollo/client/link/error');
13
14
  require('@apollo/client/testing');
14
- require('react');
15
15
  require('graphql');
16
16
 
17
17
  /**
package/HookRenderer.js CHANGED
@@ -2,6 +2,7 @@ import { _ as __awaiter, f as flushPromises } from './index2.js';
2
2
  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
+ import 'react';
5
6
  import '@trackunit/react-core-contexts-api';
6
7
  import '@trackunit/react-core-hooks';
7
8
  import '@trackunit/tailwind-styled-components';
@@ -9,7 +10,6 @@ import 'react-router-dom';
9
10
  import '@apollo/client';
10
11
  import '@apollo/client/link/error';
11
12
  import '@apollo/client/testing';
12
- import 'react';
13
13
  import 'graphql';
14
14
 
15
15
  /**
package/index.cjs CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var index = require('./index2.cjs');
6
6
  require('react/jsx-runtime');
7
+ require('react');
7
8
  require('@testing-library/react');
8
9
  require('@trackunit/react-core-contexts-api');
9
10
  require('@trackunit/react-core-hooks');
@@ -12,11 +13,11 @@ require('react-router-dom');
12
13
  require('@apollo/client');
13
14
  require('@apollo/client/link/error');
14
15
  require('@apollo/client/testing');
15
- require('react');
16
16
  require('graphql');
17
17
 
18
18
 
19
19
 
20
+ exports.Debugger = index.Debugger;
20
21
  exports.MockContextProviderBuilder = index.MockContextProviderBuilder;
21
22
  exports.doNothing = index.doNothing;
22
23
  exports.flushPromises = index.flushPromises;
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export { M as MockContextProviderBuilder, d as doNothing, f as flushPromises, c as flushPromisesInAct, m as mockAnalyticsContext, a as mockCurrentUserContext, b as mockEnvironmentContext, q as queryFor, r as rootContext, u as useLogPropsChanged, v as validateIrisApp } from './index2.js';
1
+ export { D as Debugger, M as MockContextProviderBuilder, d as doNothing, f as flushPromises, c as flushPromisesInAct, m as mockAnalyticsContext, a as mockCurrentUserContext, b as mockEnvironmentContext, q as queryFor, r as rootContext, u as useLogPropsChanged, v as validateIrisApp } from './index2.js';
2
2
  import 'react/jsx-runtime';
3
+ import 'react';
3
4
  import '@testing-library/react';
4
5
  import '@trackunit/react-core-contexts-api';
5
6
  import '@trackunit/react-core-hooks';
@@ -8,5 +9,4 @@ import 'react-router-dom';
8
9
  import '@apollo/client';
9
10
  import '@apollo/client/link/error';
10
11
  import '@apollo/client/testing';
11
- import 'react';
12
12
  import 'graphql';
package/index2.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
- var react = require('@testing-library/react');
4
+ var react = require('react');
5
+ var react$1 = require('@testing-library/react');
5
6
  var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
6
7
  var reactCoreHooks = require('@trackunit/react-core-hooks');
7
8
  var tailwindStyledComponents = require('@trackunit/tailwind-styled-components');
@@ -9,9 +10,76 @@ var reactRouterDom = require('react-router-dom');
9
10
  var client = require('@apollo/client');
10
11
  var error = require('@apollo/client/link/error');
11
12
  var testing = require('@apollo/client/testing');
12
- var react$1 = require('react');
13
13
  var graphql = require('graphql');
14
14
 
15
+ /**
16
+ * Logs props that have changed.
17
+ * Use this for debugging which props force a component to re-render.
18
+ * This is a hook version of the class component lifecycle method `componentDidUpdate`.
19
+ * ALWAYS wrap in your own object.
20
+ *
21
+ * @param propsToWatch all the props to watch for changes
22
+ */
23
+ const useLogPropsChanged = (propsToWatch) => {
24
+ var _a;
25
+ const prevPropsRef = react.useRef(propsToWatch);
26
+ const parentCaller = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim();
27
+ react.useEffect(() => {
28
+ const changedProps = Object.entries(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {}).reduce((result, [key, value]) => {
29
+ if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
30
+ result[key + ""] = [prevPropsRef.current[key], value];
31
+ }
32
+ return result;
33
+ }, {});
34
+ if (Object.keys(changedProps).length > 0) {
35
+ // eslint-disable-next-line no-console
36
+ Object.keys(changedProps).forEach(changedProp => {
37
+ // eslint-disable-next-line no-console
38
+ console.log("Props changed:", changedProp, parentCaller);
39
+ // JSON stringify is used to avoid console.table from logging the object reference
40
+ const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
41
+ const result0 = result[0];
42
+ const result1 = result[1];
43
+ result0 &&
44
+ Object.keys(result0).forEach(prop => {
45
+ result0[prop] = JSON.stringify(result0[prop]);
46
+ });
47
+ result1 &&
48
+ Object.keys(result1).forEach(prop => {
49
+ result1[prop] = JSON.stringify(result1[prop]);
50
+ });
51
+ // eslint-disable-next-line no-console
52
+ console.table([result0, result1]);
53
+ });
54
+ // eslint-disable-next-line no-console
55
+ console.dir(changedProps);
56
+ }
57
+ prevPropsRef.current = propsToWatch;
58
+ }, [parentCaller, propsToWatch]);
59
+ };
60
+ /**
61
+ * Debugger component for debugging state changes and re-renders.
62
+ * This component will log when it is mounted and unmounted.
63
+ * It will also log when any of its props change.
64
+ *
65
+ * @param logPropsChanges the props to watch for changes
66
+ * @param children the children to render
67
+ */
68
+ const Debugger = ({ logPropsChanges, children }) => {
69
+ useLogPropsChanged(logPropsChanges);
70
+ // eslint-disable-next-line no-console
71
+ console.log("Debugger is rendering");
72
+ react.useEffect(() => {
73
+ // eslint-disable-next-line no-console
74
+ console.log("Debugger is mounting");
75
+ return () => {
76
+ // eslint-disable-next-line no-console
77
+ console.log("Debugger is unmounting");
78
+ };
79
+ }, []);
80
+ return jsxRuntime.jsx("div", Object.assign({ className: "Debugger" }, { children: children }));
81
+ };
82
+
15
83
  /******************************************************************************
16
84
  Copyright (c) Microsoft Corporation.
17
85
 
@@ -198,7 +266,7 @@ const flushPromises = (waitTimeInMS = 0) => {
198
266
  * @returns {Promise<void>} - Returns a promise that resolves after the wait time.
199
267
  */
200
268
  const flushPromisesInAct = (waitTimeInMS = 0) => {
201
- return react.act(() => {
269
+ return react$1.act(() => {
202
270
  return new Promise(resolve => {
203
271
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
204
272
  if (global.ORG_setTimeout) {
@@ -377,16 +445,16 @@ class MockContextProviderBuilder {
377
445
  return __awaiter(this, void 0, void 0, function* () {
378
446
  this.validateSuppliedMocks();
379
447
  let mountedcomponent;
380
- yield react.act(() => __awaiter(this, void 0, void 0, function* () {
381
- mountedcomponent = react.render(child, {
448
+ yield react$1.act(() => __awaiter(this, void 0, void 0, function* () {
449
+ mountedcomponent = react$1.render(child, {
382
450
  wrapper: ({ children }) => this.getMockedCompositionRoot(children),
383
451
  });
384
452
  yield flushPromises();
385
453
  }));
386
- yield react.act(() => __awaiter(this, void 0, void 0, function* () {
454
+ yield react$1.act(() => __awaiter(this, void 0, void 0, function* () {
387
455
  yield flushPromises();
388
456
  }));
389
- yield react.act(() => __awaiter(this, void 0, void 0, function* () {
457
+ yield react$1.act(() => __awaiter(this, void 0, void 0, function* () {
390
458
  yield flushPromises();
391
459
  }));
392
460
  return mountedcomponent;
@@ -423,52 +491,6 @@ const TestRoot = tailwindStyledComponents.tw.div `
423
491
  inline-block;
424
492
  `;
425
493
 
426
- /**
427
- * Logs props that have changed.
428
- * Use this for debugging which props force a component to re-render.
429
- * This is a hook version of the class component lifecycle method `componentDidUpdate`.
430
- * ALWAYS wrap in your own object.
431
- *
432
- * @param propsToWatch all the props to watch for changes
433
- */
434
- const useLogPropsChanged = (propsToWatch) => {
435
- var _a;
436
- const prevPropsRef = react$1.useRef(propsToWatch);
437
- const parentCaller = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim();
438
- react$1.useEffect(() => {
439
- const changedProps = Object.entries(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {}).reduce((result, [key, value]) => {
440
- if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
441
- result[key] = [prevPropsRef.current[key], value];
442
- }
443
- return result;
444
- }, [Object.keys(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {})]);
445
- if (Object.keys(changedProps).length > 0) {
446
- // eslint-disable-next-line no-console
447
- Object.keys(changedProps).forEach(changedProp => {
448
- // eslint-disable-next-line no-console
449
- console.log("Props changed:", changedProp, parentCaller);
450
- // JSON stringify is used to avoid console.table from logging the object reference
451
- const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
452
- const result0 = result[0];
453
- const result1 = result[1];
454
- result0 &&
455
- Object.keys(result0).forEach(prop => {
456
- result0[prop] = JSON.stringify(result0[prop]);
457
- });
458
- result1 &&
459
- Object.keys(result1).forEach(prop => {
460
- result1[prop] = JSON.stringify(result1[prop]);
461
- });
462
- // eslint-disable-next-line no-console
463
- console.table([result0, result1]);
464
- });
465
- // eslint-disable-next-line no-console
466
- console.dir(changedProps);
467
- }
468
- prevPropsRef.current = propsToWatch;
469
- });
470
- };
471
-
472
494
  /**
473
495
  *
474
496
  * @param document Document that represents the specific GQL query / mutation schema.
@@ -548,6 +570,7 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
548
570
  return null;
549
571
  });
550
572
 
573
+ exports.Debugger = Debugger;
551
574
  exports.MockContextProviderBuilder = MockContextProviderBuilder;
552
575
  exports.__awaiter = __awaiter;
553
576
  exports.doNothing = doNothing;
package/index2.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
+ import { useRef, useEffect } from 'react';
2
3
  import { act, render } from '@testing-library/react';
3
4
  import { AssetSortByProperty, SortOrder, UserSubscriptionPackage } from '@trackunit/react-core-contexts-api';
4
5
  import { EnvironmentContextProvider, CurrentUserProvider, AnalyticsContext, UserSubscriptionProvider, OemBrandingContextProvider, TokenProvider, ToastProvider, GlobalSelectionProvider, AssetSortingProvider } from '@trackunit/react-core-hooks';
@@ -7,9 +8,76 @@ import { MemoryRouter } from 'react-router-dom';
7
8
  import { ApolloLink } from '@apollo/client';
8
9
  import { onError } from '@apollo/client/link/error';
9
10
  import { MockLink, MockedProvider } from '@apollo/client/testing';
10
- import { useRef, useEffect } from 'react';
11
11
  import { GraphQLError } from 'graphql';
12
12
 
13
+ /**
14
+ * Logs props that have changed.
15
+ * Use this for debugging which props force a component to re-render.
16
+ * This is a hook version of the class component lifecycle method `componentDidUpdate`.
17
+ * ALWAYS wrap in your own object.
18
+ *
19
+ * @param propsToWatch all the props to watch for changes
20
+ */
21
+ const useLogPropsChanged = (propsToWatch) => {
22
+ var _a;
23
+ const prevPropsRef = useRef(propsToWatch);
24
+ const parentCaller = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim();
25
+ useEffect(() => {
26
+ const changedProps = Object.entries(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {}).reduce((result, [key, value]) => {
27
+ if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
28
+ result[key + ""] = [prevPropsRef.current[key], value];
29
+ }
30
+ return result;
31
+ }, {});
32
+ if (Object.keys(changedProps).length > 0) {
33
+ // eslint-disable-next-line no-console
34
+ Object.keys(changedProps).forEach(changedProp => {
35
+ // eslint-disable-next-line no-console
36
+ console.log("Props changed:", changedProp, parentCaller);
37
+ // JSON stringify is used to avoid console.table from logging the object reference
38
+ const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
39
+ const result0 = result[0];
40
+ const result1 = result[1];
41
+ result0 &&
42
+ Object.keys(result0).forEach(prop => {
43
+ result0[prop] = JSON.stringify(result0[prop]);
44
+ });
45
+ result1 &&
46
+ Object.keys(result1).forEach(prop => {
47
+ result1[prop] = JSON.stringify(result1[prop]);
48
+ });
49
+ // eslint-disable-next-line no-console
50
+ console.table([result0, result1]);
51
+ });
52
+ // eslint-disable-next-line no-console
53
+ console.dir(changedProps);
54
+ }
55
+ prevPropsRef.current = propsToWatch;
56
+ }, [parentCaller, propsToWatch]);
57
+ };
58
+ /**
59
+ * Debugger component for debugging state changes and re-renders.
60
+ * This component will log when it is mounted and unmounted.
61
+ * It will also log when any of its props change.
62
+ *
63
+ * @param logPropsChanges the props to watch for changes
64
+ * @param children the children to render
65
+ */
66
+ const Debugger = ({ logPropsChanges, children }) => {
67
+ useLogPropsChanged(logPropsChanges);
68
+ // eslint-disable-next-line no-console
69
+ console.log("Debugger is rendering");
70
+ useEffect(() => {
71
+ // eslint-disable-next-line no-console
72
+ console.log("Debugger is mounting");
73
+ return () => {
74
+ // eslint-disable-next-line no-console
75
+ console.log("Debugger is unmounting");
76
+ };
77
+ }, []);
78
+ return jsx("div", Object.assign({ className: "Debugger" }, { children: children }));
79
+ };
80
+
13
81
  /******************************************************************************
14
82
  Copyright (c) Microsoft Corporation.
15
83
 
@@ -421,52 +489,6 @@ const TestRoot = tw.div `
421
489
  inline-block;
422
490
  `;
423
491
 
424
- /**
425
- * Logs props that have changed.
426
- * Use this for debugging which props force a component to re-render.
427
- * This is a hook version of the class component lifecycle method `componentDidUpdate`.
428
- * ALWAYS wrap in your own object.
429
- *
430
- * @param propsToWatch all the props to watch for changes
431
- */
432
- const useLogPropsChanged = (propsToWatch) => {
433
- var _a;
434
- const prevPropsRef = useRef(propsToWatch);
435
- const parentCaller = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim();
436
- useEffect(() => {
437
- const changedProps = Object.entries(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {}).reduce((result, [key, value]) => {
438
- if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
439
- result[key] = [prevPropsRef.current[key], value];
440
- }
441
- return result;
442
- }, [Object.keys(propsToWatch !== null && propsToWatch !== void 0 ? propsToWatch : {})]);
443
- if (Object.keys(changedProps).length > 0) {
444
- // eslint-disable-next-line no-console
445
- Object.keys(changedProps).forEach(changedProp => {
446
- // eslint-disable-next-line no-console
447
- console.log("Props changed:", changedProp, parentCaller);
448
- // JSON stringify is used to avoid console.table from logging the object reference
449
- const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
450
- const result0 = result[0];
451
- const result1 = result[1];
452
- result0 &&
453
- Object.keys(result0).forEach(prop => {
454
- result0[prop] = JSON.stringify(result0[prop]);
455
- });
456
- result1 &&
457
- Object.keys(result1).forEach(prop => {
458
- result1[prop] = JSON.stringify(result1[prop]);
459
- });
460
- // eslint-disable-next-line no-console
461
- console.table([result0, result1]);
462
- });
463
- // eslint-disable-next-line no-console
464
- console.dir(changedProps);
465
- }
466
- prevPropsRef.current = propsToWatch;
467
- });
468
- };
469
-
470
492
  /**
471
493
  *
472
494
  * @param document Document that represents the specific GQL query / mutation schema.
@@ -546,4 +568,4 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
546
568
  return null;
547
569
  });
548
570
 
549
- export { MockContextProviderBuilder as M, __awaiter as _, mockCurrentUserContext as a, mockEnvironmentContext as b, flushPromisesInAct as c, doNothing as d, flushPromises as f, mockAnalyticsContext as m, queryFor as q, rootContext as r, useLogPropsChanged as u, validateIrisApp as v };
571
+ export { Debugger as D, MockContextProviderBuilder as M, __awaiter as _, mockCurrentUserContext as a, mockEnvironmentContext as b, flushPromisesInAct as c, doNothing as d, flushPromises as f, mockAnalyticsContext as m, queryFor as q, rootContext as r, useLogPropsChanged as u, validateIrisApp as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "0.1.61",
3
+ "version": "0.1.63",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "module": "./index.js",
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ type PropsToWatch<P> = P extends object ? P : never;
3
+ /**
4
+ * Logs props that have changed.
5
+ * Use this for debugging which props force a component to re-render.
6
+ * This is a hook version of the class component lifecycle method `componentDidUpdate`.
7
+ * ALWAYS wrap in your own object.
8
+ *
9
+ * @param propsToWatch all the props to watch for changes
10
+ */
11
+ export declare const useLogPropsChanged: <P extends object>(propsToWatch: PropsToWatch<P> | null) => void;
12
+ /**
13
+ * Debugger component for debugging state changes and re-renders.
14
+ * This component will log when it is mounted and unmounted.
15
+ * It will also log when any of its props change.
16
+ *
17
+ * @param logPropsChanges the props to watch for changes
18
+ * @param children the children to render
19
+ */
20
+ export declare const Debugger: ({ logPropsChanges, children }: {
21
+ children: React.ReactNode;
22
+ logPropsChanges: {};
23
+ }) => JSX.Element;
24
+ export {};
package/src/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
+ export * from "./debugger";
1
2
  export * from "./MockContextProviderBuilder";
2
3
  export * from "./mocks/mockAnalyticsContext";
3
4
  export * from "./mocks/mockCurrentUserContext";
4
5
  export * from "./mocks/mockEnvironmentContext";
5
- export * from "./useLogPropsChanged";
6
6
  export * from "./utils/doNothing";
7
7
  export * from "./utils/queryFor";
8
8
  export * from "./utils/validateIrisApp";
@@ -1,11 +0,0 @@
1
- type PropsToWatch<P> = P extends object ? P : never;
2
- /**
3
- * Logs props that have changed.
4
- * Use this for debugging which props force a component to re-render.
5
- * This is a hook version of the class component lifecycle method `componentDidUpdate`.
6
- * ALWAYS wrap in your own object.
7
- *
8
- * @param propsToWatch all the props to watch for changes
9
- */
10
- export declare const useLogPropsChanged: <P extends object>(propsToWatch: PropsToWatch<P> | null) => void;
11
- export {};