@trackunit/react-core-contexts-test 0.1.78 → 0.1.79
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 +1 -0
- package/index.js +1 -1
- package/index2.cjs +46 -3
- package/index2.js +46 -4
- package/package.json +3 -3
- package/src/utils/queryFor.d.ts +18 -4
package/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ exports.mockOemBrandingContext = index.mockOemBrandingContext;
|
|
|
29
29
|
exports.mockToastContext = index.mockToastContext;
|
|
30
30
|
exports.mockUserSubscriptionContext = index.mockUserSubscriptionContext;
|
|
31
31
|
exports.queryFor = index.queryFor;
|
|
32
|
+
exports.queryForHook = index.queryForHook;
|
|
32
33
|
exports.trackunitProviders = index.trackunitProviders;
|
|
33
34
|
exports.useDebugger = index.useDebugger;
|
|
34
35
|
exports.validateIrisApp = index.validateIrisApp;
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { D as Debugger, T as TrackunitProvidersMockBuilder, l as doNothing, f as flushPromises,
|
|
1
|
+
export { D as Debugger, T as TrackunitProvidersMockBuilder, l as doNothing, f as flushPromises, o as flushPromisesInAct, m as mockAnalyticsContext, b as mockAssetSortingContext, e as mockCurrentUserContext, h as mockEnvironmentContext, i as mockOemBrandingContext, j as mockToastContext, k as mockUserSubscriptionContext, q as queryFor, n as queryForHook, 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 '@trackunit/react-core-contexts-api';
|
package/index2.cjs
CHANGED
|
@@ -43450,25 +43450,26 @@ const defaultOptions = {
|
|
|
43450
43450
|
errorPolicy: "all",
|
|
43451
43451
|
},
|
|
43452
43452
|
};
|
|
43453
|
+
const isDebugging = !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG;
|
|
43453
43454
|
/**
|
|
43454
43455
|
* This is a wrapper around the MockedProvider that logs errors to the console.
|
|
43455
43456
|
*/
|
|
43456
43457
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43457
43458
|
function ApolloMockedProviderWithError(props) {
|
|
43458
43459
|
const { mocks } = props, otherProps = __rest(props, ["mocks"]);
|
|
43459
|
-
const mockLink = new MockLink(mocks);
|
|
43460
|
+
const mockLink = new MockLink(mocks, false, { showWarnings: isDebugging });
|
|
43460
43461
|
const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
|
|
43461
43462
|
if (graphQLErrors) {
|
|
43462
43463
|
// eslint-disable-next-line array-callback-return
|
|
43463
43464
|
graphQLErrors.map(({ message, locations, path }) => {
|
|
43464
|
-
if (
|
|
43465
|
+
if (isDebugging) {
|
|
43465
43466
|
// eslint-disable-next-line no-console
|
|
43466
43467
|
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
|
43467
43468
|
}
|
|
43468
43469
|
});
|
|
43469
43470
|
}
|
|
43470
43471
|
if (networkError) {
|
|
43471
|
-
if (
|
|
43472
|
+
if (isDebugging) {
|
|
43472
43473
|
// eslint-disable-next-line no-console
|
|
43473
43474
|
console.log(`[Network error]: ${networkError}`);
|
|
43474
43475
|
}
|
|
@@ -43962,6 +43963,47 @@ const queryFor = (document, variables, data, error) => {
|
|
|
43962
43963
|
},
|
|
43963
43964
|
};
|
|
43964
43965
|
};
|
|
43966
|
+
/**
|
|
43967
|
+
*
|
|
43968
|
+
* @param document Document that represents the specific GQL query / mutation schema.
|
|
43969
|
+
* @param variables Variables that should be passed to the query / mutation.
|
|
43970
|
+
* Note that an *exact* match between the mock and operation is necessary.
|
|
43971
|
+
* @param data Data object to be returned.
|
|
43972
|
+
* Note that *all* properties should be given a value, use `null` in place of `undefined`,
|
|
43973
|
+
* otherwise nothing will be returned.
|
|
43974
|
+
* @param error ApolloError object to be returned.
|
|
43975
|
+
* @returns {MockedResponse} that can be passed to the mocked ApolloProvider.
|
|
43976
|
+
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
43977
|
+
*/
|
|
43978
|
+
const queryForHook = (hookFn, document, variables, data, error) => {
|
|
43979
|
+
return {
|
|
43980
|
+
request: {
|
|
43981
|
+
query: document,
|
|
43982
|
+
variables,
|
|
43983
|
+
},
|
|
43984
|
+
newData: () => {
|
|
43985
|
+
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
43986
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43987
|
+
const name = document.definitions[0].name.value;
|
|
43988
|
+
// eslint-disable-next-line no-console
|
|
43989
|
+
console.log("Found Response for: " +
|
|
43990
|
+
name +
|
|
43991
|
+
" for variables: " +
|
|
43992
|
+
JSON.stringify(variables, null, 2) +
|
|
43993
|
+
" Returning: " +
|
|
43994
|
+
"{ data: " +
|
|
43995
|
+
JSON.stringify(data, null, 2) +
|
|
43996
|
+
", error: " +
|
|
43997
|
+
JSON.stringify(error, null, 2) +
|
|
43998
|
+
"}");
|
|
43999
|
+
}
|
|
44000
|
+
return {
|
|
44001
|
+
data,
|
|
44002
|
+
errors: error ? [new GraphQLError(error.message)] : undefined,
|
|
44003
|
+
};
|
|
44004
|
+
},
|
|
44005
|
+
};
|
|
44006
|
+
};
|
|
43965
44007
|
|
|
43966
44008
|
/**
|
|
43967
44009
|
* This helps validate the IrisApp is exposed correctly it must expose:
|
|
@@ -44018,6 +44060,7 @@ exports.mockOemBrandingContext = mockOemBrandingContext;
|
|
|
44018
44060
|
exports.mockToastContext = mockToastContext;
|
|
44019
44061
|
exports.mockUserSubscriptionContext = mockUserSubscriptionContext;
|
|
44020
44062
|
exports.queryFor = queryFor;
|
|
44063
|
+
exports.queryForHook = queryForHook;
|
|
44021
44064
|
exports.trackunitProviders = trackunitProviders;
|
|
44022
44065
|
exports.useDebugger = useDebugger;
|
|
44023
44066
|
exports.validateIrisApp = validateIrisApp;
|
package/index2.js
CHANGED
|
@@ -43422,25 +43422,26 @@ const defaultOptions = {
|
|
|
43422
43422
|
errorPolicy: "all",
|
|
43423
43423
|
},
|
|
43424
43424
|
};
|
|
43425
|
+
const isDebugging = !!process.env.VSCODE_INSPECTOR_OPTIONS || !!process.env.DEBUG;
|
|
43425
43426
|
/**
|
|
43426
43427
|
* This is a wrapper around the MockedProvider that logs errors to the console.
|
|
43427
43428
|
*/
|
|
43428
43429
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43429
43430
|
function ApolloMockedProviderWithError(props) {
|
|
43430
43431
|
const { mocks } = props, otherProps = __rest(props, ["mocks"]);
|
|
43431
|
-
const mockLink = new MockLink(mocks);
|
|
43432
|
+
const mockLink = new MockLink(mocks, false, { showWarnings: isDebugging });
|
|
43432
43433
|
const errorLoggingLink = onError(({ graphQLErrors, networkError }) => {
|
|
43433
43434
|
if (graphQLErrors) {
|
|
43434
43435
|
// eslint-disable-next-line array-callback-return
|
|
43435
43436
|
graphQLErrors.map(({ message, locations, path }) => {
|
|
43436
|
-
if (
|
|
43437
|
+
if (isDebugging) {
|
|
43437
43438
|
// eslint-disable-next-line no-console
|
|
43438
43439
|
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
|
|
43439
43440
|
}
|
|
43440
43441
|
});
|
|
43441
43442
|
}
|
|
43442
43443
|
if (networkError) {
|
|
43443
|
-
if (
|
|
43444
|
+
if (isDebugging) {
|
|
43444
43445
|
// eslint-disable-next-line no-console
|
|
43445
43446
|
console.log(`[Network error]: ${networkError}`);
|
|
43446
43447
|
}
|
|
@@ -43934,6 +43935,47 @@ const queryFor = (document, variables, data, error) => {
|
|
|
43934
43935
|
},
|
|
43935
43936
|
};
|
|
43936
43937
|
};
|
|
43938
|
+
/**
|
|
43939
|
+
*
|
|
43940
|
+
* @param document Document that represents the specific GQL query / mutation schema.
|
|
43941
|
+
* @param variables Variables that should be passed to the query / mutation.
|
|
43942
|
+
* Note that an *exact* match between the mock and operation is necessary.
|
|
43943
|
+
* @param data Data object to be returned.
|
|
43944
|
+
* Note that *all* properties should be given a value, use `null` in place of `undefined`,
|
|
43945
|
+
* otherwise nothing will be returned.
|
|
43946
|
+
* @param error ApolloError object to be returned.
|
|
43947
|
+
* @returns {MockedResponse} that can be passed to the mocked ApolloProvider.
|
|
43948
|
+
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
43949
|
+
*/
|
|
43950
|
+
const queryForHook = (hookFn, document, variables, data, error) => {
|
|
43951
|
+
return {
|
|
43952
|
+
request: {
|
|
43953
|
+
query: document,
|
|
43954
|
+
variables,
|
|
43955
|
+
},
|
|
43956
|
+
newData: () => {
|
|
43957
|
+
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
43958
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43959
|
+
const name = document.definitions[0].name.value;
|
|
43960
|
+
// eslint-disable-next-line no-console
|
|
43961
|
+
console.log("Found Response for: " +
|
|
43962
|
+
name +
|
|
43963
|
+
" for variables: " +
|
|
43964
|
+
JSON.stringify(variables, null, 2) +
|
|
43965
|
+
" Returning: " +
|
|
43966
|
+
"{ data: " +
|
|
43967
|
+
JSON.stringify(data, null, 2) +
|
|
43968
|
+
", error: " +
|
|
43969
|
+
JSON.stringify(error, null, 2) +
|
|
43970
|
+
"}");
|
|
43971
|
+
}
|
|
43972
|
+
return {
|
|
43973
|
+
data,
|
|
43974
|
+
errors: error ? [new GraphQLError(error.message)] : undefined,
|
|
43975
|
+
};
|
|
43976
|
+
},
|
|
43977
|
+
};
|
|
43978
|
+
};
|
|
43937
43979
|
|
|
43938
43980
|
/**
|
|
43939
43981
|
* This helps validate the IrisApp is exposed correctly it must expose:
|
|
@@ -43972,4 +44014,4 @@ const validateIrisApp = (irisApp) => __awaiter(void 0, void 0, void 0, function*
|
|
|
43972
44014
|
return null;
|
|
43973
44015
|
});
|
|
43974
44016
|
|
|
43975
|
-
export { Debugger as D, TrackunitProvidersMockBuilder as T, __awaiter as _, act as a, mockAssetSortingContext as b, commonjsGlobal as c, dom_esm as d, mockCurrentUserContext as e, flushPromises as f, getAugmentedNamespace as g, mockEnvironmentContext as h, mockOemBrandingContext as i, mockToastContext as j, mockUserSubscriptionContext as k, doNothing as l, mockAnalyticsContext as m,
|
|
44017
|
+
export { Debugger as D, TrackunitProvidersMockBuilder as T, __awaiter as _, act as a, mockAssetSortingContext as b, commonjsGlobal as c, dom_esm as d, mockCurrentUserContext as e, flushPromises as f, getAugmentedNamespace as g, mockEnvironmentContext as h, mockOemBrandingContext as i, mockToastContext as j, mockUserSubscriptionContext as k, doNothing as l, mockAnalyticsContext as m, queryForHook as n, flushPromisesInAct as o, queryFor as q, trackunitProviders as t, useDebugger 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.
|
|
3
|
+
"version": "0.1.79",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"types": "./src/index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@apollo/client": "3.7.10",
|
|
15
|
-
"@trackunit/react-core-contexts-api": "0.2.
|
|
16
|
-
"@trackunit/react-core-hooks": "0.2.
|
|
15
|
+
"@trackunit/react-core-contexts-api": "0.2.43",
|
|
16
|
+
"@trackunit/react-core-hooks": "0.2.67",
|
|
17
17
|
"@trackunit/tailwind-styled-components": "0.0.58",
|
|
18
18
|
"graphql": "15.8.0",
|
|
19
19
|
"lodash": "4.17.21",
|
package/src/utils/queryFor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApolloError } from "@apollo/client";
|
|
1
|
+
import { ApolloError, OperationVariables, QueryHookOptions, useLazyQuery, useQuery } from "@apollo/client";
|
|
2
2
|
import { MockedResponse } from "@apollo/client/testing";
|
|
3
3
|
import { DocumentNode } from "graphql";
|
|
4
4
|
/**
|
|
@@ -13,6 +13,20 @@ import { DocumentNode } from "graphql";
|
|
|
13
13
|
* @returns {MockedResponse} that can be passed to the mocked ApolloProvider.
|
|
14
14
|
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
15
15
|
*/
|
|
16
|
-
export declare const queryFor: <
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
export declare const queryFor: <TData, TVariables extends OperationVariables = OperationVariables>(document: DocumentNode, variables: TVariables, data: TData | null, error?: ApolloError | Error) => MockedResponse;
|
|
17
|
+
type QueryReturn<TData, TVariables extends OperationVariables = OperationVariables> = ReturnType<typeof useQuery<TData, TVariables>>;
|
|
18
|
+
type QueryLazyReturn<TData, TVariables extends OperationVariables = OperationVariables> = ReturnType<typeof useLazyQuery<TData, TVariables>>;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param document Document that represents the specific GQL query / mutation schema.
|
|
22
|
+
* @param variables Variables that should be passed to the query / mutation.
|
|
23
|
+
* Note that an *exact* match between the mock and operation is necessary.
|
|
24
|
+
* @param data Data object to be returned.
|
|
25
|
+
* Note that *all* properties should be given a value, use `null` in place of `undefined`,
|
|
26
|
+
* otherwise nothing will be returned.
|
|
27
|
+
* @param error ApolloError object to be returned.
|
|
28
|
+
* @returns {MockedResponse} that can be passed to the mocked ApolloProvider.
|
|
29
|
+
* @see [Testing React components using MockedProvider and associated APIs](https://www.apollographql.com/docs/react/development-testing/testing/)
|
|
30
|
+
*/
|
|
31
|
+
export declare const queryForHook: <TData, TVariables extends OperationVariables = OperationVariables>(hookFn: (baseOptions: QueryHookOptions<TData, TVariables>) => import("@apollo/client").QueryResult<TData, TVariables> | import("@apollo/client").LazyQueryResultTuple<TData, TVariables>, document: DocumentNode, variables: TVariables, data: TData | null, error?: ApolloError | Error) => MockedResponse;
|
|
32
|
+
export {};
|