@khanacademy/wonder-blocks-testing 8.0.8 → 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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @khanacademy/wonder-blocks-testing
2
2
 
3
+ ## 8.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 7e79069d: Get the types working properly
8
+
3
9
  ## 8.0.8
4
10
 
5
11
  ### Patch Changes
@@ -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 Record<any, any>> = Readonly<TProps> | ((options: Readonly<GetPropsOptions>) => Readonly<TProps>);
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 Record<any, any>> = (
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: { [key: any]: any }> =
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: { [key: any]: any }> = (
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: any;
24
+ location: import("history").LocationDescriptor<unknown>;
25
25
  forceStatic: true;
26
26
  path?: string | undefined;
27
27
  } | {
28
- location: any;
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 $Flowgen$Import$_2e__2e__2f_types from "../types";
8
- import * as $Flowgen$Import$aphrodite from "aphrodite";
9
- import * as $Flowgen$Import$history from "history";
10
- import type { TestHarnessConfigs } from "../types";
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: $Flowgen$Import$_2e__2e__2f_types.TestHarnessAdapter<
22
- | string
23
- | string[]
24
- | $Flowgen$Import$aphrodite.CSSProperties
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 { LocationShape, Location } from "react-router-dom";
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: string | 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: string | LocationShape;
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 { LocationShape, Location } from "react-router-dom";
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: string | 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: string | LocationShape,
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: 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>;
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: ObjMap<
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: 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>>;
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: ObjMap<
28
- TAdapters,
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: ObjMap<TAdapters, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>, children: React.ReactNode) => React.ReactElement;
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: ObjMap<
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<ObjMap<{
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: any;
25
+ location: import("history").LocationDescriptor<unknown>;
26
26
  forceStatic: true;
27
27
  path?: string | undefined;
28
28
  } | {
29
- location: any;
29
+ location: import("history").LocationDescriptor<unknown>;
30
30
  path?: string | undefined;
31
31
  }>>;
32
- }, <TConfig>(arg1: import("./types").TestHarnessAdapter<TConfig>) => TConfig | null | undefined>> | undefined) => import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<TProps> & import("react").RefAttributes<unknown>>;
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: { [key: string]: any }>(
21
+ declare export var testHarness: <TProps: { ... }>(
22
22
  Component: $Flowgen$Import$react.ComponentType<TProps>,
23
23
  configs?: $Rest<
24
- ObjMap<
25
- {|
26
- +css: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
27
- | string
28
- | string[]
29
- | $Flowgen$Import$aphrodite.CSSProperties
30
- | {|
31
- classes: string[],
32
- style: $Flowgen$Import$aphrodite.CSSProperties,
33
- |}
34
- >,
35
- +data: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
36
- | ((requestId: string) => Promise<any> | null | void)
37
- | ((requestId: string) => Promise<any> | null | void)[]
38
- >,
39
- +portal: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<string>,
40
- +router: $Flowgen$Import$_2e__2f_types.TestHarnessAdapter<
41
- | string
42
- | $ReadOnly<
43
- | {|
44
- initialEntries:
45
- | $Flowgen$Import$history.LocationDescriptor<mixed>[]
46
- | void,
47
- initialIndex?: number | void,
48
- getUserConfirmation?:
49
- | ((
50
- message: string,
51
- callback: (ok: boolean) => void
52
- ) => void)
53
- | void,
54
- path?: string | void,
55
- |}
56
- | {|
57
- location: any,
58
- forceStatic: true,
59
- path?: string | void,
60
- |}
61
- | {|
62
- location: any,
63
- path?: string | void,
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<{|
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  /**
3
- * A adapter to be composed with our test harnass infrastructure.
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> = ReturnType<ExtractConfig>;
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>` - 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.
32
+ * marked as `TestHarnessAdapter<TConfig>`
44
33
  */
45
- export type TestHarnessConfigs<TAdapters extends TestHarnessAdapters> = ObjMap<TAdapters, ExtractMaybeConfig>;
46
- export {};
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
- children: React.Node,
14
- config: TConfig
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
- [adapterID: string]: TestHarnessAdapter<any>,
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
- declare type ExtractConfig = <TConfig>(
35
- arg1: TestHarnessAdapter<TConfig>
36
- ) => TConfig;
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
- <R>((...args: any[]) => R) => R,
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>` - TypeScript does not appear to pattern
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
- TAdapters,
64
- ExtractMaybeConfig
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.8",
3
+ "version": "8.0.9",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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 Record<any, any>> =
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 Record<any, any>> = (
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>` - TypeScript does not appear to pattern
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>;
@@ -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;