@trackunit/react-core-contexts-test 0.1.67 → 0.1.69
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/index.cjs +2 -2
- package/index.js +1 -1
- package/index2.cjs +50 -27
- package/index2.js +36 -17
- package/package.json +1 -1
- package/src/MockContextProviderBuilder.d.ts +1 -1
- package/src/debugger.d.ts +19 -7
package/index.cjs
CHANGED
|
@@ -26,6 +26,6 @@ exports.mockAnalyticsContext = index.mockAnalyticsContext;
|
|
|
26
26
|
exports.mockCurrentUserContext = index.mockCurrentUserContext;
|
|
27
27
|
exports.mockEnvironmentContext = index.mockEnvironmentContext;
|
|
28
28
|
exports.queryFor = index.queryFor;
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
29
|
+
exports.trackunitProviders = index.trackunitProviders;
|
|
30
|
+
exports.useDebugger = index.useDebugger;
|
|
31
31
|
exports.validateIrisApp = index.validateIrisApp;
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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,
|
|
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, t as trackunitProviders, u as useDebugger, v as validateIrisApp } from './index2.js';
|
|
2
2
|
import 'react/jsx-runtime';
|
|
3
3
|
import 'react';
|
|
4
4
|
import '@testing-library/react';
|
package/index2.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
5
|
-
var react
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var react = require('@testing-library/react');
|
|
6
6
|
var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
7
7
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
8
8
|
var tailwindStyledComponents = require('@trackunit/tailwind-styled-components');
|
|
@@ -12,20 +12,30 @@ var error = require('@apollo/client/link/error');
|
|
|
12
12
|
var testing = require('@apollo/client/testing');
|
|
13
13
|
var graphql = require('graphql');
|
|
14
14
|
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* Logs props that have changed.
|
|
17
21
|
* Use this for debugging which props force a component to re-render.
|
|
18
22
|
* This is a hook version of the class component lifecycle method `componentDidUpdate`.
|
|
19
23
|
* ALWAYS wrap in your own object.
|
|
20
24
|
*
|
|
25
|
+
* @param id optional id to use for logging or it will guess the id from the stack trace
|
|
21
26
|
* @param propsToWatch all the props to watch for changes
|
|
27
|
+
* @example
|
|
28
|
+
* const propsToWatch = { foo: props.foo, bar: props.bar };
|
|
29
|
+
* useDebugger({ id: "MyComponent", propsToWatch });
|
|
22
30
|
*/
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
const useDebugger = ({ id, propsToWatch, }) => {
|
|
32
|
+
const prevPropsRef = React.useRef(propsToWatch);
|
|
33
|
+
const uniqueId = React.useMemo(() => {
|
|
34
|
+
var _a;
|
|
35
|
+
return id || ((_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim()) || "unknown-id";
|
|
36
|
+
}, [id]);
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
|
|
29
39
|
if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
|
|
30
40
|
result[key + ""] = [prevPropsRef.current[key], value];
|
|
31
41
|
}
|
|
@@ -35,7 +45,7 @@ const useLogPropsChanged = (propsToWatch) => {
|
|
|
35
45
|
// eslint-disable-next-line no-console
|
|
36
46
|
Object.keys(changedProps).forEach(changedProp => {
|
|
37
47
|
// eslint-disable-next-line no-console
|
|
38
|
-
console.log(
|
|
48
|
+
console.log(`${uniqueId} changed property: ${changedProp}`);
|
|
39
49
|
// JSON stringify is used to avoid console.table from logging the object reference
|
|
40
50
|
const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
|
|
41
51
|
const result0 = result[0];
|
|
@@ -55,28 +65,41 @@ const useLogPropsChanged = (propsToWatch) => {
|
|
|
55
65
|
console.dir(changedProps);
|
|
56
66
|
}
|
|
57
67
|
prevPropsRef.current = propsToWatch;
|
|
58
|
-
}, [
|
|
68
|
+
}, [propsToWatch, uniqueId]);
|
|
59
69
|
};
|
|
60
70
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
71
|
+
* Debugger component for debugging state changes and re-renders.
|
|
72
|
+
*
|
|
73
|
+
* This component will log when it is mounted, re-renders or unmounted.
|
|
63
74
|
* It will also log when any of its props change.
|
|
64
75
|
*
|
|
65
|
-
* @param
|
|
76
|
+
* @param id optional id to use for logging
|
|
77
|
+
* @param stop if true, will stop execution and open debugger
|
|
78
|
+
* @param logPropsChanges optional object with props to watch for changes
|
|
66
79
|
* @param children the children to render
|
|
67
80
|
*/
|
|
68
|
-
const Debugger = ({ logPropsChanges, children }) => {
|
|
69
|
-
|
|
81
|
+
const Debugger = ({ id, logPropsChanges, stop, children, }) => {
|
|
82
|
+
var _a, _b, _c, _d, _e, _f;
|
|
83
|
+
const uniqueId = id ||
|
|
84
|
+
((_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) ||
|
|
85
|
+
((_f = new Error().stack) === null || _f === void 0 ? void 0 : _f.split("\n")[2].trim()) ||
|
|
86
|
+
"unknown-id";
|
|
87
|
+
useDebugger({ id: uniqueId, propsToWatch: logPropsChanges || {} });
|
|
70
88
|
// eslint-disable-next-line no-console
|
|
71
|
-
console.log(
|
|
72
|
-
|
|
89
|
+
console.log(`${uniqueId} Debugger is rendering`);
|
|
90
|
+
React.useEffect(() => {
|
|
73
91
|
// eslint-disable-next-line no-console
|
|
74
|
-
console.log(
|
|
92
|
+
console.log(`${uniqueId} Debugger is mounting`);
|
|
75
93
|
return () => {
|
|
76
94
|
// eslint-disable-next-line no-console
|
|
77
|
-
console.log(
|
|
95
|
+
console.log(`${uniqueId} Debugger is unmounting`);
|
|
78
96
|
};
|
|
97
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
79
98
|
}, []);
|
|
99
|
+
if (stop === true) {
|
|
100
|
+
// eslint-disable-next-line no-debugger
|
|
101
|
+
debugger;
|
|
102
|
+
}
|
|
80
103
|
return jsxRuntime.jsx("div", Object.assign({ className: "Debugger" }, { children: children }));
|
|
81
104
|
};
|
|
82
105
|
|
|
@@ -267,7 +290,7 @@ const flushPromises = (waitTimeInMS = 0) => {
|
|
|
267
290
|
* @returns {Promise<void>} - Returns a promise that resolves after the wait time.
|
|
268
291
|
*/
|
|
269
292
|
const flushPromisesInAct = (waitTimeInMS = 0) => {
|
|
270
|
-
return react
|
|
293
|
+
return react.act(() => {
|
|
271
294
|
return new Promise(resolve => {
|
|
272
295
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
273
296
|
if (global.ORG_setTimeout) {
|
|
@@ -446,16 +469,16 @@ class MockContextProviderBuilder {
|
|
|
446
469
|
return __awaiter(this, void 0, void 0, function* () {
|
|
447
470
|
this.validateSuppliedMocks();
|
|
448
471
|
let mountedcomponent;
|
|
449
|
-
yield react
|
|
450
|
-
mountedcomponent = react
|
|
472
|
+
yield react.act(() => __awaiter(this, void 0, void 0, function* () {
|
|
473
|
+
mountedcomponent = react.render(child, {
|
|
451
474
|
wrapper: ({ children }) => this.getMockedCompositionRoot(children),
|
|
452
475
|
});
|
|
453
476
|
yield flushPromises();
|
|
454
477
|
}));
|
|
455
|
-
yield react
|
|
478
|
+
yield react.act(() => __awaiter(this, void 0, void 0, function* () {
|
|
456
479
|
yield flushPromises();
|
|
457
480
|
}));
|
|
458
|
-
yield react
|
|
481
|
+
yield react.act(() => __awaiter(this, void 0, void 0, function* () {
|
|
459
482
|
yield flushPromises();
|
|
460
483
|
}));
|
|
461
484
|
return mountedcomponent;
|
|
@@ -483,7 +506,7 @@ class MockContextProviderBuilder {
|
|
|
483
506
|
/**
|
|
484
507
|
*
|
|
485
508
|
*/
|
|
486
|
-
const
|
|
509
|
+
const trackunitProviders = () => new MockContextProviderBuilder();
|
|
487
510
|
const TestRoot = tailwindStyledComponents.tw.div `
|
|
488
511
|
--tw-scale-x: 0.99;
|
|
489
512
|
--tw-scale-y: 0.99;
|
|
@@ -581,6 +604,6 @@ exports.mockAnalyticsContext = mockAnalyticsContext;
|
|
|
581
604
|
exports.mockCurrentUserContext = mockCurrentUserContext;
|
|
582
605
|
exports.mockEnvironmentContext = mockEnvironmentContext;
|
|
583
606
|
exports.queryFor = queryFor;
|
|
584
|
-
exports.
|
|
585
|
-
exports.
|
|
607
|
+
exports.trackunitProviders = trackunitProviders;
|
|
608
|
+
exports.useDebugger = useDebugger;
|
|
586
609
|
exports.validateIrisApp = validateIrisApp;
|
package/index2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useRef, useEffect } from 'react';
|
|
2
|
+
import React, { useRef, useMemo, useEffect } from 'react';
|
|
3
3
|
import { act, render } from '@testing-library/react';
|
|
4
4
|
import { AssetSortByProperty, SortOrder, UserSubscriptionPackage } from '@trackunit/react-core-contexts-api';
|
|
5
5
|
import { EnvironmentContextProvider, CurrentUserProvider, AnalyticsContext, UserSubscriptionProvider, OemBrandingContextProvider, TokenProvider, ToastProvider, GlobalSelectionProvider, AssetSortingProvider } from '@trackunit/react-core-hooks';
|
|
@@ -16,14 +16,20 @@ import { GraphQLError } from 'graphql';
|
|
|
16
16
|
* This is a hook version of the class component lifecycle method `componentDidUpdate`.
|
|
17
17
|
* ALWAYS wrap in your own object.
|
|
18
18
|
*
|
|
19
|
+
* @param id optional id to use for logging or it will guess the id from the stack trace
|
|
19
20
|
* @param propsToWatch all the props to watch for changes
|
|
21
|
+
* @example
|
|
22
|
+
* const propsToWatch = { foo: props.foo, bar: props.bar };
|
|
23
|
+
* useDebugger({ id: "MyComponent", propsToWatch });
|
|
20
24
|
*/
|
|
21
|
-
const
|
|
22
|
-
var _a;
|
|
25
|
+
const useDebugger = ({ id, propsToWatch, }) => {
|
|
23
26
|
const prevPropsRef = useRef(propsToWatch);
|
|
24
|
-
const
|
|
27
|
+
const uniqueId = useMemo(() => {
|
|
28
|
+
var _a;
|
|
29
|
+
return id || ((_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n")[2].trim()) || "unknown-id";
|
|
30
|
+
}, [id]);
|
|
25
31
|
useEffect(() => {
|
|
26
|
-
const changedProps = Object.entries(propsToWatch
|
|
32
|
+
const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
|
|
27
33
|
if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
|
|
28
34
|
result[key + ""] = [prevPropsRef.current[key], value];
|
|
29
35
|
}
|
|
@@ -33,7 +39,7 @@ const useLogPropsChanged = (propsToWatch) => {
|
|
|
33
39
|
// eslint-disable-next-line no-console
|
|
34
40
|
Object.keys(changedProps).forEach(changedProp => {
|
|
35
41
|
// eslint-disable-next-line no-console
|
|
36
|
-
console.log(
|
|
42
|
+
console.log(`${uniqueId} changed property: ${changedProp}`);
|
|
37
43
|
// JSON stringify is used to avoid console.table from logging the object reference
|
|
38
44
|
const result = JSON.parse(JSON.stringify(changedProps[changedProp]));
|
|
39
45
|
const result0 = result[0];
|
|
@@ -53,28 +59,41 @@ const useLogPropsChanged = (propsToWatch) => {
|
|
|
53
59
|
console.dir(changedProps);
|
|
54
60
|
}
|
|
55
61
|
prevPropsRef.current = propsToWatch;
|
|
56
|
-
}, [
|
|
62
|
+
}, [propsToWatch, uniqueId]);
|
|
57
63
|
};
|
|
58
64
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
65
|
+
* Debugger component for debugging state changes and re-renders.
|
|
66
|
+
*
|
|
67
|
+
* This component will log when it is mounted, re-renders or unmounted.
|
|
61
68
|
* It will also log when any of its props change.
|
|
62
69
|
*
|
|
63
|
-
* @param
|
|
70
|
+
* @param id optional id to use for logging
|
|
71
|
+
* @param stop if true, will stop execution and open debugger
|
|
72
|
+
* @param logPropsChanges optional object with props to watch for changes
|
|
64
73
|
* @param children the children to render
|
|
65
74
|
*/
|
|
66
|
-
const Debugger = ({ logPropsChanges, children }) => {
|
|
67
|
-
|
|
75
|
+
const Debugger = ({ id, logPropsChanges, stop, children, }) => {
|
|
76
|
+
var _a, _b, _c, _d, _e, _f;
|
|
77
|
+
const uniqueId = id ||
|
|
78
|
+
((_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) ||
|
|
79
|
+
((_f = new Error().stack) === null || _f === void 0 ? void 0 : _f.split("\n")[2].trim()) ||
|
|
80
|
+
"unknown-id";
|
|
81
|
+
useDebugger({ id: uniqueId, propsToWatch: logPropsChanges || {} });
|
|
68
82
|
// eslint-disable-next-line no-console
|
|
69
|
-
console.log(
|
|
83
|
+
console.log(`${uniqueId} Debugger is rendering`);
|
|
70
84
|
useEffect(() => {
|
|
71
85
|
// eslint-disable-next-line no-console
|
|
72
|
-
console.log(
|
|
86
|
+
console.log(`${uniqueId} Debugger is mounting`);
|
|
73
87
|
return () => {
|
|
74
88
|
// eslint-disable-next-line no-console
|
|
75
|
-
console.log(
|
|
89
|
+
console.log(`${uniqueId} Debugger is unmounting`);
|
|
76
90
|
};
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
92
|
}, []);
|
|
93
|
+
if (stop === true) {
|
|
94
|
+
// eslint-disable-next-line no-debugger
|
|
95
|
+
debugger;
|
|
96
|
+
}
|
|
78
97
|
return jsx("div", Object.assign({ className: "Debugger" }, { children: children }));
|
|
79
98
|
};
|
|
80
99
|
|
|
@@ -481,7 +500,7 @@ class MockContextProviderBuilder {
|
|
|
481
500
|
/**
|
|
482
501
|
*
|
|
483
502
|
*/
|
|
484
|
-
const
|
|
503
|
+
const trackunitProviders = () => new MockContextProviderBuilder();
|
|
485
504
|
const TestRoot = tw.div `
|
|
486
505
|
--tw-scale-x: 0.99;
|
|
487
506
|
--tw-scale-y: 0.99;
|
|
@@ -569,4 +588,4 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
|
|
|
569
588
|
return null;
|
|
570
589
|
});
|
|
571
590
|
|
|
572
|
-
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,
|
|
591
|
+
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, trackunitProviders as t, useDebugger as u, validateIrisApp as v };
|
package/package.json
CHANGED
package/src/debugger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
2
|
type PropsToWatch<P> = P extends object ? P : never;
|
|
3
3
|
/**
|
|
4
4
|
* Logs props that have changed.
|
|
@@ -6,19 +6,31 @@ type PropsToWatch<P> = P extends object ? P : never;
|
|
|
6
6
|
* This is a hook version of the class component lifecycle method `componentDidUpdate`.
|
|
7
7
|
* ALWAYS wrap in your own object.
|
|
8
8
|
*
|
|
9
|
+
* @param id optional id to use for logging or it will guess the id from the stack trace
|
|
9
10
|
* @param propsToWatch all the props to watch for changes
|
|
11
|
+
* @example
|
|
12
|
+
* const propsToWatch = { foo: props.foo, bar: props.bar };
|
|
13
|
+
* useDebugger({ id: "MyComponent", propsToWatch });
|
|
10
14
|
*/
|
|
11
|
-
export declare const
|
|
15
|
+
export declare const useDebugger: <P extends object>({ id, propsToWatch, }: {
|
|
16
|
+
id?: string | undefined;
|
|
17
|
+
propsToWatch: PropsToWatch<P> | null;
|
|
18
|
+
}) => void;
|
|
12
19
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
20
|
+
* Debugger component for debugging state changes and re-renders.
|
|
21
|
+
*
|
|
22
|
+
* This component will log when it is mounted, re-renders or unmounted.
|
|
15
23
|
* It will also log when any of its props change.
|
|
16
24
|
*
|
|
17
|
-
* @param
|
|
25
|
+
* @param id optional id to use for logging
|
|
26
|
+
* @param stop if true, will stop execution and open debugger
|
|
27
|
+
* @param logPropsChanges optional object with props to watch for changes
|
|
18
28
|
* @param children the children to render
|
|
19
29
|
*/
|
|
20
|
-
export declare const Debugger: ({ logPropsChanges, children }: {
|
|
30
|
+
export declare const Debugger: ({ id, logPropsChanges, stop, children, }: {
|
|
21
31
|
children: React.ReactNode;
|
|
22
|
-
|
|
32
|
+
id?: string | undefined;
|
|
33
|
+
stop?: boolean | undefined;
|
|
34
|
+
logPropsChanges?: {} | undefined;
|
|
23
35
|
}) => JSX.Element;
|
|
24
36
|
export {};
|