@khanacademy/wonder-blocks-testing-core 1.0.1 → 1.0.2

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +32 -32
  3. package/src/__tests__/mock-requester.test.ts +0 -212
  4. package/src/__tests__/render-hook-static.test.ts +0 -48
  5. package/src/__tests__/respond-with.test.ts +0 -524
  6. package/src/__tests__/response-impl.test.js +0 -47
  7. package/src/__tests__/settle-controller.test.ts +0 -28
  8. package/src/__tests__/settle-signal.test.ts +0 -104
  9. package/src/fetch/__tests__/__snapshots__/mock-fetch.test.ts.snap +0 -29
  10. package/src/fetch/__tests__/fetch-request-matches-mock.test.ts +0 -98
  11. package/src/fetch/__tests__/mock-fetch.test.ts +0 -83
  12. package/src/fetch/fetch-request-matches-mock.ts +0 -42
  13. package/src/fetch/mock-fetch.ts +0 -20
  14. package/src/fetch/types.ts +0 -14
  15. package/src/fixtures/__tests__/fixtures.test.tsx +0 -147
  16. package/src/fixtures/fixtures.basic.stories.tsx +0 -62
  17. package/src/fixtures/fixtures.defaultwrapper.stories.tsx +0 -49
  18. package/src/fixtures/fixtures.tsx +0 -72
  19. package/src/fixtures/types.ts +0 -42
  20. package/src/harness/__tests__/adapt.test.tsx +0 -248
  21. package/src/harness/__tests__/hook-harness.test.ts +0 -73
  22. package/src/harness/__tests__/make-hook-harness.test.tsx +0 -93
  23. package/src/harness/__tests__/make-test-harness.test.tsx +0 -195
  24. package/src/harness/__tests__/test-harness.test.ts +0 -75
  25. package/src/harness/__tests__/types.typestest.tsx +0 -103
  26. package/src/harness/adapt.tsx +0 -41
  27. package/src/harness/adapters/__tests__/__snapshots__/router.test.tsx.snap +0 -5
  28. package/src/harness/adapters/__tests__/css.test.tsx +0 -95
  29. package/src/harness/adapters/__tests__/error-boundary.test.tsx +0 -121
  30. package/src/harness/adapters/__tests__/portal.test.tsx +0 -30
  31. package/src/harness/adapters/__tests__/router.test.tsx +0 -252
  32. package/src/harness/adapters/adapters.ts +0 -35
  33. package/src/harness/adapters/css.tsx +0 -66
  34. package/src/harness/adapters/error-boundary.tsx +0 -56
  35. package/src/harness/adapters/portal.tsx +0 -25
  36. package/src/harness/adapters/router.tsx +0 -205
  37. package/src/harness/get-named-adapter-component.tsx +0 -36
  38. package/src/harness/hook-harness.ts +0 -22
  39. package/src/harness/make-hook-harness.tsx +0 -40
  40. package/src/harness/make-test-harness.tsx +0 -60
  41. package/src/harness/test-harness.ts +0 -13
  42. package/src/harness/types.ts +0 -47
  43. package/src/index.ts +0 -29
  44. package/src/mock-requester.ts +0 -68
  45. package/src/render-hook-static.tsx +0 -60
  46. package/src/respond-with.ts +0 -263
  47. package/src/response-impl.ts +0 -8
  48. package/src/settle-controller.ts +0 -34
  49. package/src/settle-signal.ts +0 -42
  50. package/src/types.ts +0 -40
  51. package/tsconfig-build.json +0 -10
  52. package/tsconfig-build.tsbuildinfo +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @khanacademy/wonder-blocks-testing-core
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
8
+
3
9
  ## 1.0.1
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
1
  {
2
- "name": "@khanacademy/wonder-blocks-testing-core",
3
- "version": "1.0.1",
4
- "design": "v1",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "description": "",
9
- "main": "dist/index.js",
10
- "module": "dist/es/index.js",
11
- "types": "dist/index.d.ts",
12
- "scripts": {
13
- "test": "echo \"Error: no test specified\" && exit 1"
14
- },
15
- "dependencies": {
16
- "@babel/runtime": "^7.18.6"
17
- },
18
- "peerDependencies": {
19
- "@khanacademy/wonder-stuff-core": "^1.2.2",
20
- "@storybook/addon-actions": "^7.0.0",
21
- "aphrodite": "^1.2.5",
22
- "node-fetch": "^2.6.7",
23
- "react": "16.14.0",
24
- "react-dom": "16.14.0",
25
- "react-router-dom": "5.3.0"
26
- },
27
- "devDependencies": {
28
- "@khanacademy/wb-dev-build-settings": "^1.0.1",
29
- "@khanacademy/wonder-stuff-testing": "^3.0.1"
30
- },
31
- "author": "",
32
- "license": "MIT"
33
- }
2
+ "name": "@khanacademy/wonder-blocks-testing-core",
3
+ "version": "1.0.2",
4
+ "design": "v1",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "",
9
+ "main": "dist/index.js",
10
+ "module": "dist/es/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "dependencies": {
16
+ "@babel/runtime": "^7.18.6"
17
+ },
18
+ "peerDependencies": {
19
+ "@khanacademy/wonder-stuff-core": "^1.2.2",
20
+ "@storybook/addon-actions": "^7.0.0",
21
+ "aphrodite": "^1.2.5",
22
+ "node-fetch": "^2.6.7",
23
+ "react": "16.14.0",
24
+ "react-dom": "16.14.0",
25
+ "react-router-dom": "5.3.0"
26
+ },
27
+ "devDependencies": {
28
+ "@khanacademy/wb-dev-build-settings": "^1.0.1",
29
+ "@khanacademy/wonder-stuff-testing": "^3.0.1"
30
+ },
31
+ "author": "",
32
+ "license": "MIT"
33
+ }
@@ -1,212 +0,0 @@
1
- import {RespondWith} from "../respond-with";
2
- import {mockRequester} from "../mock-requester";
3
-
4
- describe("#mockRequester", () => {
5
- it("should return a function", () => {
6
- // Arrange
7
-
8
- // Act
9
- const result = mockRequester(jest.fn(), jest.fn());
10
-
11
- // Assert
12
- expect(result).toBeInstanceOf(Function);
13
- });
14
-
15
- it("should provide mockOperation API", () => {
16
- // Arrange
17
-
18
- // Act
19
- const result = mockRequester(jest.fn(), jest.fn());
20
-
21
- // Assert
22
- expect(result).toHaveProperty("mockOperation", expect.any(Function));
23
- });
24
-
25
- it("should provide mockOperationOnce API", () => {
26
- // Arrange
27
-
28
- // Act
29
- const result = mockRequester(jest.fn(), jest.fn());
30
-
31
- // Assert
32
- expect(result).toHaveProperty(
33
- "mockOperationOnce",
34
- expect.any(Function),
35
- );
36
- });
37
-
38
- it("should throw with helpful details formatted by operationToString if no matching mock is found", async () => {
39
- // Arrange
40
- const mockFn = mockRequester(
41
- jest.fn(),
42
- (...args: any) => `TEST FORMATTING: ${JSON.stringify(args)}`,
43
- );
44
-
45
- // Act
46
- const underTest = mockFn("any", "arguments", {we: {want: 42}});
47
-
48
- // Assert
49
- await expect(underTest).rejects.toThrowErrorMatchingInlineSnapshot(`
50
- "No matching mock response found for request:
51
- TEST FORMATTING: ["any","arguments",{"we":{"want":42}}]"
52
- `);
53
- });
54
-
55
- describe("mockOperation", () => {
56
- it("should invoke matcher with mock for a request", async () => {
57
- // Arrange
58
- const matcher = jest.fn().mockReturnValue(true);
59
- const operationToString = jest.fn();
60
- const mockFn = mockRequester(matcher, operationToString);
61
-
62
- // Act
63
- mockFn.mockOperation(
64
- "THE MOCK DESCRIPTION",
65
- RespondWith.text("TADA!"),
66
- );
67
- await mockFn("any", "arguments", {we: {want: 42}});
68
-
69
- // Assert
70
- expect(matcher).toHaveBeenCalledWith(
71
- "THE MOCK DESCRIPTION",
72
- "any",
73
- "arguments",
74
- {
75
- we: {want: 42},
76
- },
77
- );
78
- });
79
-
80
- it("should return mocked operation response if matcher returns true", async () => {
81
- // Arrange
82
- const matcher = jest.fn().mockReturnValue(true);
83
- const operationToString = jest.fn();
84
- const mockFn = mockRequester(matcher, operationToString);
85
-
86
- // Act
87
- mockFn.mockOperation(
88
- "THE MOCK DESCRIPTION",
89
- RespondWith.text("TADA!"),
90
- );
91
- const response = await mockFn("DO SOMETHING");
92
- const result = response.text();
93
-
94
- // Assert
95
- await expect(result).resolves.toBe("TADA!");
96
- });
97
-
98
- it("should skip mock if matcher returns false and try more mocks", async () => {
99
- // Arrange
100
- const matcher = jest
101
- .fn()
102
- .mockReturnValueOnce(false)
103
- .mockReturnValueOnce(true);
104
- const operationToString = jest.fn();
105
- const mockFn = mockRequester(matcher, operationToString);
106
-
107
- // Act
108
- mockFn.mockOperation(
109
- "THE MOCK DESCRIPTION 1",
110
- RespondWith.text("ONE"),
111
- );
112
- mockFn.mockOperation(
113
- "THE MOCK DESCRIPTION 2",
114
- RespondWith.text("TWO"),
115
- );
116
- const response = await mockFn("DO SOMETHING");
117
- const result = response.text();
118
-
119
- // Assert
120
- await expect(result).resolves.toBe("TWO");
121
- });
122
- });
123
-
124
- describe("mockOperationOnce", () => {
125
- it("should invoke matcher with mock for a request", async () => {
126
- // Arrange
127
- const matcher = jest.fn().mockReturnValue(true);
128
- const operationToString = jest.fn();
129
- const mockFn = mockRequester(matcher, operationToString);
130
-
131
- // Act
132
- mockFn.mockOperationOnce(
133
- "THE MOCK DESCRIPTION",
134
- RespondWith.text("TADA!"),
135
- );
136
- await mockFn("any", "arguments", {we: {want: 42}});
137
-
138
- // Assert
139
- expect(matcher).toHaveBeenCalledWith(
140
- "THE MOCK DESCRIPTION",
141
- "any",
142
- "arguments",
143
- {
144
- we: {want: 42},
145
- },
146
- );
147
- });
148
-
149
- it("should match once", async () => {
150
- // Arrange
151
- const matcher = jest.fn().mockReturnValue(true);
152
- const operationToString = jest.fn();
153
- const mockFn = mockRequester(matcher, operationToString);
154
-
155
- // Act
156
- mockFn.mockOperationOnce(
157
- "THE MOCK DESCRIPTION",
158
- RespondWith.text("TADA!"),
159
- );
160
- const response = await mockFn("DO SOMETHING");
161
- const result = response.text();
162
-
163
- // Assert
164
- await expect(result).resolves.toBe("TADA!");
165
- });
166
-
167
- it("should only match once", async () => {
168
- // Arrange
169
- const matcher = jest.fn().mockReturnValue(true);
170
- const operationToString = jest.fn();
171
- const mockFn = mockRequester(matcher, operationToString);
172
-
173
- // Act
174
- mockFn.mockOperationOnce(
175
- "THE MOCK DESCRIPTION",
176
- RespondWith.text("TADA!"),
177
- );
178
- const result = Promise.all([
179
- mockFn("DO SOMETHING"),
180
- mockFn("DO SOMETHING"),
181
- ]);
182
-
183
- // Assert
184
- await expect(result).rejects.toThrowError();
185
- });
186
-
187
- it("should skip mock if matcher returns false and try more mocks", async () => {
188
- // Arrange
189
- const matcher = jest
190
- .fn()
191
- .mockReturnValueOnce(false)
192
- .mockReturnValueOnce(true);
193
- const operationToString = jest.fn();
194
- const mockFn = mockRequester(matcher, operationToString);
195
-
196
- // Act
197
- mockFn.mockOperationOnce(
198
- "THE MOCK DESCRIPTION 1",
199
- RespondWith.text("ONE"),
200
- );
201
- mockFn.mockOperationOnce(
202
- "THE MOCK DESCRIPTION 2",
203
- RespondWith.text("TWO"),
204
- );
205
- const response = await mockFn("DO SOMETHING");
206
- const result = response.text();
207
-
208
- // Assert
209
- await expect(result).resolves.toBe("TWO");
210
- });
211
- });
212
- });
@@ -1,48 +0,0 @@
1
- import {useLocation} from "react-router-dom";
2
-
3
- import {hookHarness} from "../harness/hook-harness";
4
- import {renderHookStatic} from "../render-hook-static";
5
-
6
- describe("renderHookStatic", () => {
7
- it("should return the result of rendering the hook", () => {
8
- // Arrange
9
- const useTestHook = () => "Hello, World!";
10
-
11
- // Act
12
- const result = renderHookStatic(useTestHook);
13
-
14
- // Assert
15
- expect(result).toStrictEqual({result: {current: "Hello, World!"}});
16
- });
17
-
18
- it("should render the hook with the given initialProps", () => {
19
- // Arrange
20
- const useTestHook = (initialProps?: string) =>
21
- initialProps ?? "BAD RESULT";
22
-
23
- // Act
24
- const result = renderHookStatic(useTestHook, {
25
- initialProps: "Hello, World!",
26
- });
27
-
28
- // Assert
29
- expect(result).toStrictEqual({result: {current: "Hello, World!"}});
30
- });
31
-
32
- it("should return the result of rendering the hook inside the wrapper", () => {
33
- // Arrange
34
- const Wrapper = hookHarness({
35
- router: "/test/route",
36
- });
37
- const useTestHook = () => {
38
- const location = useLocation();
39
- return location.pathname;
40
- };
41
-
42
- // Act
43
- const result = renderHookStatic(useTestHook, {wrapper: Wrapper});
44
-
45
- // Assert
46
- expect(result).toStrictEqual({result: {current: "/test/route"}});
47
- });
48
- });