@khanacademy/wonder-blocks-testing 7.1.10 → 7.1.11
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 +25 -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
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
|
|
4
|
-
import {StaticRouter, MemoryRouter, Route, Switch} from "react-router-dom";
|
|
5
|
-
|
|
6
|
-
import type {LocationShape, Location} from "react-router-dom";
|
|
7
|
-
import type {TestHarnessAdapter} from "../types";
|
|
8
|
-
|
|
9
|
-
type MemoryRouterProps = React.ElementConfig<typeof MemoryRouter>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Configuration for the withLocation test harness adapter.
|
|
13
|
-
*/
|
|
14
|
-
type Config =
|
|
15
|
-
| $ReadOnly<
|
|
16
|
-
| {|
|
|
17
|
-
/**
|
|
18
|
-
* See MemoryRouter prop for initialEntries.
|
|
19
|
-
*/
|
|
20
|
-
initialEntries: MemoryRouterProps["initialEntries"],
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* See MemoryRouter prop for initialIndex.
|
|
24
|
-
*/
|
|
25
|
-
initialIndex?: MemoryRouterProps["initialIndex"],
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* See MemoryRouter prop for getUserConfirmation.
|
|
29
|
-
*/
|
|
30
|
-
getUserConfirmation?: MemoryRouterProps["getUserConfirmation"],
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A path match to use.
|
|
34
|
-
*
|
|
35
|
-
* When this is specified, the harnessed component will be
|
|
36
|
-
* rendered inside a `Route` handler with this path.
|
|
37
|
-
*
|
|
38
|
-
* If the path matches the location, then the route will
|
|
39
|
-
* render the component.
|
|
40
|
-
*
|
|
41
|
-
* If the path does not match the location, then the route
|
|
42
|
-
* will not render the component.
|
|
43
|
-
*/
|
|
44
|
-
path?: string,
|
|
45
|
-
|}
|
|
46
|
-
| {|
|
|
47
|
-
/**
|
|
48
|
-
* The location to use.
|
|
49
|
-
*/
|
|
50
|
-
location: string | Location,
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Force the use of a StaticRouter, instead of MemoryRouter.
|
|
54
|
-
*/
|
|
55
|
-
forceStatic: true,
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* A path match to use.
|
|
59
|
-
*
|
|
60
|
-
* When this is specified, the harnessed component will be
|
|
61
|
-
* rendered inside a `Route` handler with this path.
|
|
62
|
-
*
|
|
63
|
-
* If the path matches the location, then the route will
|
|
64
|
-
* render the component.
|
|
65
|
-
*
|
|
66
|
-
* If the path does not match the location, then the route
|
|
67
|
-
* will not render the component.
|
|
68
|
-
*/
|
|
69
|
-
path?: string,
|
|
70
|
-
|}
|
|
71
|
-
| {|
|
|
72
|
-
/**
|
|
73
|
-
* The initial location to use.
|
|
74
|
-
*/
|
|
75
|
-
location: string | LocationShape,
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* A path match to use.
|
|
79
|
-
*
|
|
80
|
-
* When this is specified, the harnessed component will be
|
|
81
|
-
* rendered inside a `Route` handler with this path.
|
|
82
|
-
*
|
|
83
|
-
* If the path matches the location, then the route will
|
|
84
|
-
* render the component.
|
|
85
|
-
*
|
|
86
|
-
* If the path does not match the location, then the route
|
|
87
|
-
* will not render the component.
|
|
88
|
-
*/
|
|
89
|
-
path?: string,
|
|
90
|
-
|},
|
|
91
|
-
>
|
|
92
|
-
// The initial location to use.
|
|
93
|
-
| string;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The default configuration for this adapter.
|
|
97
|
-
*/
|
|
98
|
-
export const defaultConfig = {location: "/"};
|
|
99
|
-
|
|
100
|
-
const maybeWithRoute = (children: React.Node, path: ?string): React.Node => {
|
|
101
|
-
if (path == null) {
|
|
102
|
-
return children;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<Switch>
|
|
107
|
-
<Route exact={true} path={path}>
|
|
108
|
-
{children}
|
|
109
|
-
</Route>
|
|
110
|
-
<Route
|
|
111
|
-
path="*"
|
|
112
|
-
render={() => {
|
|
113
|
-
throw new Error(
|
|
114
|
-
"The configured path must match the configured location or your harnessed component will not render.",
|
|
115
|
-
);
|
|
116
|
-
}}
|
|
117
|
-
/>
|
|
118
|
-
</Switch>
|
|
119
|
-
);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Adapter that sets up a router and AppShell location-specific contexts.
|
|
124
|
-
*
|
|
125
|
-
* This allows you to ensure that components are being tested in the
|
|
126
|
-
* AppShell world.
|
|
127
|
-
*
|
|
128
|
-
* NOTE(somewhatabstract): The AppShell component itself already does
|
|
129
|
-
* the work of setting up routing and the AppShellContext and so using this
|
|
130
|
-
* adapter with the App component will have zero-effect since AppShell will
|
|
131
|
-
* override it.
|
|
132
|
-
*/
|
|
133
|
-
export const adapter: TestHarnessAdapter<Config> = (
|
|
134
|
-
children: React.Node,
|
|
135
|
-
config: Config,
|
|
136
|
-
): React.Element<any> => {
|
|
137
|
-
if (typeof config === "string") {
|
|
138
|
-
config = {
|
|
139
|
-
location: config,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Wrap children with the various contexts and routes, as per the config.
|
|
144
|
-
const wrappedWithRoute = maybeWithRoute(children, config.path);
|
|
145
|
-
if (config.forceStatic) {
|
|
146
|
-
/**
|
|
147
|
-
* There may be times (SSR testing comes to mind) where we will be
|
|
148
|
-
* really strict about not permitting client-side navigation events.
|
|
149
|
-
*/
|
|
150
|
-
return (
|
|
151
|
-
<StaticRouter location={config.location} context={{}}>
|
|
152
|
-
{wrappedWithRoute}
|
|
153
|
-
</StaticRouter>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* OK, we must be OK with a memory router.
|
|
159
|
-
*
|
|
160
|
-
* There are two flavors of config for this. The easy one with just a
|
|
161
|
-
* location, and the complex one for those gnarlier setups.
|
|
162
|
-
*
|
|
163
|
-
* First, the easy one.
|
|
164
|
-
*/
|
|
165
|
-
if (typeof config.location !== "undefined") {
|
|
166
|
-
return (
|
|
167
|
-
<MemoryRouter initialEntries={[config.location]}>
|
|
168
|
-
{wrappedWithRoute}
|
|
169
|
-
</MemoryRouter>
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* If it's not the easy one, it should be the complex one.
|
|
175
|
-
* Let's make sure we have good data (also keeps flow happy).
|
|
176
|
-
*/
|
|
177
|
-
if (typeof config.initialEntries === "undefined") {
|
|
178
|
-
throw new Error(
|
|
179
|
-
"A location or initial history entries must be provided.",
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* What should happen if no entries were in the array?
|
|
185
|
-
* It likely uses the root one anyway, but a consistent API is what
|
|
186
|
-
* we want, so let's ensure we always have our default location at least.
|
|
187
|
-
*/
|
|
188
|
-
const entries =
|
|
189
|
-
config.initialEntries.length === 0
|
|
190
|
-
? [defaultConfig.location]
|
|
191
|
-
: config.initialEntries;
|
|
192
|
-
|
|
193
|
-
// Memory router doesn't allow us to pass maybe types in its flow types.
|
|
194
|
-
// So let's build props then spread them.
|
|
195
|
-
const routerProps: MemoryRouterProps = {
|
|
196
|
-
initialEntries: entries,
|
|
197
|
-
};
|
|
198
|
-
if (config.initialIndex != null) {
|
|
199
|
-
routerProps.initialIndex = config.initialIndex;
|
|
200
|
-
}
|
|
201
|
-
if (config.getUserConfirmation != null) {
|
|
202
|
-
routerProps.getUserConfirmation = config.getUserConfirmation;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return <MemoryRouter {...routerProps}>{wrappedWithRoute}</MemoryRouter>;
|
|
206
|
-
};
|
package/src/types.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import type {MockResponse} from "./respond-with";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A valid GraphQL response as supported by our mocking framework.
|
|
6
|
-
* Note that we don't currently support both data and errors being set.
|
|
7
|
-
*/
|
|
8
|
-
export type GraphQLJson<TData: {...}> =
|
|
9
|
-
| {|
|
|
10
|
-
data: TData,
|
|
11
|
-
|}
|
|
12
|
-
| {|
|
|
13
|
-
errors: Array<{|
|
|
14
|
-
message: string,
|
|
15
|
-
|}>,
|
|
16
|
-
|};
|
|
17
|
-
|
|
18
|
-
export type MockFn<TOperationType> = {|
|
|
19
|
-
(...args: Array<any>): Promise<Response>,
|
|
20
|
-
mockOperation: MockOperationFn<TOperationType>,
|
|
21
|
-
mockOperationOnce: MockOperationFn<TOperationType>,
|
|
22
|
-
|};
|
|
23
|
-
|
|
24
|
-
export type OperationMock<TOperation> = {|
|
|
25
|
-
operation: TOperation,
|
|
26
|
-
onceOnly: boolean,
|
|
27
|
-
used: boolean,
|
|
28
|
-
response: () => Promise<Response>,
|
|
29
|
-
|};
|
|
30
|
-
|
|
31
|
-
export type OperationMatcher<TOperation> = (
|
|
32
|
-
operation: TOperation,
|
|
33
|
-
...args: Array<any>
|
|
34
|
-
) => boolean;
|
|
35
|
-
|
|
36
|
-
export type MockOperationFn<TOperationType> = <TOperation: TOperationType>(
|
|
37
|
-
operation: TOperation,
|
|
38
|
-
response: MockResponse<any>,
|
|
39
|
-
) => MockFn<TOperationType>;
|
/package/src/harness/adapters/__tests__/__snapshots__/{router.test.js.snap → router.test.tsx.snap}
RENAMED
|
File without changes
|