@khanacademy/wonder-blocks-testing 7.1.10 → 7.1.12
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/CHANGELOG.md +31 -0
- package/dist/es/index.js +183 -120
- package/dist/fetch/fetch-request-matches-mock.d.ts +5 -0
- package/dist/fetch/fetch-request-matches-mock.js.flow +17 -0
- package/dist/fetch/mock-fetch.d.ts +5 -0
- package/dist/fetch/mock-fetch.js.flow +13 -0
- package/dist/fetch/types.d.ts +9 -0
- package/dist/fetch/types.js.flow +19 -0
- package/dist/fixtures/fixtures.basic.stories.d.ts +13 -0
- package/dist/fixtures/fixtures.basic.stories.js.flow +22 -0
- package/dist/fixtures/fixtures.d.ts +19 -0
- package/dist/fixtures/fixtures.defaultwrapper.stories.d.ts +9 -0
- package/dist/fixtures/fixtures.defaultwrapper.stories.js.flow +17 -0
- package/dist/fixtures/fixtures.js.flow +33 -0
- package/dist/fixtures/types.d.ts +36 -0
- package/dist/fixtures/types.js.flow +37 -0
- package/dist/gql/gql-request-matches-mock.d.ts +3 -0
- package/dist/gql/gql-request-matches-mock.js.flow +15 -0
- package/dist/gql/mock-gql-fetch.d.ts +5 -0
- package/dist/gql/mock-gql-fetch.js.flow +13 -0
- package/dist/gql/types.d.ts +15 -0
- package/dist/gql/types.js.flow +39 -0
- package/dist/harness/adapters/adapters.d.ts +35 -0
- package/dist/harness/adapters/adapters.js.flow +69 -0
- package/dist/harness/adapters/css.d.ts +12 -0
- package/dist/harness/adapters/css.js.flow +23 -0
- package/dist/harness/adapters/data.d.ts +18 -0
- package/dist/harness/adapters/data.js.flow +32 -0
- package/dist/harness/adapters/portal.d.ts +12 -0
- package/dist/harness/adapters/portal.js.flow +18 -0
- package/dist/harness/adapters/router.d.ts +94 -0
- package/dist/harness/adapters/router.js.flow +122 -0
- package/dist/harness/hook-harness.d.ts +13 -0
- package/dist/harness/hook-harness.js.flow +23 -0
- package/dist/harness/make-hook-harness.d.ts +17 -0
- package/dist/harness/make-hook-harness.js.flow +42 -0
- package/dist/harness/make-test-harness.d.ts +18 -0
- package/dist/harness/make-test-harness.js.flow +48 -0
- package/dist/harness/render-adapters.d.ts +6 -0
- package/dist/harness/render-adapters.js.flow +24 -0
- package/dist/harness/test-harness.d.ts +32 -0
- package/dist/harness/test-harness.js.flow +83 -0
- package/dist/harness/types.d.ts +46 -0
- package/dist/harness/types.js.flow +66 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +185 -127
- package/dist/index.js.flow +26 -2
- package/dist/mock-requester.d.ts +5 -0
- package/dist/mock-requester.js.flow +22 -0
- package/dist/respond-with.d.ts +57 -0
- package/dist/respond-with.js.flow +91 -0
- package/dist/response-impl.d.ts +1 -0
- package/dist/response-impl.js.flow +8 -0
- package/dist/settle-controller.d.ts +19 -0
- package/dist/settle-controller.js.flow +26 -0
- package/dist/settle-signal.d.ts +18 -0
- package/dist/settle-signal.js.flow +26 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.js.flow +46 -0
- package/package.json +6 -6
- package/src/__tests__/{mock-requester.test.js → mock-requester.test.ts} +1 -2
- package/src/__tests__/{respond-with.test.js → respond-with.test.ts} +0 -1
- package/src/__tests__/response-impl.test.js +1 -1
- package/src/__tests__/{settle-controller.test.js → settle-controller.test.ts} +0 -1
- package/src/__tests__/{settle-signal.test.js → settle-signal.test.ts} +0 -1
- package/src/fetch/__tests__/__snapshots__/{mock-fetch.test.js.snap → mock-fetch.test.ts.snap} +3 -3
- package/src/fetch/__tests__/{fetch-request-matches-mock.test.js → fetch-request-matches-mock.test.ts} +5 -6
- package/src/fetch/__tests__/{mock-fetch.test.js → mock-fetch.test.ts} +1 -2
- package/src/fetch/{fetch-request-matches-mock.js → fetch-request-matches-mock.ts} +3 -2
- package/src/fetch/{mock-fetch.js → mock-fetch.ts} +2 -3
- package/src/fetch/{types.js → types.ts} +5 -6
- package/src/fixtures/__tests__/{fixtures.test.js → fixtures.test.tsx} +6 -4
- package/src/fixtures/{fixtures.basic.stories.js → fixtures.basic.stories.tsx} +16 -13
- package/src/fixtures/{fixtures.defaultwrapper.stories.js → fixtures.defaultwrapper.stories.tsx} +8 -8
- package/src/fixtures/{fixtures.js → fixtures.tsx} +16 -11
- package/src/fixtures/{types.js → types.ts} +9 -13
- package/src/gql/__tests__/{gql-request-matches-mock.test.js → gql-request-matches-mock.test.ts} +17 -18
- package/src/gql/__tests__/{mock-gql-fetch.test.js → mock-gql-fetch.test.tsx} +44 -45
- package/src/gql/__tests__/{wb-data-integration.test.js → wb-data-integration.test.tsx} +21 -22
- package/src/gql/{gql-request-matches-mock.js → gql-request-matches-mock.ts} +1 -4
- package/src/gql/{mock-gql-fetch.js → mock-gql-fetch.ts} +3 -6
- package/src/gql/types.ts +33 -0
- package/src/harness/__tests__/{hook-harness.test.js → hook-harness.test.ts} +5 -6
- package/src/harness/__tests__/{make-hook-harness.test.js → make-hook-harness.test.tsx} +10 -11
- package/src/harness/__tests__/{make-test-harness.test.js → make-test-harness.test.tsx} +4 -5
- package/src/harness/__tests__/{render-adapters.test.js → render-adapters.test.tsx} +8 -9
- package/src/harness/__tests__/{test-harness.test.js → test-harness.test.ts} +5 -6
- package/src/harness/__tests__/{types.flowtest.js → types.flowtest.tsx} +24 -27
- package/src/harness/adapters/__tests__/{css.test.js → css.test.tsx} +2 -3
- package/src/harness/adapters/__tests__/{data.test.js → data.test.tsx} +4 -3
- package/src/harness/adapters/__tests__/{portal.test.js → portal.test.tsx} +0 -1
- package/src/harness/adapters/__tests__/{router.test.js → router.test.tsx} +75 -56
- package/src/harness/adapters/{adapters.js → adapters.ts} +1 -2
- package/src/harness/adapters/{css.js → css.tsx} +21 -18
- package/src/harness/adapters/{data.js → data.tsx} +7 -5
- package/src/harness/adapters/{portal.js → portal.tsx} +3 -4
- package/src/harness/adapters/router.tsx +218 -0
- package/src/harness/{hook-harness.js → hook-harness.ts} +2 -3
- package/src/harness/{make-hook-harness.js → make-hook-harness.ts} +6 -6
- package/src/harness/{make-test-harness.js → make-test-harness.tsx} +17 -20
- package/src/harness/{render-adapters.js → render-adapters.ts} +4 -4
- package/src/harness/{test-harness.js → test-harness.ts} +1 -12
- package/src/harness/{types.js → types.ts} +14 -12
- package/src/{index.js → index.ts} +0 -2
- package/src/{mock-requester.js → mock-requester.ts} +4 -3
- package/src/{respond-with.js → respond-with.ts} +42 -37
- package/src/{response-impl.js → response-impl.ts} +1 -2
- package/src/{settle-controller.js → settle-controller.ts} +9 -7
- package/src/{settle-signal.js → settle-signal.ts} +10 -7
- package/src/types.ts +40 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -18
- package/src/__docs__/_overview_fixtures.stories.mdx +0 -18
- package/src/__docs__/_overview_mocking.stories.mdx +0 -14
- package/src/__docs__/_overview_test_harness.stories.mdx +0 -18
- package/src/__docs__/exports.fixtures.stories.mdx +0 -31
- package/src/__docs__/exports.harness-adapters.stories.mdx +0 -187
- package/src/__docs__/exports.hook-harness.stories.mdx +0 -22
- package/src/__docs__/exports.make-hook-harness.stories.mdx +0 -25
- package/src/__docs__/exports.make-test-harness.stories.mdx +0 -28
- package/src/__docs__/exports.mock-fetch.stories.mdx +0 -40
- package/src/__docs__/exports.mock-gql-fetch.stories.mdx +0 -64
- package/src/__docs__/exports.respond-with.stories.mdx +0 -84
- package/src/__docs__/exports.settle-controller.stories.mdx +0 -32
- package/src/__docs__/exports.test-harness.stories.mdx +0 -23
- package/src/__docs__/types.fetch-mock-fn.stories.mdx +0 -22
- package/src/__docs__/types.fetch-mock-operation.stories.mdx +0 -18
- package/src/__docs__/types.fixture-fn.stories.mdx +0 -46
- package/src/__docs__/types.fixture-props.stories.mdx +0 -20
- package/src/__docs__/types.get-props-options.stories.mdx +0 -52
- package/src/__docs__/types.gql-fetch-mock-fn.stories.mdx +0 -27
- package/src/__docs__/types.gql-mock-operation.stories.mdx +0 -26
- package/src/__docs__/types.mock-response.stories.mdx +0 -22
- package/src/__docs__/types.test-harness-adapter.stories.mdx +0 -21
- package/src/__docs__/types.test-harness-adapters.stories.mdx +0 -46
- package/src/__docs__/types.test-harness-config.stories.mdx +0 -18
- package/src/__docs__/types.test-harness-configs.stories.mdx +0 -59
- package/src/gql/types.js +0 -34
- package/src/harness/adapters/router.js +0 -206
- package/src/types.js +0 -39
- /package/src/harness/adapters/__tests__/__snapshots__/{router.test.js.snap → router.test.tsx.snap} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for router
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { MemoryRouter } from "react-router-dom";
|
|
10
|
+
import type { LocationShape, Location } from "react-router-dom";
|
|
11
|
+
import type { TestHarnessAdapter } from "../types";
|
|
12
|
+
declare type MemoryRouterProps = JSX.LibraryManagedAttributes<
|
|
13
|
+
typeof MemoryRouter,
|
|
14
|
+
React.ComponentProps<typeof MemoryRouter>
|
|
15
|
+
>;
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for the withLocation test harness adapter.
|
|
18
|
+
*/
|
|
19
|
+
declare type Config =
|
|
20
|
+
| $ReadOnly<
|
|
21
|
+
| {
|
|
22
|
+
/**
|
|
23
|
+
* See MemoryRouter prop for initialEntries.
|
|
24
|
+
*/
|
|
25
|
+
initialEntries: $PropertyType<MemoryRouterProps, "initialEntries">,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* See MemoryRouter prop for initialIndex.
|
|
29
|
+
*/
|
|
30
|
+
initialIndex?: $PropertyType<MemoryRouterProps, "initialIndex">,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* See MemoryRouter prop for getUserConfirmation.
|
|
34
|
+
*/
|
|
35
|
+
getUserConfirmation?: $PropertyType<
|
|
36
|
+
MemoryRouterProps,
|
|
37
|
+
"getUserConfirmation"
|
|
38
|
+
>,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A path match to use.
|
|
42
|
+
*
|
|
43
|
+
* When this is specified, the harnessed component will be
|
|
44
|
+
* rendered inside a `Route` handler with this path.
|
|
45
|
+
*
|
|
46
|
+
* If the path matches the location, then the route will
|
|
47
|
+
* render the component.
|
|
48
|
+
*
|
|
49
|
+
* If the path does not match the location, then the route
|
|
50
|
+
* will not render the component.
|
|
51
|
+
*/
|
|
52
|
+
path?: string,
|
|
53
|
+
...
|
|
54
|
+
}
|
|
55
|
+
| {
|
|
56
|
+
/**
|
|
57
|
+
* The location to use.
|
|
58
|
+
*/
|
|
59
|
+
location: string | Location,
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Force the use of a StaticRouter, instead of MemoryRouter.
|
|
63
|
+
*/
|
|
64
|
+
forceStatic: true,
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A path match to use.
|
|
68
|
+
*
|
|
69
|
+
* When this is specified, the harnessed component will be
|
|
70
|
+
* rendered inside a `Route` handler with this path.
|
|
71
|
+
*
|
|
72
|
+
* If the path matches the location, then the route will
|
|
73
|
+
* render the component.
|
|
74
|
+
*
|
|
75
|
+
* If the path does not match the location, then the route
|
|
76
|
+
* will not render the component.
|
|
77
|
+
*/
|
|
78
|
+
path?: string,
|
|
79
|
+
...
|
|
80
|
+
}
|
|
81
|
+
| {
|
|
82
|
+
/**
|
|
83
|
+
* The initial location to use.
|
|
84
|
+
*/
|
|
85
|
+
location: string | LocationShape,
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A path match to use.
|
|
89
|
+
*
|
|
90
|
+
* When this is specified, the harnessed component will be
|
|
91
|
+
* rendered inside a `Route` handler with this path.
|
|
92
|
+
*
|
|
93
|
+
* If the path matches the location, then the route will
|
|
94
|
+
* render the component.
|
|
95
|
+
*
|
|
96
|
+
* If the path does not match the location, then the route
|
|
97
|
+
* will not render the component.
|
|
98
|
+
*/
|
|
99
|
+
path?: string,
|
|
100
|
+
...
|
|
101
|
+
}
|
|
102
|
+
>
|
|
103
|
+
| string;
|
|
104
|
+
/**
|
|
105
|
+
* The default configuration for this adapter.
|
|
106
|
+
*/
|
|
107
|
+
declare export var defaultConfig: {
|
|
108
|
+
+location: "/",
|
|
109
|
+
...
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Adapter that sets up a router and AppShell location-specific contexts.
|
|
113
|
+
*
|
|
114
|
+
* This allows you to ensure that components are being tested in the
|
|
115
|
+
* AppShell world.
|
|
116
|
+
*
|
|
117
|
+
* NOTE(somewhatabstract): The AppShell component itself already does
|
|
118
|
+
* the work of setting up routing and the AppShellContext and so using this
|
|
119
|
+
* adapter with the App component will have zero-effect since AppShell will
|
|
120
|
+
* override it.
|
|
121
|
+
*/
|
|
122
|
+
declare export var adapter: TestHarnessAdapter<Config>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { DefaultAdapters } from "./adapters/adapters";
|
|
3
|
+
import type { TestHarnessConfigs } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Create test wrapper for hook testing with Wonder Blocks default adapters.
|
|
6
|
+
*
|
|
7
|
+
* This is primarily useful for tests within Wonder Blocks.
|
|
8
|
+
*
|
|
9
|
+
* If you want to expand the range of adapters or change the default
|
|
10
|
+
* configurations, use `makeHookHarness` to create a new `hookHarness`
|
|
11
|
+
* function.
|
|
12
|
+
*/
|
|
13
|
+
export declare const hookHarness: (configs?: Partial<TestHarnessConfigs<typeof DefaultAdapters>>) => React.ForwardRefExoticComponent<any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for hook-harness
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { DefaultAdapters } from "./adapters/adapters";
|
|
10
|
+
import type { TestHarnessConfigs } from "./types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create test wrapper for hook testing with Wonder Blocks default adapters.
|
|
14
|
+
*
|
|
15
|
+
* This is primarily useful for tests within Wonder Blocks.
|
|
16
|
+
*
|
|
17
|
+
* If you want to expand the range of adapters or change the default
|
|
18
|
+
* configurations, use `makeHookHarness` to create a new `hookHarness`
|
|
19
|
+
* function.
|
|
20
|
+
*/
|
|
21
|
+
declare export var hookHarness: (
|
|
22
|
+
configs?: $Rest<TestHarnessConfigs<typeof DefaultAdapters>, { ... }>
|
|
23
|
+
) => React.ForwardRefExoticComponent<any>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Create a test harness method for use with React hooks.
|
|
5
|
+
*
|
|
6
|
+
* This returns a test harness method that applies the default configurations
|
|
7
|
+
* to the given adapters, wrapping a given component.
|
|
8
|
+
*
|
|
9
|
+
* @param {TAdapters} adapters All the adapters to be supported by the returned
|
|
10
|
+
* test harness.
|
|
11
|
+
* @param {TestHarnessConfigs<TAdapters>} defaultConfigs Default configuration values for
|
|
12
|
+
* the adapters.
|
|
13
|
+
* @returns {(
|
|
14
|
+
* configs?: $Shape<TestHarnessConfigs<TAdapters>>,
|
|
15
|
+
* ) => React.AbstractComponent<any, any>} A test harness.
|
|
16
|
+
*/
|
|
17
|
+
export declare const makeHookHarness: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, defaultConfigs: ObjMap<TAdapters, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>) => (configs?: Partial<ObjMap<TAdapters, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>> | undefined) => React.ForwardRefExoticComponent<any>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for make-hook-harness
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as $Flowgen$Import$_2e__2f_types from "./types";
|
|
9
|
+
import * as React from "react";
|
|
10
|
+
import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a test harness method for use with React hooks.
|
|
14
|
+
*
|
|
15
|
+
* This returns a test harness method that applies the default configurations
|
|
16
|
+
* to the given adapters, wrapping a given component.
|
|
17
|
+
* @param {TAdapters} adapters All the adapters to be supported by the returned
|
|
18
|
+
* test harness.
|
|
19
|
+
* @param {TestHarnessConfigs<TAdapters>} defaultConfigs Default configuration values for
|
|
20
|
+
* the adapters.
|
|
21
|
+
* @returns {(
|
|
22
|
+
configs?: $Shape<TestHarnessConfigs<TAdapters>>) => React.AbstractComponent<any, any>} A test harness.
|
|
23
|
+
*/
|
|
24
|
+
declare export var makeHookHarness: <TAdapters: TestHarnessAdapters>(
|
|
25
|
+
adapters: TAdapters,
|
|
26
|
+
defaultConfigs: ObjMap<
|
|
27
|
+
TAdapters,
|
|
28
|
+
<TConfig>(
|
|
29
|
+
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
30
|
+
) => TConfig | null | void
|
|
31
|
+
>
|
|
32
|
+
) => (
|
|
33
|
+
configs?: $Rest<
|
|
34
|
+
ObjMap<
|
|
35
|
+
TAdapters,
|
|
36
|
+
<TConfig>(
|
|
37
|
+
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
38
|
+
) => TConfig | null | void
|
|
39
|
+
>,
|
|
40
|
+
{ ... }
|
|
41
|
+
> | void
|
|
42
|
+
) => React.ForwardRefExoticComponent<any>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Create a test harness method for use with React components.
|
|
5
|
+
*
|
|
6
|
+
* This returns a test harness method that applies the default configurations
|
|
7
|
+
* to the given adapters, wrapping a given component.
|
|
8
|
+
*
|
|
9
|
+
* @param {TAdapters} adapters All the adapters to be supported by the returned
|
|
10
|
+
* test harness.
|
|
11
|
+
* @param {Configs<TAdapters>} defaultConfigs Default configuration values for
|
|
12
|
+
* the adapters.
|
|
13
|
+
* @returns {<-TProps, +Instance = mixed>(
|
|
14
|
+
* Component: React.AbstractComponent<TProps, Instance>,
|
|
15
|
+
* configs?: $Shape<Configs<TAdapters>>,
|
|
16
|
+
* ) => React.AbstractComponent<TProps, Instance>} A test harness.
|
|
17
|
+
*/
|
|
18
|
+
export declare const makeTestHarness: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, defaultConfigs: ObjMap<TAdapters, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>) => <TProps extends object>(Component: React.ComponentType<TProps>, configs?: Partial<ObjMap<TAdapters, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>> | undefined) => React.ForwardRefExoticComponent<React.PropsWithoutRef<TProps> & React.RefAttributes<unknown>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for make-test-harness
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as $Flowgen$Import$_2e__2f_types from "./types";
|
|
9
|
+
import * as React from "react";
|
|
10
|
+
import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a test harness method for use with React components.
|
|
14
|
+
*
|
|
15
|
+
* This returns a test harness method that applies the default configurations
|
|
16
|
+
* to the given adapters, wrapping a given component.
|
|
17
|
+
* @param {TAdapters} adapters All the adapters to be supported by the returned
|
|
18
|
+
* test harness.
|
|
19
|
+
* @param {Configs<TAdapters>} defaultConfigs Default configuration values for
|
|
20
|
+
* the adapters.
|
|
21
|
+
* @returns {<>() => } -TProps, +Instance = mixed>(
|
|
22
|
+
* Component: React.AbstractComponent<TProps, Instance>,
|
|
23
|
+
* configs?: $Shape<Configs<TAdapters>>,
|
|
24
|
+
* ) => React.AbstractComponent<TProps, Instance>} A test harness.
|
|
25
|
+
*/
|
|
26
|
+
declare export var makeTestHarness: <TAdapters: TestHarnessAdapters>(
|
|
27
|
+
adapters: TAdapters,
|
|
28
|
+
defaultConfigs: ObjMap<
|
|
29
|
+
TAdapters,
|
|
30
|
+
<TConfig>(
|
|
31
|
+
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
32
|
+
) => TConfig | null | void
|
|
33
|
+
>
|
|
34
|
+
) => <TProps: { [key: string]: any }>(
|
|
35
|
+
Component: React.ComponentType<TProps>,
|
|
36
|
+
configs?: $Rest<
|
|
37
|
+
ObjMap<
|
|
38
|
+
TAdapters,
|
|
39
|
+
<TConfig>(
|
|
40
|
+
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
41
|
+
) => TConfig | null | void
|
|
42
|
+
>,
|
|
43
|
+
{ ... }
|
|
44
|
+
> | void
|
|
45
|
+
) => React.ForwardRefExoticComponent<{
|
|
46
|
+
...React.PropsWithoutRef<TProps>,
|
|
47
|
+
...React.RefAttributes<mixed>,
|
|
48
|
+
}>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TestHarnessConfigs, TestHarnessAdapters } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Render test adapters around a child component.
|
|
5
|
+
*/
|
|
6
|
+
export declare const renderAdapters: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, configs: ObjMap<TAdapters, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>, children: React.ReactNode) => React.ReactElement;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for render-adapters
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as $Flowgen$Import$_2e__2f_types from "./types";
|
|
9
|
+
import * as React from "react";
|
|
10
|
+
import type { TestHarnessConfigs, TestHarnessAdapters } from "./types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Render test adapters around a child component.
|
|
14
|
+
*/
|
|
15
|
+
declare export var renderAdapters: <TAdapters: TestHarnessAdapters>(
|
|
16
|
+
adapters: TAdapters,
|
|
17
|
+
configs: ObjMap<
|
|
18
|
+
TAdapters,
|
|
19
|
+
<TConfig>(
|
|
20
|
+
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
21
|
+
) => TConfig | null | void
|
|
22
|
+
>,
|
|
23
|
+
children: React.Node
|
|
24
|
+
) => React.Element<>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference path="../../types/aphrodite.d.ts" />
|
|
2
|
+
/// <reference types="react" />
|
|
3
|
+
/**
|
|
4
|
+
* Wrap a component with a test harness using Wonder Blocks default adapters.
|
|
5
|
+
*
|
|
6
|
+
* This is primarily useful for tests within Wonder Blocks.
|
|
7
|
+
*
|
|
8
|
+
* If you want to expand the range of adapters or change the default
|
|
9
|
+
* configurations, use `makeTestHarness` to create a new `testHarness`
|
|
10
|
+
* function.
|
|
11
|
+
*/
|
|
12
|
+
export declare const testHarness: <TProps extends object>(Component: import("react").ComponentType<TProps>, configs?: Partial<ObjMap<{
|
|
13
|
+
readonly css: import("./types").TestHarnessAdapter<string | string[] | import("aphrodite").CSSProperties | {
|
|
14
|
+
classes: string[];
|
|
15
|
+
style: import("aphrodite").CSSProperties;
|
|
16
|
+
}>;
|
|
17
|
+
readonly data: import("./types").TestHarnessAdapter<((requestId: string) => Promise<any> | null | undefined) | ((requestId: string) => Promise<any> | null | undefined)[]>;
|
|
18
|
+
readonly portal: import("./types").TestHarnessAdapter<string>;
|
|
19
|
+
readonly router: import("./types").TestHarnessAdapter<string | Readonly<{
|
|
20
|
+
initialEntries: import("history").LocationDescriptor<unknown>[] | undefined;
|
|
21
|
+
initialIndex?: number | undefined;
|
|
22
|
+
getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
|
|
23
|
+
path?: string | undefined;
|
|
24
|
+
} | {
|
|
25
|
+
location: any;
|
|
26
|
+
forceStatic: true;
|
|
27
|
+
path?: string | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
location: any;
|
|
30
|
+
path?: string | undefined;
|
|
31
|
+
}>>;
|
|
32
|
+
}, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>> | undefined) => import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<TProps> & import("react").RefAttributes<unknown>>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for test-harness
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as $Flowgen$Import$react from "react";
|
|
9
|
+
import * as $Flowgen$Import$_2e__2f_types from "./types";
|
|
10
|
+
import * as $Flowgen$Import$aphrodite from "aphrodite";
|
|
11
|
+
import * as $Flowgen$Import$history from "history";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wrap a component with a test harness using Wonder Blocks default adapters.
|
|
15
|
+
*
|
|
16
|
+
* This is primarily useful for tests within Wonder Blocks.
|
|
17
|
+
*
|
|
18
|
+
* If you want to expand the range of adapters or change the default
|
|
19
|
+
* configurations, use `makeTestHarness` to create a new `testHarness`
|
|
20
|
+
* function.
|
|
21
|
+
*/
|
|
22
|
+
declare export var testHarness: <TProps: { [key: string]: any }>(
|
|
23
|
+
Component: $Flowgen$Import$react.ComponentType<TProps>,
|
|
24
|
+
configs?: $Rest<
|
|
25
|
+
ObjMap<
|
|
26
|
+
{
|
|
27
|
+
+css: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
|
|
28
|
+
| string
|
|
29
|
+
| string[]
|
|
30
|
+
| $Flowgen$Import$aphrodite.CSSProperties
|
|
31
|
+
| {
|
|
32
|
+
classes: string[],
|
|
33
|
+
style: $Flowgen$Import$aphrodite.CSSProperties,
|
|
34
|
+
...
|
|
35
|
+
}
|
|
36
|
+
>,
|
|
37
|
+
+data: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
|
|
38
|
+
| ((requestId: string) => Promise<any> | null | void)
|
|
39
|
+
| ((requestId: string) => Promise<any> | null | void)[]
|
|
40
|
+
>,
|
|
41
|
+
+portal: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<string>,
|
|
42
|
+
+router: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
|
|
43
|
+
| string
|
|
44
|
+
| $ReadOnly<
|
|
45
|
+
| {
|
|
46
|
+
initialEntries:
|
|
47
|
+
| $Flowgen$Import$history.LocationDescriptor<mixed>[]
|
|
48
|
+
| void,
|
|
49
|
+
initialIndex?: number | void,
|
|
50
|
+
getUserConfirmation?:
|
|
51
|
+
| ((
|
|
52
|
+
message: string,
|
|
53
|
+
callback: (ok: boolean) => void
|
|
54
|
+
) => void)
|
|
55
|
+
| void,
|
|
56
|
+
path?: string | void,
|
|
57
|
+
...
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
location: any,
|
|
61
|
+
forceStatic: true,
|
|
62
|
+
path?: string | void,
|
|
63
|
+
...
|
|
64
|
+
}
|
|
65
|
+
| {
|
|
66
|
+
location: any,
|
|
67
|
+
path?: string | void,
|
|
68
|
+
...
|
|
69
|
+
}
|
|
70
|
+
>
|
|
71
|
+
>,
|
|
72
|
+
...
|
|
73
|
+
},
|
|
74
|
+
<TConfig>(
|
|
75
|
+
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
76
|
+
) => TConfig | null | void
|
|
77
|
+
>,
|
|
78
|
+
{ ... }
|
|
79
|
+
> | void
|
|
80
|
+
) => $Flowgen$Import$react.ForwardRefExoticComponent<{
|
|
81
|
+
...$Flowgen$Import$react.PropsWithoutRef<TProps>,
|
|
82
|
+
...$Flowgen$Import$react.RefAttributes<mixed>,
|
|
83
|
+
}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A adapter to be composed with our test harnass infrastructure.
|
|
4
|
+
*/
|
|
5
|
+
export type TestHarnessAdapter<TConfig> = (children: React.ReactNode, config: TConfig) => React.ReactElement<any>;
|
|
6
|
+
/**
|
|
7
|
+
* A general map of adapters by their identifiers.
|
|
8
|
+
*
|
|
9
|
+
* It's OK that this has `any` for the config type as this is the very base
|
|
10
|
+
* version of a adapter set. In reality, a more specific type will be used
|
|
11
|
+
* with the harness functions that use more specific definitions of known
|
|
12
|
+
* adapters. This is just to support the base reality of not knowing.
|
|
13
|
+
*
|
|
14
|
+
* Use this on input positions only. Output positions for adapters
|
|
15
|
+
* should infer their type in most cases to ensure the strongest typing of
|
|
16
|
+
* the adapters.
|
|
17
|
+
*/
|
|
18
|
+
export type TestHarnessAdapters = {
|
|
19
|
+
[adapterID: string]: TestHarnessAdapter<any>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Mapping functions from a adapter-like function to config type.
|
|
23
|
+
*/
|
|
24
|
+
type ExtractConfig = <TConfig>(arg1: TestHarnessAdapter<TConfig>) => TConfig;
|
|
25
|
+
type ExtractMaybeConfig = <TConfig>(arg1: TestHarnessAdapter<TConfig>) => TConfig | null | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Type for easily defining an adapter's config type.
|
|
28
|
+
*
|
|
29
|
+
* This is the `TestHarnessAdapter` equivalent of `React.ElementConfig`.
|
|
30
|
+
*/
|
|
31
|
+
export type TestHarnessConfig<TAdapter> = ReturnType<ExtractConfig>;
|
|
32
|
+
/**
|
|
33
|
+
* The `TestHarnessConfigs` type as defined by parsing a given set of adapters.
|
|
34
|
+
*
|
|
35
|
+
* NOTE: This only works if the properties of the passed `TAdapters` type
|
|
36
|
+
* are explicitly typed as `TestHarnessAdapter<TConfig>` so if passing in a
|
|
37
|
+
* non-Adapters type (which we should be, to get strong `TConfig` types instead
|
|
38
|
+
* of `any`), then that object should make sure that each adapter is strongly
|
|
39
|
+
* marked as `TestHarnessAdapter<TConfig>` - TypeScript does not appear to pattern
|
|
40
|
+
* match against the type definition when invoking the `ExtractConfig` type and I
|
|
41
|
+
* haven't worked out how to get it to multi-dispatch so that it matches
|
|
42
|
+
* functions too. Even worse, if the type doesn't match, it just allows `any`
|
|
43
|
+
* in the `Configs` object, rather than indicating any kind of problem.
|
|
44
|
+
*/
|
|
45
|
+
export type TestHarnessConfigs<TAdapters extends TestHarnessAdapters> = ObjMap<TAdapters, ExtractMaybeConfig>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A adapter to be composed with our test harnass infrastructure.
|
|
12
|
+
*/
|
|
13
|
+
export type TestHarnessAdapter<TConfig> = (
|
|
14
|
+
children: React.Node,
|
|
15
|
+
config: TConfig
|
|
16
|
+
) => React.Element<any>;
|
|
17
|
+
/**
|
|
18
|
+
* A general map of adapters by their identifiers.
|
|
19
|
+
*
|
|
20
|
+
* It's OK that this has `any` for the config type as this is the very base
|
|
21
|
+
* version of a adapter set. In reality, a more specific type will be used
|
|
22
|
+
* with the harness functions that use more specific definitions of known
|
|
23
|
+
* adapters. This is just to support the base reality of not knowing.
|
|
24
|
+
*
|
|
25
|
+
* Use this on input positions only. Output positions for adapters
|
|
26
|
+
* should infer their type in most cases to ensure the strongest typing of
|
|
27
|
+
* the adapters.
|
|
28
|
+
*/
|
|
29
|
+
export type TestHarnessAdapters = {
|
|
30
|
+
[adapterID: string]: TestHarnessAdapter<any>,
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Mapping functions from a adapter-like function to config type.
|
|
34
|
+
*/
|
|
35
|
+
declare type ExtractConfig = <TConfig>(
|
|
36
|
+
arg1: TestHarnessAdapter<TConfig>
|
|
37
|
+
) => TConfig;
|
|
38
|
+
declare type ExtractMaybeConfig = <TConfig>(
|
|
39
|
+
arg1: TestHarnessAdapter<TConfig>
|
|
40
|
+
) => TConfig | null | void;
|
|
41
|
+
/**
|
|
42
|
+
* Type for easily defining an adapter's config type.
|
|
43
|
+
*
|
|
44
|
+
* This is the `TestHarnessAdapter` equivalent of `React.ElementConfig`.
|
|
45
|
+
*/
|
|
46
|
+
export type TestHarnessConfig<TAdapter> = $Call<
|
|
47
|
+
<R>((...args: any[]) => R) => R,
|
|
48
|
+
ExtractConfig
|
|
49
|
+
>;
|
|
50
|
+
/**
|
|
51
|
+
* The `TestHarnessConfigs` type as defined by parsing a given set of adapters.
|
|
52
|
+
*
|
|
53
|
+
* NOTE: This only works if the properties of the passed `TAdapters` type
|
|
54
|
+
* are explicitly typed as `TestHarnessAdapter<TConfig>` so if passing in a
|
|
55
|
+
* non-Adapters type (which we should be, to get strong `TConfig` types instead
|
|
56
|
+
* of `any`), then that object should make sure that each adapter is strongly
|
|
57
|
+
* marked as `TestHarnessAdapter<TConfig>` - TypeScript does not appear to pattern
|
|
58
|
+
* match against the type definition when invoking the `ExtractConfig` type and I
|
|
59
|
+
* haven't worked out how to get it to multi-dispatch so that it matches
|
|
60
|
+
* functions too. Even worse, if the type doesn't match, it just allows `any`
|
|
61
|
+
* in the `Configs` object, rather than indicating any kind of problem.
|
|
62
|
+
*/
|
|
63
|
+
export type TestHarnessConfigs<TAdapters: TestHarnessAdapters> = ObjMap<
|
|
64
|
+
TAdapters,
|
|
65
|
+
ExtractMaybeConfig
|
|
66
|
+
>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { fixtures } from "./fixtures/fixtures";
|
|
2
|
+
export type { FixtureFn, FixtureProps, GetPropsOptions } from "./fixtures/types";
|
|
3
|
+
export { mockFetch } from "./fetch/mock-fetch";
|
|
4
|
+
export { mockGqlFetch } from "./gql/mock-gql-fetch";
|
|
5
|
+
export { RespondWith } from "./respond-with";
|
|
6
|
+
export { SettleController } from "./settle-controller";
|
|
7
|
+
export type { MockResponse } from "./respond-with";
|
|
8
|
+
export type { FetchMockFn, FetchMockOperation } from "./fetch/types";
|
|
9
|
+
export type { GqlFetchMockFn, GqlMockOperation } from "./gql/types";
|
|
10
|
+
export * from "./harness/types";
|
|
11
|
+
export * as harnessAdapters from "./harness/adapters/adapters";
|
|
12
|
+
export { makeHookHarness } from "./harness/make-hook-harness";
|
|
13
|
+
export { makeTestHarness } from "./harness/make-test-harness";
|
|
14
|
+
export { hookHarness } from "./harness/hook-harness";
|
|
15
|
+
export { testHarness } from "./harness/test-harness";
|