@khanacademy/wonder-blocks-testing 8.0.8 → 8.0.10

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,17 @@
1
1
  # @khanacademy/wonder-blocks-testing
2
2
 
3
+ ## 8.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 97829726: Fix indentation change in mockGqlFetch
8
+
9
+ ## 8.0.9
10
+
11
+ ### Patch Changes
12
+
13
+ - 7e79069d: Get the types working properly
14
+
3
15
  ## 8.0.8
4
16
 
5
17
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -125,8 +125,8 @@ const gqlRequestMatchesMock = (mock, operation, variables, context) => {
125
125
  };
126
126
 
127
127
  const mockGqlFetch = () => mockRequester(gqlRequestMatchesMock, (operation, variables, context) => `Operation: ${operation.type} ${operation.id}
128
- Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
129
- Context: ${JSON.stringify(context, null, 2)}`);
128
+ Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
129
+ Context: ${JSON.stringify(context, null, 2)}`);
130
130
 
131
131
  const ResponseImpl = typeof Response === "undefined" ? require("node-fetch").Response : Response;
132
132
 
@@ -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/dist/index.js CHANGED
@@ -149,8 +149,8 @@ const gqlRequestMatchesMock = (mock, operation, variables, context) => {
149
149
  };
150
150
 
151
151
  const mockGqlFetch = () => mockRequester(gqlRequestMatchesMock, (operation, variables, context) => `Operation: ${operation.type} ${operation.id}
152
- Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
153
- Context: ${JSON.stringify(context, null, 2)}`);
152
+ Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
153
+ Context: ${JSON.stringify(context, null, 2)}`);
154
154
 
155
155
  const ResponseImpl = typeof Response === "undefined" ? require("node-fetch").Response : Response;
156
156
 
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.10",
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
  */
@@ -172,16 +172,18 @@ describe("#mockGqlFetch", () => {
172
172
  );
173
173
 
174
174
  // Assert
175
- await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
176
- "No matching mock response found for request:
177
- Operation: query getMyStuff
178
- Variables: {
179
- "a": "variable"
180
- }
181
- Context: {
182
- "my": "context"
183
- }"
184
- `);
175
+ // The indentation on the lines for Operation, Variables, and Context
176
+ // are expected.
177
+ await expect(result).rejects.toThrowError(
178
+ `No matching mock response found for request:
179
+ Operation: query getMyStuff
180
+ Variables: {
181
+ "a": "variable"
182
+ }
183
+ Context: {
184
+ "my": "context"
185
+ }`,
186
+ );
185
187
  });
186
188
 
187
189
  describe("mockOperation", () => {
@@ -8,8 +8,13 @@ import type {GqlFetchMockFn, GqlMockOperation} from "./types";
8
8
  export const mockGqlFetch = (): GqlFetchMockFn =>
9
9
  mockRequester<GqlMockOperation<any, any, any>, any>(
10
10
  gqlRequestMatchesMock,
11
+ // Note that the identation at the start of each line is important.
12
+ // TODO(somewhatabstract): Make a stringify that indents each line of
13
+ // the output properly too.
11
14
  (operation, variables, context) =>
12
15
  `Operation: ${operation.type} ${operation.id}
13
- Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
14
- Context: ${JSON.stringify(context, null, 2)}`,
16
+ Variables: ${
17
+ variables == null ? "None" : JSON.stringify(variables, null, 2)
18
+ }
19
+ Context: ${JSON.stringify(context, null, 2)}`,
15
20
  );