@khanacademy/wonder-blocks-testing 8.0.7 → 8.0.9
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 +12 -0
- package/dist/fixtures/types.d.ts +2 -2
- package/dist/fixtures/types.js.flow +2 -2
- package/dist/harness/adapters/adapters.d.ts +2 -2
- package/dist/harness/adapters/adapters.js.flow +10 -45
- package/dist/harness/adapters/router.d.ts +3 -3
- package/dist/harness/adapters/router.js.flow +3 -3
- package/dist/harness/make-hook-harness.d.ts +1 -1
- package/dist/harness/make-hook-harness.js.flow +2 -16
- package/dist/harness/make-test-harness.d.ts +1 -1
- package/dist/harness/make-test-harness.js.flow +3 -17
- package/dist/harness/render-adapters.d.ts +1 -1
- package/dist/harness/render-adapters.js.flow +1 -7
- package/dist/harness/test-harness.d.ts +4 -4
- package/dist/harness/test-harness.js.flow +41 -49
- package/dist/harness/types.d.ts +7 -17
- package/dist/harness/types.js.flow +17 -25
- package/package.json +3 -3
- package/src/fixtures/types.ts +2 -2
- package/src/harness/__tests__/{types.flowtest.tsx → types.typestest.tsx} +3 -5
- package/src/harness/adapters/adapters.js.flow +28 -0
- package/src/harness/adapters/adapters.ts +4 -1
- package/src/harness/adapters/router.jsx.flow +112 -0
- package/src/harness/adapters/router.tsx +5 -4
- package/src/harness/types.js.flow +57 -0
- package/src/harness/types.ts +13 -23
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// WARNING: If you modify this file you may need to update adapters.js.flow
|
|
2
|
+
// to ensure that the Flow types are still correct.
|
|
3
|
+
|
|
1
4
|
import * as css from "./css";
|
|
2
5
|
import * as data from "./data";
|
|
3
6
|
import * as portal from "./portal";
|
|
@@ -29,4 +32,4 @@ export const DefaultConfigs: TestHarnessConfigs<typeof DefaultAdapters> = {
|
|
|
29
32
|
data: data.defaultConfig,
|
|
30
33
|
portal: portal.defaultConfig,
|
|
31
34
|
router: router.defaultConfig,
|
|
32
|
-
};
|
|
35
|
+
} as const;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flow
|
|
3
|
+
*/
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { MemoryRouter } from "react-router-dom";
|
|
6
|
+
import type { LocationShape } from "react-router-dom";
|
|
7
|
+
import type { TestHarnessAdapter } from "../types";
|
|
8
|
+
declare type MemoryRouterProps = React.ElementConfig<typeof MemoryRouter>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for the withLocation test harness adapter.
|
|
12
|
+
*/
|
|
13
|
+
declare type Config =
|
|
14
|
+
| $ReadOnly<
|
|
15
|
+
| {|
|
|
16
|
+
/**
|
|
17
|
+
* See MemoryRouter prop for initialEntries.
|
|
18
|
+
*/
|
|
19
|
+
initialEntries: $PropertyType<MemoryRouterProps, "initialEntries">,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* See MemoryRouter prop for initialIndex.
|
|
23
|
+
*/
|
|
24
|
+
initialIndex?: $PropertyType<MemoryRouterProps, "initialIndex">,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* See MemoryRouter prop for getUserConfirmation.
|
|
28
|
+
*/
|
|
29
|
+
getUserConfirmation?: $PropertyType<
|
|
30
|
+
MemoryRouterProps,
|
|
31
|
+
"getUserConfirmation"
|
|
32
|
+
>,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A path match to use.
|
|
36
|
+
*
|
|
37
|
+
* When this is specified, the harnessed component will be
|
|
38
|
+
* rendered inside a `Route` handler with this path.
|
|
39
|
+
*
|
|
40
|
+
* If the path matches the location, then the route will
|
|
41
|
+
* render the component.
|
|
42
|
+
*
|
|
43
|
+
* If the path does not match the location, then the route
|
|
44
|
+
* will not render the component.
|
|
45
|
+
*/
|
|
46
|
+
path?: string,
|
|
47
|
+
|}
|
|
48
|
+
| {|
|
|
49
|
+
/**
|
|
50
|
+
* The location to use.
|
|
51
|
+
*/
|
|
52
|
+
location: string | LocationShape,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Force the use of a StaticRouter, instead of MemoryRouter.
|
|
56
|
+
*/
|
|
57
|
+
forceStatic: true,
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A path match to use.
|
|
61
|
+
*
|
|
62
|
+
* When this is specified, the harnessed component will be
|
|
63
|
+
* rendered inside a `Route` handler with this path.
|
|
64
|
+
*
|
|
65
|
+
* If the path matches the location, then the route will
|
|
66
|
+
* render the component.
|
|
67
|
+
*
|
|
68
|
+
* If the path does not match the location, then the route
|
|
69
|
+
* will not render the component.
|
|
70
|
+
*/
|
|
71
|
+
path?: string,
|
|
72
|
+
|}
|
|
73
|
+
| {|
|
|
74
|
+
/**
|
|
75
|
+
* The initial location to use.
|
|
76
|
+
*/
|
|
77
|
+
location: string | LocationShape,
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A path match to use.
|
|
81
|
+
*
|
|
82
|
+
* When this is specified, the harnessed component will be
|
|
83
|
+
* rendered inside a `Route` handler with this path.
|
|
84
|
+
*
|
|
85
|
+
* If the path matches the location, then the route will
|
|
86
|
+
* render the component.
|
|
87
|
+
*
|
|
88
|
+
* If the path does not match the location, then the route
|
|
89
|
+
* will not render the component.
|
|
90
|
+
*/
|
|
91
|
+
path?: string,
|
|
92
|
+
|}
|
|
93
|
+
>
|
|
94
|
+
| string;
|
|
95
|
+
/**
|
|
96
|
+
* The default configuration for this adapter.
|
|
97
|
+
*/
|
|
98
|
+
declare export var defaultConfig: {|
|
|
99
|
+
+location: "/",
|
|
100
|
+
|};
|
|
101
|
+
/**
|
|
102
|
+
* Adapter that sets up a router and AppShell location-specific contexts.
|
|
103
|
+
*
|
|
104
|
+
* This allows you to ensure that components are being tested in the
|
|
105
|
+
* AppShell world.
|
|
106
|
+
*
|
|
107
|
+
* NOTE(somewhatabstract): The AppShell component itself already does
|
|
108
|
+
* the work of setting up routing and the AppShellContext and so using this
|
|
109
|
+
* adapter with the App component will have zero-effect since AppShell will
|
|
110
|
+
* override it.
|
|
111
|
+
*/
|
|
112
|
+
declare export var adapter: TestHarnessAdapter<Config>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
// WARNING: If you modify this file you may need to update router.jsx.flow
|
|
2
|
+
// to ensure that the Flow types are still correct.
|
|
1
3
|
import * as React from "react";
|
|
2
4
|
|
|
3
5
|
import {StaticRouter, MemoryRouter, Route, Switch} from "react-router-dom";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
import type {LocationShape, Location} from "react-router-dom";
|
|
7
|
+
import type {LocationDescriptor} from "history";
|
|
7
8
|
import type {TestHarnessAdapter} from "../types";
|
|
8
9
|
|
|
9
10
|
type MemoryRouterProps = JSX.LibraryManagedAttributes<
|
|
@@ -48,7 +49,7 @@ type Config = // The initial location to use.
|
|
|
48
49
|
/**
|
|
49
50
|
* The location to use.
|
|
50
51
|
*/
|
|
51
|
-
location:
|
|
52
|
+
location: LocationDescriptor;
|
|
52
53
|
/**
|
|
53
54
|
* Force the use of a StaticRouter, instead of MemoryRouter.
|
|
54
55
|
*/
|
|
@@ -71,7 +72,7 @@ type Config = // The initial location to use.
|
|
|
71
72
|
/**
|
|
72
73
|
* The initial location to use.
|
|
73
74
|
*/
|
|
74
|
-
location:
|
|
75
|
+
location: LocationDescriptor;
|
|
75
76
|
/**
|
|
76
77
|
* A path match to use.
|
|
77
78
|
*
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A adapter to be composed with our test harnass infrastructure.
|
|
6
|
+
*/
|
|
7
|
+
export type TestHarnessAdapter<TConfig> = (
|
|
8
|
+
children: React.Node,
|
|
9
|
+
config: TConfig,
|
|
10
|
+
) => React.Element<any>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A general map of adapters by their identifiers.
|
|
14
|
+
*
|
|
15
|
+
* It's OK that this has `any` for the config type as this is the very base
|
|
16
|
+
* version of a adapter set. In reality, a more specific type will be used
|
|
17
|
+
* with the harness functions that use more specific definitions of known
|
|
18
|
+
* adapters. This is just to support the base reality of not knowing.
|
|
19
|
+
*
|
|
20
|
+
* Use this on input positions only. Output positions for adapters
|
|
21
|
+
* should infer their type in most cases to ensure the strongest typing of
|
|
22
|
+
* the adapters.
|
|
23
|
+
*/
|
|
24
|
+
export type TestHarnessAdapters = {|
|
|
25
|
+
+[adapterID: string]: TestHarnessAdapter<any>,
|
|
26
|
+
|};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Mapping functions from a adapter-like function to config type.
|
|
30
|
+
*/
|
|
31
|
+
type ExtractConfig = <TConfig>(TestHarnessAdapter<TConfig>) => TConfig;
|
|
32
|
+
type ExtractMaybeConfig = <TConfig>(TestHarnessAdapter<TConfig>) => ?TConfig;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Type for easily defining an adapter's config type.
|
|
36
|
+
*
|
|
37
|
+
* This is the `TestHarnessAdapter` equivalent of `React.ElementConfig`.
|
|
38
|
+
*/
|
|
39
|
+
export type TestHarnessConfig<TAdapter> = $Call<ExtractConfig, TAdapter>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The `TestHarnessConfigs` type as defined by parsing a given set of adapters.
|
|
43
|
+
*
|
|
44
|
+
* NOTE: This only works if the properties of the passed `TAdapters` type
|
|
45
|
+
* are explicitly typed as `TestHarnessAdapter<TConfig>` so if passing in a
|
|
46
|
+
* non-Adapters type (which we should be, to get strong `TConfig` types instead
|
|
47
|
+
* of `any`), then that object should make sure that each adapter is strongly
|
|
48
|
+
* marked as `TestHarnessAdapter<TConfig>` - flow does not appear to pattern
|
|
49
|
+
* match against the type definition when invoking the `ExtractConfig` type and I
|
|
50
|
+
* haven't worked out how to get it to multi-dispatch so that it matches
|
|
51
|
+
* functions too. Even worse, if the type doesn't match, it just allows `any`
|
|
52
|
+
* in the `Configs` object, rather than indicating any kind of problem.
|
|
53
|
+
*/
|
|
54
|
+
export type TestHarnessConfigs<TAdapters: TestHarnessAdapters> = $ObjMap<
|
|
55
|
+
TAdapters,
|
|
56
|
+
ExtractMaybeConfig,
|
|
57
|
+
>;
|
package/src/harness/types.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
// WARNING: If you modify this file you may need to update types.js.flow
|
|
2
|
+
// to ensure that the Flow types are still correct.
|
|
1
3
|
import * as React from "react";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
* A adapter to be composed with our test
|
|
6
|
+
* A adapter to be composed with our test harness infrastructure.
|
|
5
7
|
*/
|
|
6
8
|
export type TestHarnessAdapter<TConfig> = (
|
|
7
9
|
children: React.ReactNode,
|
|
@@ -21,24 +23,17 @@ export type TestHarnessAdapter<TConfig> = (
|
|
|
21
23
|
* the adapters.
|
|
22
24
|
*/
|
|
23
25
|
export type TestHarnessAdapters = {
|
|
24
|
-
[adapterID: string]: TestHarnessAdapter<any>;
|
|
26
|
+
readonly [adapterID: string]: TestHarnessAdapter<any>;
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
/**
|
|
28
|
-
* Mapping functions from a adapter-like function to config type.
|
|
29
|
-
*/
|
|
30
|
-
type ExtractConfig = <TConfig>(arg1: TestHarnessAdapter<TConfig>) => TConfig;
|
|
31
|
-
type ExtractMaybeConfig = <TConfig>(
|
|
32
|
-
arg1: TestHarnessAdapter<TConfig>,
|
|
33
|
-
) => TConfig | null | undefined;
|
|
34
|
-
|
|
35
29
|
/**
|
|
36
30
|
* Type for easily defining an adapter's config type.
|
|
37
|
-
*
|
|
38
|
-
* This is the `TestHarnessAdapter` equivalent of `React.ElementConfig`.
|
|
39
31
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
export type TestHarnessConfig<TAdapter> = TAdapter extends TestHarnessAdapter<
|
|
33
|
+
infer TConfig
|
|
34
|
+
>
|
|
35
|
+
? TConfig
|
|
36
|
+
: never;
|
|
42
37
|
|
|
43
38
|
/**
|
|
44
39
|
* The `TestHarnessConfigs` type as defined by parsing a given set of adapters.
|
|
@@ -47,13 +42,8 @@ export type TestHarnessConfig<TAdapter> = ReturnType<ExtractConfig>;
|
|
|
47
42
|
* are explicitly typed as `TestHarnessAdapter<TConfig>` so if passing in a
|
|
48
43
|
* non-Adapters type (which we should be, to get strong `TConfig` types instead
|
|
49
44
|
* of `any`), then that object should make sure that each adapter is strongly
|
|
50
|
-
* marked as `TestHarnessAdapter<TConfig>`
|
|
51
|
-
* match against the type definition when invoking the `ExtractConfig` type and I
|
|
52
|
-
* haven't worked out how to get it to multi-dispatch so that it matches
|
|
53
|
-
* functions too. Even worse, if the type doesn't match, it just allows `any`
|
|
54
|
-
* in the `Configs` object, rather than indicating any kind of problem.
|
|
45
|
+
* marked as `TestHarnessAdapter<TConfig>`
|
|
55
46
|
*/
|
|
56
|
-
export type TestHarnessConfigs<TAdapters extends TestHarnessAdapters> =
|
|
57
|
-
TAdapters
|
|
58
|
-
|
|
59
|
-
>;
|
|
47
|
+
export type TestHarnessConfigs<TAdapters extends TestHarnessAdapters> = {
|
|
48
|
+
[K in keyof TAdapters]: TestHarnessConfig<TAdapters[K]> | null | undefined;
|
|
49
|
+
};
|