@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
package/CHANGELOG.md
CHANGED
package/dist/fixtures/types.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ export type GetPropsOptions = {
|
|
|
14
14
|
*/
|
|
15
15
|
logHandler: (name: string) => (...args: Array<any>) => void;
|
|
16
16
|
};
|
|
17
|
-
export type FixtureProps<TProps extends
|
|
17
|
+
export type FixtureProps<TProps extends object> = Readonly<TProps> | ((options: Readonly<GetPropsOptions>) => Readonly<TProps>);
|
|
18
18
|
/**
|
|
19
19
|
* A function for defining a fixture.
|
|
20
20
|
*/
|
|
21
|
-
export type FixtureFn<TProps extends
|
|
21
|
+
export type FixtureFn<TProps extends object> = (
|
|
22
22
|
/**
|
|
23
23
|
* The name of the fixture.
|
|
24
24
|
*/
|
|
@@ -22,13 +22,13 @@ export type GetPropsOptions = {|
|
|
|
22
22
|
*/
|
|
23
23
|
logHandler: (name: string) => (...args: Array<any>) => void,
|
|
24
24
|
|};
|
|
25
|
-
export type FixtureProps<TProps: {
|
|
25
|
+
export type FixtureProps<TProps: { ... }> =
|
|
26
26
|
| $ReadOnly<TProps>
|
|
27
27
|
| ((options: $ReadOnly<GetPropsOptions>) => $ReadOnly<TProps>);
|
|
28
28
|
/**
|
|
29
29
|
* A function for defining a fixture.
|
|
30
30
|
*/
|
|
31
|
-
export type FixtureFn<TProps: {
|
|
31
|
+
export type FixtureFn<TProps: { ... }> = (
|
|
32
32
|
description: string,
|
|
33
33
|
props: FixtureProps<TProps>,
|
|
34
34
|
wrapper?: React.ComponentType<TProps>
|
|
@@ -21,11 +21,11 @@ export declare const DefaultAdapters: {
|
|
|
21
21
|
getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
|
|
22
22
|
path?: string | undefined;
|
|
23
23
|
} | {
|
|
24
|
-
location:
|
|
24
|
+
location: import("history").LocationDescriptor<unknown>;
|
|
25
25
|
forceStatic: true;
|
|
26
26
|
path?: string | undefined;
|
|
27
27
|
} | {
|
|
28
|
-
location:
|
|
28
|
+
location: import("history").LocationDescriptor<unknown>;
|
|
29
29
|
path?: string | undefined;
|
|
30
30
|
}>>;
|
|
31
31
|
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
2
|
* @flow
|
|
6
3
|
*/
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import
|
|
4
|
+
import * as css from "./css";
|
|
5
|
+
import * as data from "./data";
|
|
6
|
+
import * as portal from "./portal";
|
|
7
|
+
import * as router from "./router";
|
|
8
|
+
|
|
9
|
+
import type { TestHarnessConfigs, TestHarnessConfig } from "../types";
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* NOTE: We do not type `DefaultAdapters` with `Adapters` here because we want
|
|
@@ -18,44 +17,10 @@ import type { TestHarnessConfigs } from "../types";
|
|
|
18
17
|
* The default adapters provided by Wonder Blocks.
|
|
19
18
|
*/
|
|
20
19
|
declare export var DefaultAdapters: {|
|
|
21
|
-
+css:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
| {|
|
|
26
|
-
classes: string[],
|
|
27
|
-
style: $Flowgen$Import$aphrodite.CSSProperties,
|
|
28
|
-
|}
|
|
29
|
-
>,
|
|
30
|
-
+data: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<
|
|
31
|
-
| ((requestId: string) => Promise<any> | null | void)
|
|
32
|
-
| ((requestId: string) => Promise<any> | null | void)[]
|
|
33
|
-
>,
|
|
34
|
-
+portal: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<string>,
|
|
35
|
-
+router: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<
|
|
36
|
-
| string
|
|
37
|
-
| $ReadOnly<
|
|
38
|
-
| {|
|
|
39
|
-
initialEntries:
|
|
40
|
-
| $Flowgen$Import$history.LocationDescriptor<mixed>[]
|
|
41
|
-
| void,
|
|
42
|
-
initialIndex?: number | void,
|
|
43
|
-
getUserConfirmation?:
|
|
44
|
-
| ((message: string, callback: (ok: boolean) => void) => void)
|
|
45
|
-
| void,
|
|
46
|
-
path?: string | void,
|
|
47
|
-
|}
|
|
48
|
-
| {|
|
|
49
|
-
location: any,
|
|
50
|
-
forceStatic: true,
|
|
51
|
-
path?: string | void,
|
|
52
|
-
|}
|
|
53
|
-
| {|
|
|
54
|
-
location: any,
|
|
55
|
-
path?: string | void,
|
|
56
|
-
|}
|
|
57
|
-
>
|
|
58
|
-
>,
|
|
20
|
+
+css: typeof css.adapter,
|
|
21
|
+
+data: typeof data.adapter,
|
|
22
|
+
+portal: typeof portal.adapter,
|
|
23
|
+
+router: typeof router.adapter,
|
|
59
24
|
|};
|
|
60
25
|
/**
|
|
61
26
|
* The default configurations to use with the `DefaultAdapters`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { MemoryRouter } from "react-router-dom";
|
|
3
|
-
import type {
|
|
3
|
+
import type { LocationDescriptor } from "history";
|
|
4
4
|
import type { TestHarnessAdapter } from "../types";
|
|
5
5
|
type MemoryRouterProps = JSX.LibraryManagedAttributes<typeof MemoryRouter, React.ComponentProps<typeof MemoryRouter>>;
|
|
6
6
|
/**
|
|
@@ -36,7 +36,7 @@ type Config = Readonly<{
|
|
|
36
36
|
/**
|
|
37
37
|
* The location to use.
|
|
38
38
|
*/
|
|
39
|
-
location:
|
|
39
|
+
location: LocationDescriptor;
|
|
40
40
|
/**
|
|
41
41
|
* Force the use of a StaticRouter, instead of MemoryRouter.
|
|
42
42
|
*/
|
|
@@ -58,7 +58,7 @@ type Config = Readonly<{
|
|
|
58
58
|
/**
|
|
59
59
|
* The initial location to use.
|
|
60
60
|
*/
|
|
61
|
-
location:
|
|
61
|
+
location: LocationDescriptor;
|
|
62
62
|
/**
|
|
63
63
|
* A path match to use.
|
|
64
64
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as React from "react";
|
|
8
8
|
import { MemoryRouter } from "react-router-dom";
|
|
9
|
-
import type {
|
|
9
|
+
import type { LocationDescriptor } from "history";
|
|
10
10
|
import type { TestHarnessAdapter } from "../types";
|
|
11
11
|
declare type MemoryRouterProps = React.ElementConfig<typeof MemoryRouter>;
|
|
12
12
|
/**
|
|
@@ -51,7 +51,7 @@ declare type Config =
|
|
|
51
51
|
/**
|
|
52
52
|
* The location to use.
|
|
53
53
|
*/
|
|
54
|
-
location:
|
|
54
|
+
location: LocationDescriptor,
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Force the use of a StaticRouter, instead of MemoryRouter.
|
|
@@ -76,7 +76,7 @@ declare type Config =
|
|
|
76
76
|
/**
|
|
77
77
|
* The initial location to use.
|
|
78
78
|
*/
|
|
79
|
-
location:
|
|
79
|
+
location: LocationDescriptor,
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* A path match to use.
|
|
@@ -14,4 +14,4 @@ import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
|
14
14
|
* configs?: $Shape<TestHarnessConfigs<TAdapters>>,
|
|
15
15
|
* ) => React.AbstractComponent<any, any>} A test harness.
|
|
16
16
|
*/
|
|
17
|
-
export declare const makeHookHarness: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, defaultConfigs:
|
|
17
|
+
export declare const makeHookHarness: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, defaultConfigs: TestHarnessConfigs<TAdapters>) => (configs?: Partial<TestHarnessConfigs<TAdapters>> | undefined) => React.ForwardRefExoticComponent<any>;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import * as $Flowgen$Import$_2e__2f_types from "./types";
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
10
9
|
|
|
@@ -22,20 +21,7 @@ configs?: $Shape<TestHarnessConfigs<TAdapters>>) => React.AbstractComponent<any,
|
|
|
22
21
|
*/
|
|
23
22
|
declare export var makeHookHarness: <TAdapters: TestHarnessAdapters>(
|
|
24
23
|
adapters: TAdapters,
|
|
25
|
-
defaultConfigs:
|
|
26
|
-
TAdapters,
|
|
27
|
-
<TConfig>(
|
|
28
|
-
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
29
|
-
) => TConfig | null | void
|
|
30
|
-
>
|
|
24
|
+
defaultConfigs: TestHarnessConfigs<TAdapters>
|
|
31
25
|
) => (
|
|
32
|
-
configs?: $Rest<
|
|
33
|
-
ObjMap<
|
|
34
|
-
TAdapters,
|
|
35
|
-
<TConfig>(
|
|
36
|
-
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
37
|
-
) => TConfig | null | void
|
|
38
|
-
>,
|
|
39
|
-
{}
|
|
40
|
-
> | void
|
|
26
|
+
configs?: $Rest<TestHarnessConfigs<TAdapters>, {}> | void
|
|
41
27
|
) => React.ForwardRefExoticComponent<any>;
|
|
@@ -15,4 +15,4 @@ import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
|
15
15
|
* configs?: $Shape<Configs<TAdapters>>,
|
|
16
16
|
* ) => React.AbstractComponent<TProps, Instance>} A test harness.
|
|
17
17
|
*/
|
|
18
|
-
export declare const makeTestHarness: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, defaultConfigs:
|
|
18
|
+
export declare const makeTestHarness: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, defaultConfigs: TestHarnessConfigs<TAdapters>) => <TProps extends object>(Component: React.ComponentType<TProps>, configs?: Partial<TestHarnessConfigs<TAdapters>> | undefined) => React.ForwardRefExoticComponent<React.PropsWithoutRef<TProps> & React.RefAttributes<unknown>>;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import * as $Flowgen$Import$_2e__2f_types from "./types";
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
10
9
|
|
|
@@ -24,23 +23,10 @@ import type { TestHarnessAdapters, TestHarnessConfigs } from "./types";
|
|
|
24
23
|
*/
|
|
25
24
|
declare export var makeTestHarness: <TAdapters: TestHarnessAdapters>(
|
|
26
25
|
adapters: TAdapters,
|
|
27
|
-
defaultConfigs:
|
|
28
|
-
|
|
29
|
-
<TConfig>(
|
|
30
|
-
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
31
|
-
) => TConfig | null | void
|
|
32
|
-
>
|
|
33
|
-
) => <TProps: { [key: string]: any }>(
|
|
26
|
+
defaultConfigs: TestHarnessConfigs<TAdapters>
|
|
27
|
+
) => <TProps: { ... }>(
|
|
34
28
|
Component: React.ComponentType<TProps>,
|
|
35
|
-
configs?: $Rest<
|
|
36
|
-
ObjMap<
|
|
37
|
-
TAdapters,
|
|
38
|
-
<TConfig>(
|
|
39
|
-
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
40
|
-
) => TConfig | null | void
|
|
41
|
-
>,
|
|
42
|
-
{}
|
|
43
|
-
> | void
|
|
29
|
+
configs?: $Rest<TestHarnessConfigs<TAdapters>, {}> | void
|
|
44
30
|
) => React.ForwardRefExoticComponent<{|
|
|
45
31
|
...React.PropsWithoutRef<TProps>,
|
|
46
32
|
...React.RefAttributes<mixed>,
|
|
@@ -3,4 +3,4 @@ import type { TestHarnessConfigs, TestHarnessAdapters } from "./types";
|
|
|
3
3
|
/**
|
|
4
4
|
* Render test adapters around a child component.
|
|
5
5
|
*/
|
|
6
|
-
export declare const renderAdapters: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, configs:
|
|
6
|
+
export declare const renderAdapters: <TAdapters extends TestHarnessAdapters>(adapters: TAdapters, configs: TestHarnessConfigs<TAdapters>, children: React.ReactNode) => React.ReactElement;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import * as $Flowgen$Import$_2e__2f_types from "./types";
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import type { TestHarnessConfigs, TestHarnessAdapters } from "./types";
|
|
10
9
|
|
|
@@ -13,11 +12,6 @@ import type { TestHarnessConfigs, TestHarnessAdapters } from "./types";
|
|
|
13
12
|
*/
|
|
14
13
|
declare export var renderAdapters: <TAdapters: TestHarnessAdapters>(
|
|
15
14
|
adapters: TAdapters,
|
|
16
|
-
configs:
|
|
17
|
-
TAdapters,
|
|
18
|
-
<TConfig>(
|
|
19
|
-
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
20
|
-
) => TConfig | null | void
|
|
21
|
-
>,
|
|
15
|
+
configs: TestHarnessConfigs<TAdapters>,
|
|
22
16
|
children: React.Node
|
|
23
17
|
) => React.Element<any>;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* configurations, use `makeTestHarness` to create a new `testHarness`
|
|
10
10
|
* function.
|
|
11
11
|
*/
|
|
12
|
-
export declare const testHarness: <TProps extends object>(Component: import("react").ComponentType<TProps>, configs?: Partial<
|
|
12
|
+
export declare const testHarness: <TProps extends object>(Component: import("react").ComponentType<TProps>, configs?: Partial<import("./types").TestHarnessConfigs<{
|
|
13
13
|
readonly css: import("./types").TestHarnessAdapter<string | string[] | import("aphrodite").CSSProperties | {
|
|
14
14
|
classes: string[];
|
|
15
15
|
style: import("aphrodite").CSSProperties;
|
|
@@ -22,11 +22,11 @@ export declare const testHarness: <TProps extends object>(Component: import("rea
|
|
|
22
22
|
getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
|
|
23
23
|
path?: string | undefined;
|
|
24
24
|
} | {
|
|
25
|
-
location:
|
|
25
|
+
location: import("history").LocationDescriptor<unknown>;
|
|
26
26
|
forceStatic: true;
|
|
27
27
|
path?: string | undefined;
|
|
28
28
|
} | {
|
|
29
|
-
location:
|
|
29
|
+
location: import("history").LocationDescriptor<unknown>;
|
|
30
30
|
path?: string | undefined;
|
|
31
31
|
}>>;
|
|
32
|
-
}
|
|
32
|
+
}>> | undefined) => import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<TProps> & import("react").RefAttributes<unknown>>;
|
|
@@ -18,57 +18,49 @@ import * as $Flowgen$Import$history from "history";
|
|
|
18
18
|
* configurations, use `makeTestHarness` to create a new `testHarness`
|
|
19
19
|
* function.
|
|
20
20
|
*/
|
|
21
|
-
declare export var testHarness: <TProps: {
|
|
21
|
+
declare export var testHarness: <TProps: { ... }>(
|
|
22
22
|
Component: $Flowgen$Import$react.ComponentType<TProps>,
|
|
23
23
|
configs?: $Rest<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|}
|
|
65
|
-
>
|
|
66
|
-
>,
|
|
67
|
-
|},
|
|
68
|
-
<TConfig>(
|
|
69
|
-
arg1: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<TConfig>
|
|
70
|
-
) => TConfig | null | void
|
|
71
|
-
>,
|
|
24
|
+
$Flowgen$Import$_2e__2f_types.TestHarnessConfigs<{|
|
|
25
|
+
+css: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
|
|
26
|
+
| string
|
|
27
|
+
| string[]
|
|
28
|
+
| $Flowgen$Import$aphrodite.CSSProperties
|
|
29
|
+
| {|
|
|
30
|
+
classes: string[],
|
|
31
|
+
style: $Flowgen$Import$aphrodite.CSSProperties,
|
|
32
|
+
|}
|
|
33
|
+
>,
|
|
34
|
+
+data: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
|
|
35
|
+
| ((requestId: string) => Promise<any> | null | void)
|
|
36
|
+
| ((requestId: string) => Promise<any> | null | void)[]
|
|
37
|
+
>,
|
|
38
|
+
+portal: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<string>,
|
|
39
|
+
+router: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
|
|
40
|
+
| string
|
|
41
|
+
| $ReadOnly<
|
|
42
|
+
| {|
|
|
43
|
+
initialEntries:
|
|
44
|
+
| $Flowgen$Import$history.LocationDescriptor<mixed>[]
|
|
45
|
+
| void,
|
|
46
|
+
initialIndex?: number | void,
|
|
47
|
+
getUserConfirmation?:
|
|
48
|
+
| ((message: string, callback: (ok: boolean) => void) => void)
|
|
49
|
+
| void,
|
|
50
|
+
path?: string | void,
|
|
51
|
+
|}
|
|
52
|
+
| {|
|
|
53
|
+
location: $Flowgen$Import$history.LocationDescriptor<mixed>,
|
|
54
|
+
forceStatic: true,
|
|
55
|
+
path?: string | void,
|
|
56
|
+
|}
|
|
57
|
+
| {|
|
|
58
|
+
location: $Flowgen$Import$history.LocationDescriptor<mixed>,
|
|
59
|
+
path?: string | void,
|
|
60
|
+
|}
|
|
61
|
+
>
|
|
62
|
+
>,
|
|
63
|
+
|}>,
|
|
72
64
|
{}
|
|
73
65
|
> | void
|
|
74
66
|
) => $Flowgen$Import$react.ForwardRefExoticComponent<{|
|
package/dist/harness/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
/**
|
|
3
|
-
* A adapter to be composed with our test
|
|
3
|
+
* A adapter to be composed with our test harness infrastructure.
|
|
4
4
|
*/
|
|
5
5
|
export type TestHarnessAdapter<TConfig> = (children: React.ReactNode, config: TConfig) => React.ReactElement<any>;
|
|
6
6
|
/**
|
|
@@ -16,19 +16,12 @@ export type TestHarnessAdapter<TConfig> = (children: React.ReactNode, config: TC
|
|
|
16
16
|
* the adapters.
|
|
17
17
|
*/
|
|
18
18
|
export type TestHarnessAdapters = {
|
|
19
|
-
[adapterID: string]: TestHarnessAdapter<any>;
|
|
19
|
+
readonly [adapterID: string]: TestHarnessAdapter<any>;
|
|
20
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
21
|
/**
|
|
27
22
|
* Type for easily defining an adapter's config type.
|
|
28
|
-
*
|
|
29
|
-
* This is the `TestHarnessAdapter` equivalent of `React.ElementConfig`.
|
|
30
23
|
*/
|
|
31
|
-
export type TestHarnessConfig<TAdapter> =
|
|
24
|
+
export type TestHarnessConfig<TAdapter> = TAdapter extends TestHarnessAdapter<infer TConfig> ? TConfig : never;
|
|
32
25
|
/**
|
|
33
26
|
* The `TestHarnessConfigs` type as defined by parsing a given set of adapters.
|
|
34
27
|
*
|
|
@@ -36,11 +29,8 @@ export type TestHarnessConfig<TAdapter> = ReturnType<ExtractConfig>;
|
|
|
36
29
|
* are explicitly typed as `TestHarnessAdapter<TConfig>` so if passing in a
|
|
37
30
|
* non-Adapters type (which we should be, to get strong `TConfig` types instead
|
|
38
31
|
* of `any`), then that object should make sure that each adapter is strongly
|
|
39
|
-
* marked as `TestHarnessAdapter<TConfig>`
|
|
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.
|
|
32
|
+
* marked as `TestHarnessAdapter<TConfig>`
|
|
44
33
|
*/
|
|
45
|
-
export type TestHarnessConfigs<TAdapters extends TestHarnessAdapters> =
|
|
46
|
-
|
|
34
|
+
export type TestHarnessConfigs<TAdapters extends TestHarnessAdapters> = {
|
|
35
|
+
[K in keyof TAdapters]: TestHarnessConfig<TAdapters[K]> | null | undefined;
|
|
36
|
+
};
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
1
|
+
// @flow
|
|
7
2
|
import * as React from "react";
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* A adapter to be composed with our test harnass infrastructure.
|
|
11
6
|
*/
|
|
12
7
|
export type TestHarnessAdapter<TConfig> = (
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
children: React.Node,
|
|
9
|
+
config: TConfig,
|
|
15
10
|
) => React.Element<any>;
|
|
11
|
+
|
|
16
12
|
/**
|
|
17
13
|
* A general map of adapters by their identifiers.
|
|
18
14
|
*
|
|
@@ -25,27 +21,23 @@ export type TestHarnessAdapter<TConfig> = (
|
|
|
25
21
|
* should infer their type in most cases to ensure the strongest typing of
|
|
26
22
|
* the adapters.
|
|
27
23
|
*/
|
|
28
|
-
export type TestHarnessAdapters = {
|
|
29
|
-
|
|
30
|
-
};
|
|
24
|
+
export type TestHarnessAdapters = {|
|
|
25
|
+
+[adapterID: string]: TestHarnessAdapter<any>,
|
|
26
|
+
|};
|
|
27
|
+
|
|
31
28
|
/**
|
|
32
29
|
* Mapping functions from a adapter-like function to config type.
|
|
33
30
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
declare type ExtractMaybeConfig = <TConfig>(
|
|
38
|
-
arg1: TestHarnessAdapter<TConfig>
|
|
39
|
-
) => TConfig | null | void;
|
|
31
|
+
type ExtractConfig = <TConfig>(TestHarnessAdapter<TConfig>) => TConfig;
|
|
32
|
+
type ExtractMaybeConfig = <TConfig>(TestHarnessAdapter<TConfig>) => ?TConfig;
|
|
33
|
+
|
|
40
34
|
/**
|
|
41
35
|
* Type for easily defining an adapter's config type.
|
|
42
36
|
*
|
|
43
37
|
* This is the `TestHarnessAdapter` equivalent of `React.ElementConfig`.
|
|
44
38
|
*/
|
|
45
|
-
export type TestHarnessConfig<TAdapter> = $Call<
|
|
46
|
-
|
|
47
|
-
ExtractConfig
|
|
48
|
-
>;
|
|
39
|
+
export type TestHarnessConfig<TAdapter> = $Call<ExtractConfig, TAdapter>;
|
|
40
|
+
|
|
49
41
|
/**
|
|
50
42
|
* The `TestHarnessConfigs` type as defined by parsing a given set of adapters.
|
|
51
43
|
*
|
|
@@ -53,13 +45,13 @@ export type TestHarnessConfig<TAdapter> = $Call<
|
|
|
53
45
|
* are explicitly typed as `TestHarnessAdapter<TConfig>` so if passing in a
|
|
54
46
|
* non-Adapters type (which we should be, to get strong `TConfig` types instead
|
|
55
47
|
* of `any`), then that object should make sure that each adapter is strongly
|
|
56
|
-
* marked as `TestHarnessAdapter<TConfig>` -
|
|
48
|
+
* marked as `TestHarnessAdapter<TConfig>` - flow does not appear to pattern
|
|
57
49
|
* match against the type definition when invoking the `ExtractConfig` type and I
|
|
58
50
|
* haven't worked out how to get it to multi-dispatch so that it matches
|
|
59
51
|
* functions too. Even worse, if the type doesn't match, it just allows `any`
|
|
60
52
|
* in the `Configs` object, rather than indicating any kind of problem.
|
|
61
53
|
*/
|
|
62
|
-
export type TestHarnessConfigs<TAdapters: TestHarnessAdapters> = ObjMap<
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
export type TestHarnessConfigs<TAdapters: TestHarnessAdapters> = $ObjMap<
|
|
55
|
+
TAdapters,
|
|
56
|
+
ExtractMaybeConfig,
|
|
65
57
|
>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-testing",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.9",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.18.6",
|
|
17
|
-
"@khanacademy/wonder-blocks-data": "^11.0.
|
|
17
|
+
"@khanacademy/wonder-blocks-data": "^11.0.8"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@khanacademy/wonder-stuff-core": "^1.2.2",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react-router-dom": "5.3.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"wb-dev-build-settings": "^0.9.
|
|
29
|
+
"wb-dev-build-settings": "^0.9.7"
|
|
30
30
|
},
|
|
31
31
|
"author": "",
|
|
32
32
|
"license": "MIT"
|
package/src/fixtures/types.ts
CHANGED
|
@@ -16,14 +16,14 @@ export type GetPropsOptions = {
|
|
|
16
16
|
logHandler: (name: string) => (...args: Array<any>) => void;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export type FixtureProps<TProps extends
|
|
19
|
+
export type FixtureProps<TProps extends object> =
|
|
20
20
|
| Readonly<TProps>
|
|
21
21
|
| ((options: Readonly<GetPropsOptions>) => Readonly<TProps>);
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* A function for defining a fixture.
|
|
25
25
|
*/
|
|
26
|
-
export type FixtureFn<TProps extends
|
|
26
|
+
export type FixtureFn<TProps extends object> = (
|
|
27
27
|
/**
|
|
28
28
|
* The name of the fixture.
|
|
29
29
|
*/
|
|
@@ -59,6 +59,7 @@ import type {
|
|
|
59
59
|
|
|
60
60
|
//> should error if the config type is wrong
|
|
61
61
|
// 45 is not a string
|
|
62
|
+
// @ts-expect-error: Type '45' is not assignable to type 'string'.
|
|
62
63
|
45 as TestHarnessConfig<TestHarnessAdapter<string>>;
|
|
63
64
|
//<
|
|
64
65
|
|
|
@@ -69,11 +70,7 @@ import type {
|
|
|
69
70
|
* are explicitly typed as `TestHarnessAdapter<TConfig>` so if passing in a
|
|
70
71
|
* non-Adapters type (which we should be, to get strong TConfig types instead
|
|
71
72
|
* of `any`), then that object should make sure that each adapter is strongly
|
|
72
|
-
* marked as `TestHarnessAdapter<TConfig
|
|
73
|
-
* match against the type definition when invoking the ExtractConfig type and I
|
|
74
|
-
* haven't worked out how to get it to multi-dispatch so that it matches
|
|
75
|
-
* functions too. Even worse, if the type doesn't match, it just allows `any`
|
|
76
|
-
* in the configs object, rather than indicating any kind of problem.
|
|
73
|
+
* marked as `TestHarnessAdapter<TConfig>`.
|
|
77
74
|
*/
|
|
78
75
|
const notadapters = "this is wrong";
|
|
79
76
|
const adapterA: TestHarnessAdapter<string> = (
|
|
@@ -103,6 +100,7 @@ const adapters = {
|
|
|
103
100
|
//<
|
|
104
101
|
|
|
105
102
|
//> should assert if config does not match adapter config
|
|
103
|
+
// @ts-expect-error: Conversion of type '{ adapterA: string; adapterB: string; }' to type 'TestHarnessConfigs<{ readonly adapterA: TestHarnessAdapter<string>; readonly adapterB: TestHarnessAdapter<number>; }>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Types of property 'adapterB' are incompatible. Type 'string' is not comparable to type 'number'.
|
|
106
104
|
({
|
|
107
105
|
adapterA: "a string, this is correct",
|
|
108
106
|
// the config type here is a number, not a string
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flow
|
|
3
|
+
*/
|
|
4
|
+
import * as css from "./css";
|
|
5
|
+
import * as data from "./data";
|
|
6
|
+
import * as portal from "./portal";
|
|
7
|
+
import * as router from "./router";
|
|
8
|
+
|
|
9
|
+
import type { TestHarnessConfigs, TestHarnessConfig } from "../types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* NOTE: We do not type `DefaultAdapters` with `Adapters` here because we want
|
|
13
|
+
* the individual config types of each adapter to remain intact rather than
|
|
14
|
+
* getting changed to `any`.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The default adapters provided by Wonder Blocks.
|
|
18
|
+
*/
|
|
19
|
+
declare export var DefaultAdapters: {|
|
|
20
|
+
+css: typeof css.adapter,
|
|
21
|
+
+data: typeof data.adapter,
|
|
22
|
+
+portal: typeof portal.adapter,
|
|
23
|
+
+router: typeof router.adapter,
|
|
24
|
+
|};
|
|
25
|
+
/**
|
|
26
|
+
* The default configurations to use with the `DefaultAdapters`.
|
|
27
|
+
*/
|
|
28
|
+
declare export var DefaultConfigs: TestHarnessConfigs<typeof DefaultAdapters>;
|